Single out RestconfConstants.MOUNT 62/96862/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 10 Jul 2021 05:18:02 +0000 (07:18 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 10 Jul 2021 05:18:02 +0000 (07:18 +0200)
This constant should be used via its PathArgument equivalent. Reduce
its use in tests and mark it for removal.

Change-Id: Ia3b75b95b236e35167ffb213c138930ed419a7f1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfSchemaServiceTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java

index 93f6e754baec56e5d213c09c00a629351b719ca6..12363a9bb511c579d899b51d2d32af317264d5e5 100644 (file)
@@ -13,11 +13,16 @@ import com.google.common.base.Splitter;
  * Util class for Restconf constants.
  */
 public final class RestconfConstants {
-    public static final String MOUNT = "yang-ext:mount";
     public static final Splitter SLASH_SPLITTER = Splitter.on('/');
     public static final String BASE_URI_PATTERN = "rests";
     public static final String NOTIF = "notif";
 
+    // FIXME: Remove this constant. All logic relying on this constant should instead rely on YangInstanceIdentifier
+    //        equivalent coming out of argument parsing. This may require keeping List<YangInstanceIdentifier> as the
+    //        nested path split on yang-ext:mount. This splitting needs to be based on consulting the
+    //        EffectiveModelContext and allowing it only where yang-ext:mount is actually used in models.
+    public static final String MOUNT = "yang-ext:mount";
+
     private RestconfConstants() {
         // Hidden on purpose
     }
index 305b93ff7a95829daa5c8f34ea992eee13158842..a913a5079fd4ccede7b32c928c8d9dfb0f2433bf 100644 (file)
@@ -249,13 +249,12 @@ public final class ParserIdentifier {
                 final String current = componentIter.next();
 
                 if (RestconfConstants.MOUNT.equals(current)) {
-                    pathBuilder.append("/");
-                    pathBuilder.append(RestconfConstants.MOUNT);
+                    pathBuilder.append('/').append(RestconfConstants.MOUNT);
                     break;
                 }
 
                 if (pathBuilder.length() != 0) {
-                    pathBuilder.append("/");
+                    pathBuilder.append('/');
                 }
 
                 pathBuilder.append(current);
index 7499b53212d1ab0400304f28d181d97ecbb76a6b..f2a6dbe73fc56e3799c6494f475e1881eb7f4bd7 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -46,9 +45,9 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
  */
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class RestconfSchemaServiceTest {
-    private static final String MOUNT_POINT = "mount-point-1:cont" + "/" + RestconfConstants.MOUNT + "/";
-    private static final String NULL_MOUNT_POINT = "mount-point-2:cont" + "/" + RestconfConstants.MOUNT + "/";
-    private static final String NOT_EXISTING_MOUNT_POINT = "mount-point-3:cont" + "/" + RestconfConstants.MOUNT + "/";
+    private static final String MOUNT_POINT = "mount-point-1:cont/yang-ext:mount/";
+    private static final String NULL_MOUNT_POINT = "mount-point-2:cont/yang-ext:mount/";
+    private static final String NOT_EXISTING_MOUNT_POINT = "mount-point-3:cont/yang-ext:mount/";
 
     private static final String TEST_MODULE = "module1/2014-01-01";
     private static final String TEST_MODULE_BEHIND_MOUNT_POINT = "module1-behind-mount-point/2014-02-03";
index 2b6e7d6a43ed92b0e5e7b96c6591ad2356a302ea..1b1111b131b346b4b966ab8ec039bc7a6668046e 100644 (file)
@@ -50,12 +50,10 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ParserIdentifierTest {
     // mount point identifier
-    private static final String MOUNT_POINT_IDENT =
-            "mount-point:mount-container/point-number" + "/" + RestconfConstants.MOUNT;
+    private static final String MOUNT_POINT_IDENT = "mount-point:mount-container/point-number/yang-ext:mount";
 
     // invalid mount point identifier
-    private static final String INVALID_MOUNT_POINT_IDENT =
-            "mount-point:point-number" + "/" + RestconfConstants.MOUNT;
+    private static final String INVALID_MOUNT_POINT_IDENT = "mount-point:point-number/yang-ext:mount";
 
     // test identifier + expected result
     private static final String TEST_IDENT =
@@ -249,7 +247,7 @@ public class ParserIdentifierTest {
     @Test
     public void toInstanceIdentifierMissingMountPointNegativeTest() {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
-            () -> ParserIdentifier.toInstanceIdentifier("" + "/" + RestconfConstants.MOUNT, SCHEMA_CONTEXT,
+            () -> ParserIdentifier.toInstanceIdentifier("/yang-ext:mount", SCHEMA_CONTEXT,
                 Optional.of(this.mountPointService)));
         assertEquals("Not expected error type", RestconfError.ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
         assertEquals("Not expected error tag", ErrorTag.RESOURCE_DENIED_TRANSPORT, ex.getErrors().get(0).getErrorTag());
@@ -263,7 +261,7 @@ public class ParserIdentifierTest {
     @Test
     public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
         RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
-            () -> ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, SCHEMA_CONTEXT, Optional.empty()));
+            () -> ParserIdentifier.toInstanceIdentifier("yang-ext:mount", SCHEMA_CONTEXT, Optional.empty()));
         assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
         assertEquals("Not expected error tag", ErrorTag.OPERATION_FAILED, ex.getErrors().get(0).getErrorTag());
         assertEquals("Not expected error status code", 500, ex.getErrors().get(0).getErrorTag().getStatusCode());
@@ -565,7 +563,7 @@ public class ParserIdentifierTest {
     @Test
     public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
         assertThrows(IllegalStateException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
-                SCHEMA_CONTEXT, "/" + RestconfConstants.MOUNT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
+                SCHEMA_CONTEXT, "/yang-ext:mount/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
                 this.mockMountPointService, sourceProvider));
     }