- // schema with testing modules
- private SchemaContext schemaContext;
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Before
- public void setup() throws Exception {
- schemaContext = TestRestconfUtils.loadSchemaContext("/modules/restconf-module-testing");
- }
-
- /**
- * Positive test for getting <code>DataSchemaNode</code> from Restconf module for schema node name equals to
- * {@link RestconfModule#MODULE_LIST_SCHEMA_NODE} when this node can be found.
- */
- @Test
- public void getRestconfSchemaNodeListModuleTest() {
- final DataSchemaNode dataSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("ietf-restconf"),
- RestconfModule.MODULE_LIST_SCHEMA_NODE);
-
- assertNotNull("Existing schema node "+ RestconfModule.MODULE_LIST_SCHEMA_NODE + " should be found",
- dataSchemaNode);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getLocalName(), RestconfModule.MODULE_LIST_SCHEMA_NODE);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getNamespace().toString(), RestconfModule.NAMESPACE);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getFormattedRevision(), RestconfModule.REVISION);
- }
-
- /**
- * Positive test for getting <code>DataSchemaNode</code> from Restconf module for schema node name equals to
- * {@link MonitoringModule#STREAM_LIST_SCHEMA_NODE} when this node can be found.
- */
- @Test
- public void getRestconfSchemaNodeListStreamTest() {
- final DataSchemaNode dataSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("ietf-restconf"),
- MonitoringModule.STREAM_LIST_SCHEMA_NODE);
-
- assertNotNull("Existing schema node " + MonitoringModule.STREAM_LIST_SCHEMA_NODE + " should be found",
- dataSchemaNode);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getLocalName(), MonitoringModule.STREAM_LIST_SCHEMA_NODE);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getNamespace().toString(), RestconfModule.NAMESPACE);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getFormattedRevision(), RestconfModule.REVISION);
- }
-
- /**
- * Positive test for getting <code>DataSchemaNode</code> from Restconf module for schema node name equals to
- * {@link RestconfModule#MODULES_CONTAINER_SCHEMA_NODE} when this node can be found.
- */
- @Test
- public void getRestconfSchemaNodeContainerModulesTest() {
- final DataSchemaNode dataSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("ietf-restconf"),
- RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
-
- assertNotNull("Existing schema node " + RestconfModule.MODULES_CONTAINER_SCHEMA_NODE + "should be found",
- dataSchemaNode);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getLocalName(), RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getNamespace().toString(), RestconfModule.NAMESPACE);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getFormattedRevision(), RestconfModule.REVISION);
- }
-
- /**
- * Positive test for getting <code>DataSchemaNode</code> from Restconf module for schema node name equals to
- * {@link MonitoringModule#STREAMS_CONTAINER_SCHEMA_NODE} when this node can be found.
- */
- @Test
- public void getRestconfSchemaNodeContainerStreamsTest() {
- final DataSchemaNode dataSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("ietf-restconf"),
- MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE);
-
- assertNotNull("Existing schema node " + MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE + " should be found",
- dataSchemaNode);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getLocalName(), MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getNamespace().toString(), RestconfModule.NAMESPACE);
- assertEquals("Incorrect schema node was returned",
- dataSchemaNode.getQName().getFormattedRevision(), RestconfModule.REVISION);
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module when Restconf module is
- * <code>null</code>. Test is expected to fail catching <code>NullPointerException</code>.
- */
- @Test
- public void getRestconfSchemaNodeNullRestconfModuleNegativeTest() {
- thrown.expect(NullPointerException.class);
- RestconfSchemaUtil.getRestconfSchemaNode(null, RestconfModule.RESTCONF_CONTAINER_SCHEMA_NODE);
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module when name of the schema node name is
- * <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
- */
- @Test
- public void getRestconfSchemaNodeNullSchemaNodeNameNegativeTest() {
- thrown.expect(NullPointerException.class);
- RestconfSchemaUtil.getRestconfSchemaNode(getTestingRestconfModule("ietf-restconf"), null);
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module when name of the schema node name
- * references to not existing node. Test is expected to fail catching code>RestconfDocumentedException</code> and
- * checking expected error type, error tag and error status code.
- */
- @Test
- public void getRestconfSchemaNodeNotExistingSchemaNodeNameNegativeTest() {
- try {
- RestconfSchemaUtil.getRestconfSchemaNode(getTestingRestconfModule("ietf-restconf"), "not-existing-node");
- fail("Test should fail due to not-existing node name");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Error type is not correct",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Error tag is not correct",
- RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals("Error status code is not correct",
- 404, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module for schema node name equals to
- * {@link RestconfModule#MODULES_CONTAINER_SCHEMA_NODE} when this node cannot be found.
- * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
- * compared to expected values.
- */
- @Test
- public void getRestconfSchemaNodeContainerModulesNegativeTest() {
- try {
- RestconfSchemaUtil.getRestconfSchemaNode(getTestingRestconfModule(
- "restconf-module-with-missing-container-modules"), RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
- fail("Test should fail due to missing " + RestconfModule.MODULES_CONTAINER_SCHEMA_NODE + " node");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Error type is not correct",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Error tag is not correct",
- RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals("Error status code is not correct",
- 404, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module for schema node name equals to
- * {@link RestconfModule#MODULE_LIST_SCHEMA_NODE} when this node cannot be found.
- * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code are
- * compared to expected values.
- */
- @Test
- public void getRestconfSchemaNodeListModuleNegativeTest() {
- try {
- RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("restconf-module-with-missing-list-module"),
- RestconfModule.MODULE_LIST_SCHEMA_NODE);
- fail("Test should fail due to missing " + RestconfModule.MODULE_LIST_SCHEMA_NODE + " node");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Error type is not correct",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Error tag is not correct",
- RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals("Error status code is not correct",
- 404, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module for schema node name equals to
- * {@link MonitoringModule#STREAMS_CONTAINER_SCHEMA_NODE} when this node cannot
- * be found. <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code
- * are compared to expected values.
- */
- @Test
- public void getRestconfSchemaNodeContainerStreamsNegativeTest() {
- try {
- RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("restconf-module-with-missing-container-streams"),
- MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE);
- fail("Test should fail due to missing " + MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE + " node");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Error type is not correct",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Error tag is not correct",
- RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals("Error status code is not correct",
- 404, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module for schema node name equals to
- * {@link MonitoringModule#STREAM_LIST_SCHEMA_NODE} when this node cannot be found.
- * <code>RestconfDocumentedException</code> is expected and error type, error tag and error status code
- * are compared to expected values.
- */
- @Test
- public void getRestconfSchemaNodeListStreamNegativeTest() {
- try {
- RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("restconf-module-with-missing-list-stream"),
- MonitoringModule.STREAM_LIST_SCHEMA_NODE);
- fail("Test should fail due to missing " + MonitoringModule.STREAM_LIST_SCHEMA_NODE + " node");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Error type is not correct",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Error tag is not correct",
- RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals("Error status code is not correct",
- 404, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module when Restconf module does not
- * contains restconf grouping. Test is expected to fail with <code>RestconfDocumentedException</code> and error
- * type, error tag and error status code are compared to expected values.
- */
- @Test
- public void getRestconfSchemaNodeMissingRestconfGroupingNegativeTest() {
- try {
- RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("restconf-module-with-missing-grouping-restconf"),
- RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
- fail("Test should fail due to missing restconf grouping in Restconf module");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Error type is not correct",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Error tag is not correct",
- RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals("Error status code is not correct",
- 404, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
- }
-
- /**
- * Negative test for getting <code>DataSchemaNode</code> from Restconf module when Restconf module contains
- * restconf grouping which does not contain any child nodes. Test is expected to fail with
- * <code>NoSuchElementException</code>.
- */
- @Test
- public void getRestconfSchemaNodeEmptyRestconfGroupingNegativeTest() {
- thrown.expect(NoSuchElementException.class);
- RestconfSchemaUtil.getRestconfSchemaNode(
- getTestingRestconfModule("restconf-module-with-empty-grouping-restconf"),
- RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
- }
-
- /**
- * Positive test trying to find <code>DataSchemaNode</code> of {@link RestconfModule#RESTCONF_GROUPING_SCHEMA_NODE}
- * in Restconf module groupings collection.
- */
- @Test
- public void findSchemaNodeInCollectionTest() {
- final SchemaNode schemaNode = RestconfSchemaUtil.findSchemaNodeInCollection(
- getTestingRestconfModule("ietf-restconf").getGroupings(),
- RestconfModule.RESTCONF_GROUPING_SCHEMA_NODE);
-
- assertNotNull("Restconf grouping schema node should be found", schemaNode);
- assertEquals("Incorrect grouping was returned",
- schemaNode.getQName().getLocalName(), RestconfModule.RESTCONF_GROUPING_SCHEMA_NODE);
- assertEquals("Incorrect grouping was returned",
- schemaNode.getQName().getNamespace().toString(), RestconfModule.NAMESPACE);
- assertEquals("Incorrect grouping was returned",
- schemaNode.getQName().getFormattedRevision(), RestconfModule.REVISION);
- }
-
- /**
- * Negative test trying to find <code>DataSchemaNode</code> of not existing groupings schema node name in Restconf
- * module grouping collection. Test is expected to fail catching <code>RestconfDocumentedException</code> and
- * checking for correct error type, error tag and error status code.
- */
- @Test
- public void findSchemaNodeInCollectionNegativeTest() {
- try {
- RestconfSchemaUtil.findSchemaNodeInCollection(
- getTestingRestconfModule("ietf-restconf").getGroupings(), "not-existing-grouping");
- fail("Test should fail due to missing not-existing grouping in Restconf grouping collection");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Error type is not correct",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Error tag is not correct",
- RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals("Error status code is not correct",
- 404, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
- }