Convert apidocs to new web API
[netconf.git] / restconf / sal-rest-docgen / src / test / java / org / opendaylight / controller / sal / rest / doc / impl / MountPointSwaggerTest.java
index 06f5c819e83c6b197105e49b5de030f8a8c9b973..9703c2ba5b0c61bdb3637d67f329530bc73231f3 100644 (file)
@@ -11,8 +11,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+
 import com.google.common.base.Optional;
-import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
@@ -23,6 +23,7 @@ import org.junit.Test;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorDraft02;
 import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointSwagger;
 import org.opendaylight.netconf.sal.rest.doc.swagger.Api;
 import org.opendaylight.netconf.sal.rest.doc.swagger.ApiDeclaration;
@@ -36,21 +37,36 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 public class MountPointSwaggerTest {
 
     private static final String HTTP_URL = "http://localhost/path";
-    private static final YangInstanceIdentifier instanceId = 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 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 MountPointSwagger swagger;
     private DocGenTestHelper helper;
     private SchemaContext schemaContext;
 
+    @SuppressWarnings("resource")
     @Before
     public void setUp() throws Exception {
-        this.swagger = new MountPointSwagger();
         this.helper = new DocGenTestHelper();
         this.helper.setUp();
         this.schemaContext = this.helper.getSchemaContext();
+
+        // We are sharing the global schema service and the mount schema service
+        // in our test.
+        // OK for testing - real thing would have seperate instances.
+        final SchemaContext context = this.helper.createMockSchemaContext();
+        final SchemaService schemaService = this.helper.createMockSchemaService(context);
+
+        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+        when(mountPoint.getSchemaContext()).thenReturn(context);
+
+        final DOMMountPointService service = mock(DOMMountPointService.class);
+        when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
+
+        MountPointSwaggerGeneratorDraft02 generator = new MountPointSwaggerGeneratorDraft02(schemaService, service);
+        this.swagger = generator.getMountPointSwagger();
     }
 
     @Test()
@@ -62,25 +78,23 @@ public class MountPointSwaggerTest {
 
     @Test()
     public void getInstanceIdentifiers() throws Exception {
-        final UriInfo mockInfo = setUpSwaggerForDocGeneration();
-
         assertEquals(0, this.swagger.getInstanceIdentifiers().size());
-        this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+        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()
                 .getValue());
         assertEquals(INSTANCE_URL, this.swagger.getInstanceIdentifiers().entrySet().iterator().next()
                 .getKey());
-        this.swagger.onMountPointRemoved(instanceId); // remove ID from list of mount
+        this.swagger.onMountPointRemoved(INSTANCE_ID); // remove ID from list of mount
                                                  // points
         assertEquals(0, this.swagger.getInstanceIdentifiers().size());
     }
 
     @Test
     public void testGetResourceListGoodId() throws Exception {
-        final UriInfo mockInfo = setUpSwaggerForDocGeneration();
-        this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+        final UriInfo mockInfo = this.helper.createMockUriInfo(HTTP_URL);
+        this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
                                                  // mount points
         final ResourceList resourceList = this.swagger.getResourceList(mockInfo, 1L);
 
@@ -95,9 +109,10 @@ public class MountPointSwaggerTest {
 
     @Test
     public void testGetDataStoreApi() throws Exception {
-        final UriInfo mockInfo = setUpSwaggerForDocGeneration();
-        this.swagger.onMountPointCreated(instanceId); // add this ID into the list of
+        final UriInfo mockInfo = this.helper.createMockUriInfo(HTTP_URL);
+        this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
                                                  // mount points
+
         final ApiDeclaration mountPointApi = this.swagger.getMountPointApi(mockInfo, 1L, "Datastores", "-");
         assertNotNull("failed to find Datastore API", mountPointApi);
         final List<Api> apis = mountPointApi.getApis();
@@ -114,29 +129,9 @@ public class MountPointSwaggerTest {
                     .getNotes());
         }
         final Set<String> expectedApis = new TreeSet<>(Arrays.asList(new String[] {
-                "/config/" + INSTANCE_URL + "yang-ext:mount/",
-                "/operational/" + INSTANCE_URL + "yang-ext:mount/",
-                "/operations/" + INSTANCE_URL + "yang-ext:mount/", }));
+            "/restconf/config" + INSTANCE_URL + "yang-ext:mount",
+            "/restconf/operational" + INSTANCE_URL + "yang-ext:mount",
+            "/restconf/operations" + INSTANCE_URL + "yang-ext:mount",}));
         assertEquals(expectedApis, actualApis);
     }
-
-    protected UriInfo setUpSwaggerForDocGeneration() throws URISyntaxException {
-        final UriInfo mockInfo = this.helper.createMockUriInfo(HTTP_URL);
-        // We are sharing the global schema service and the mount schema service
-        // in our test.
-        // OK for testing - real thing would have seperate instances.
-        final SchemaContext context = this.helper.createMockSchemaContext();
-        final SchemaService schemaService = this.helper.createMockSchemaService(context);
-
-        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-        when(mountPoint.getSchemaContext()).thenReturn(context);
-
-        final DOMMountPointService service = mock(DOMMountPointService.class);
-        when(service.getMountPoint(instanceId)).thenReturn(Optional.of(mountPoint));
-        this.swagger.setMountService(service);
-        this.swagger.setGlobalSchema(schemaService);
-
-        return mockInfo;
-    }
-
 }