if (!Iterables.contains(pathComponents, RestconfConstants.MOUNT)) {
final String moduleName = validateAndGetModulName(componentIter);
final Revision revision = validateAndGetRevision(componentIter);
- final Module module = schemaContext.findModule(moduleName, revision).orElseThrow();
+ final Module module = coerceModule(schemaContext, moduleName, revision, null);
return new SchemaExportContext(schemaContext, module, sourceProvider);
} else {
final StringBuilder pathBuilder = new StringBuilder();
final String moduleName = validateAndGetModulName(componentIter);
final Revision revision = validateAndGetRevision(componentIter);
final EffectiveModelContext context = coerceModelContext(point.getMountPoint());
- final Module module = context.findModule(moduleName, revision).orElseThrow();
+ final Module module = coerceModule(context, moduleName, revision, point.getMountPoint());
return new SchemaExportContext(context, module, sourceProvider);
}
}
return name;
}
+ private static Module coerceModule(final EffectiveModelContext context, final String moduleName,
+ final Revision revision, final DOMMountPoint mountPoint) {
+ final var module = context.findModule(moduleName, revision);
+ if (module.isEmpty()) {
+ final var msg = "Module %s %s cannot be found on %s.".formatted(moduleName, revision,
+ mountPoint == null ? "controller" : mountPoint.getIdentifier());
+ throw new RestconfDocumentedException(msg, ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
+ }
+ return module.orElseThrow();
+ }
+
private static EffectiveModelContext coerceModelContext(final DOMMountPoint mountPoint) {
final EffectiveModelContext context = modelContext(mountPoint);
checkState(context != null, "Mount point %s does not have a model context", mountPoint);
import static org.mockito.Mockito.when;
import java.io.FileNotFoundException;
-import java.util.NoSuchElementException;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT);
// make test & verify
- assertThrows(NoSuchElementException.class, () -> schemaService.getSchema(NOT_EXISTING_MODULE));
+ final var ex = assertThrows(RestconfDocumentedException.class, () ->
+ schemaService.getSchema(NOT_EXISTING_MODULE));
+ assertEquals("Not expected error tag", ErrorTag.DATA_MISSING, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
}
/**
when(this.mockContextHandler.get()).thenReturn(SCHEMA_CONTEXT_WITH_MOUNT_POINTS);
// make test & verify
- assertThrows(NoSuchElementException.class, () -> schemaService.getSchema(MOUNT_POINT + NOT_EXISTING_MODULE));
+ final var ex = assertThrows(RestconfDocumentedException.class, () ->
+ schemaService.getSchema(MOUNT_POINT + NOT_EXISTING_MODULE));
+ assertEquals("Not expected error tag", ErrorTag.DATA_MISSING, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
}
/**
import java.util.List;
import java.util.Map.Entry;
-import java.util.NoSuchElementException;
import java.util.Optional;
import org.junit.AfterClass;
import org.junit.Before;
*/
@Test
public void toSchemaExportContextFromIdentifierNotFoundTest() {
- assertThrows(NoSuchElementException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
+ final var ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
SCHEMA_CONTEXT,
"not-existing-module" + "/" + "2016-01-01",
null, sourceProvider));
+ assertEquals("Not expected error tag", ErrorTag.DATA_MISSING, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
}
/**
*/
@Test
public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
- assertThrows(NoSuchElementException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
+ final var ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
SCHEMA_CONTEXT,
MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
mountPointService, sourceProvider));
+ assertEquals("Not expected error tag", ErrorTag.DATA_MISSING, ex.getErrors().get(0).getErrorTag());
+ assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
}
/**