From: lubos-cicut Date: Thu, 21 Dec 2023 11:27:42 +0000 (+0100) Subject: Test revision requirement in schema service X-Git-Tag: v7.0.0~54 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=7d907f45dc663a1b6d6059721d5f1fddfc849983;p=netconf.git Test revision requirement in schema service This patch adapt old tests, because they were using not existing module. JIRA: NETCONF-1160 Change-Id: I2ca913b69fb128d9e4aafa4baf1571c7db7650a6 Signed-off-by: Oleksandr Panasiuk Signed-off-by: lubos-cicut Signed-off-by: Ivan Hrasko Signed-off-by: lubos-cicut --- diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfModulesGetTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfModulesGetTest.java index 65112273d2..b93a04b082 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfModulesGetTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfModulesGetTest.java @@ -173,6 +173,24 @@ class RestconfModulesGetTest extends AbstractRestconfTest { assertEquals(ErrorTags.RESOURCE_DENIED_TRANSPORT, error.getErrorTag()); } + /** + * Positive test of getting SchemaExportContext behind mount point for module without revision. + * Expected module name, prefix and namespace are verified. + */ + @Test + void toSchemaExportContextFromIdentifierNullRevisionTest() { + mockMountPoint(); + + final var content = assertYang(MOUNT_POINT_IDENT, "module-without-revision", null); + + assertEquals(""" + module module-without-revision { + namespace module:without:revision; + prefix mwr; + } + """, content); + } + private void mockMountPoint() { doReturn(Optional.of(new FixedDOMSchemaService(MODEL_CONTEXT_ON_MOUNT_POINT))).when(mountPoint) .getService(DOMSchemaService.class); @@ -185,15 +203,19 @@ class RestconfModulesGetTest extends AbstractRestconfTest { } /** - * Negative test of module revision validation when there is no revision. Test fails catching - * RestconfDocumentedException and checking for correct error type, error tag and error status code. + * Positive test of getting SchemaExportContext for module without revision. + * Expected module name, prefix and namespace are verified. */ @Test - void validateAndGetRevisionNotSuppliedTest() { - final var error = assertError(ar -> restconf.modulesYangGET("module", null, ar)); - assertEquals("Source module not found", error.getErrorMessage()); - assertEquals(ErrorType.APPLICATION, error.getErrorType()); - assertEquals(ErrorTag.DATA_MISSING, error.getErrorTag()); + void validateAndGetModuleWithoutRevisionTest() { + final var content = assertYang(null, "module-without-revision", null); + + assertEquals(""" + module module-without-revision { + namespace module:without:revision; + prefix mwr; + } + """, content); } /** diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfSchemaServiceTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfSchemaServiceTest.java index 822f5ec60a..160dc08ee8 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfSchemaServiceTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfSchemaServiceTest.java @@ -16,6 +16,7 @@ import static org.opendaylight.restconf.nb.jaxrs.AbstractRestconfTest.assertEnti import static org.opendaylight.restconf.nb.jaxrs.AbstractRestconfTest.assertError; import com.google.common.util.concurrent.Futures; +import java.io.IOException; import java.io.Reader; import java.util.List; import org.junit.Before; @@ -142,15 +143,15 @@ public class RestconfSchemaServiceTest { } /** - * Try to get schema with identifier which does not contain revision catching - * RestconfDocumentedException. Error type, error tag and error status code are compared to expected - * values. + * Try to get schema with identifier which does not contain revision catching and check if the correct module + * was found. */ @Test - public void getSchemaWithoutRevisionTest() { - final var error = assertError(ar -> restconf.modulesYinGET("module", null, ar)); - assertEquals("Source module not found", error.getErrorMessage()); - assertEquals(ErrorType.APPLICATION, error.getErrorType()); - assertEquals(ErrorTag.DATA_MISSING, error.getErrorTag()); + public void getSchemaWithoutRevisionTest() throws IOException { + doReturn(Futures.immediateFuture(yangSource)).when(sourceProvider) + .getYangTexttSource(new SourceIdentifier("module-without-revision", (Revision) null)); + doReturn(yangReader).when(yangSource).openStream(); + assertSame(yangReader, assertEntity(Reader.class, 200, + ar -> restconf.modulesYangGET("module-without-revision", null, ar))); } } diff --git a/restconf/restconf-nb/src/test/resources/parser-identifier/module-without-revision.yang b/restconf/restconf-nb/src/test/resources/parser-identifier/module-without-revision.yang new file mode 100644 index 0000000000..3939472636 --- /dev/null +++ b/restconf/restconf-nb/src/test/resources/parser-identifier/module-without-revision.yang @@ -0,0 +1,4 @@ +module module-without-revision { + namespace "module:without:revision"; + prefix "mwr"; +}