Remove Bierman02 support from sal-rest-docgen
[netconf.git] / restconf / sal-rest-docgen / src / test / java / org / opendaylight / controller / sal / rest / doc / impl / MountPointSwaggerTest.java
index 7639871fb5af719d58d37de1447dd72052257715..1f241da3dd59121dd54e3c4f8947256d4e5b49be 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.sal.rest.doc.impl;
 
 import static org.junit.Assert.assertEquals;
@@ -15,7 +14,6 @@ import static org.mockito.Mockito.when;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Optional;
@@ -28,75 +26,62 @@ import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl.OAversion;
-import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl.URIType;
-import org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorDraft02;
+import org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorRFC8040;
 import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointSwagger;
 import org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-
-public class MountPointSwaggerTest {
 
+public final class MountPointSwaggerTest extends AbstractApiDocTest {
     private static final String HTTP_URL = "http://localhost/path";
     private static final YangInstanceIdentifier INSTANCE_ID = YangInstanceIdentifier.builder()
             .node(QName.create("", "nodes"))
             .node(QName.create("", "node"))
             .nodeWithKey(QName.create("", "node"), QName.create("", "id"), "123").build();
-    private static final String INSTANCE_URL = "/nodes/node/123/";
+    private static final String INSTANCE_URL = "/nodes/node=123/";
+
     private MountPointSwagger swagger;
-    private DocGenTestHelper helper;
 
-    @SuppressWarnings("resource")
     @Before
-    public void setUp() throws Exception {
-        this.helper = new DocGenTestHelper();
-        this.helper.setUp();
-
+    public void before() {
         // We are sharing the global schema service and the mount schema service
         // in our test.
         // OK for testing - real thing would have separate instances.
-        final EffectiveModelContext context = this.helper.createMockSchemaContext();
-        final DOMSchemaService schemaService = this.helper.createMockSchemaService(context);
-
         final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-        when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(schemaService));
+        when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(SCHEMA_SERVICE));
 
         final DOMMountPointService service = mock(DOMMountPointService.class);
         when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
 
-        final MountPointSwaggerGeneratorDraft02 generator =
-                new MountPointSwaggerGeneratorDraft02(schemaService, service);
-
-        this.swagger = generator.getMountPointSwagger();
+        swagger = new MountPointSwaggerGeneratorRFC8040(SCHEMA_SERVICE, service).getMountPointSwagger();
     }
 
     @Test()
-    public void getInstanceIdentifiers() throws Exception {
-        assertEquals(0, this.swagger.getInstanceIdentifiers().size());
-        this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of mount points
-        assertEquals(1, this.swagger.getInstanceIdentifiers().size());
-        assertEquals((Long) 1L, this.swagger.getInstanceIdentifiers().entrySet().iterator().next()
+    public void getInstanceIdentifiers() {
+        assertEquals(0, swagger.getInstanceIdentifiers().size());
+        swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of mount points
+        assertEquals(1, swagger.getInstanceIdentifiers().size());
+        assertEquals((Long) 1L, swagger.getInstanceIdentifiers().entrySet().iterator().next()
                 .getValue());
-        assertEquals(INSTANCE_URL, this.swagger.getInstanceIdentifiers().entrySet().iterator().next()
+        assertEquals(INSTANCE_URL, swagger.getInstanceIdentifiers().entrySet().iterator().next()
                 .getKey());
-        this.swagger.onMountPointRemoved(INSTANCE_ID); // remove ID from list of mount points
-        assertEquals(0, this.swagger.getInstanceIdentifiers().size());
+        swagger.onMountPointRemoved(INSTANCE_ID); // remove ID from list of mount points
+        assertEquals(0, swagger.getInstanceIdentifiers().size());
     }
 
     @Test
     public void testGetDataStoreApi() throws Exception {
-        final UriInfo mockInfo = this.helper.createMockUriInfo(HTTP_URL);
-        this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of mount points
+        final UriInfo mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
+        swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of mount points
 
-        final SwaggerObject mountPointApi = (SwaggerObject) this.swagger.getMountPointApi(mockInfo, 1L, "Datastores",
-                "-", URIType.DRAFT02, OAversion.V2_0);
+        final SwaggerObject mountPointApi = (SwaggerObject) swagger.getMountPointApi(mockInfo, 1L, "Datastores", "-",
+            OAversion.V2_0);
         assertNotNull("failed to find Datastore API", mountPointApi);
 
         final ObjectNode pathsObject = mountPointApi.getPaths();
         assertNotNull(pathsObject);
 
-        assertEquals("Unexpected api list size", 3, pathsObject.size());
+        assertEquals("Unexpected api list size", 2, pathsObject.size());
 
         final Set<String> actualUrls = new TreeSet<>();
 
@@ -115,10 +100,7 @@ public class MountPointSwaggerTest {
             assertNotNull("expected non-null desc on " + path, getOperation.get("description"));
         }
 
-        final Set<String> expectedUrls = new TreeSet<>(Arrays.asList(
-                "/restconf/config" + INSTANCE_URL + "yang-ext:mount",
-                "/restconf/operational" + INSTANCE_URL + "yang-ext:mount",
-                "/restconf/operations" + INSTANCE_URL + "yang-ext:mount"));
-        assertEquals(expectedUrls, actualUrls);
+        assertEquals(Set.of("/rests/data" + INSTANCE_URL + "yang-ext:mount",
+            "/rests/operations" + INSTANCE_URL + "yang-ext:mount"), actualUrls);
     }
 }