Test revision requirement in schema service 51/107351/11
authorlubos-cicut <lubos.cicut@pantheon.tech>
Thu, 21 Dec 2023 11:27:42 +0000 (12:27 +0100)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Wed, 7 Feb 2024 08:42:48 +0000 (08:42 +0000)
This patch adapt old tests, because they were using not existing
module.

JIRA: NETCONF-1160
Change-Id: I2ca913b69fb128d9e4aafa4baf1571c7db7650a6
Signed-off-by: Oleksandr Panasiuk <oleksandr.panasiuk@pantheon.tech>
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfModulesGetTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfSchemaServiceTest.java
restconf/restconf-nb/src/test/resources/parser-identifier/module-without-revision.yang [new file with mode: 0644]

index 65112273d2626f0ab30d0267c7d7a63b873831dd..b93a04b0828cedacd8a61614fba430bcf0ecf064 100644 (file)
@@ -173,6 +173,24 @@ class RestconfModulesGetTest extends AbstractRestconfTest {
         assertEquals(ErrorTags.RESOURCE_DENIED_TRANSPORT, error.getErrorTag());
     }
 
+    /**
+     * Positive test of getting <code>SchemaExportContext</code> 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
-     * <code>RestconfDocumentedException</code> and checking for correct error type, error tag and error status code.
+     * Positive test of getting <code>SchemaExportContext</code> 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);
     }
 
     /**
index 822f5ec60a86cd50c2b848b86c180a6c1fe5f0e2..160dc08ee8609f7a12d7f948a9699b4e2fed9725 100644 (file)
@@ -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
-     * <code>RestconfDocumentedException</code>. 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 (file)
index 0000000..3939472
--- /dev/null
@@ -0,0 +1,4 @@
+module module-without-revision {
+    namespace "module:without:revision";
+    prefix "mwr";
+}