X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Fsal-rest-docgen%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fdoc%2Fimpl%2FMountPointSwaggerTest.java;h=9703c2ba5b0c61bdb3637d67f329530bc73231f3;hb=588a9496bd3ccadc3bbfbe6a2d6d15223078ac85;hp=b04064577465679862e4436bcac3c9302bcf5b7e;hpb=698006bd45dcb38043fdd74980893307d2bc9257;p=netconf.git diff --git a/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java b/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java index b040645774..9703c2ba5b 100644 --- a/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java +++ b/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java @@ -13,7 +13,6 @@ 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; @@ -24,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; @@ -37,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 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() @@ -63,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); @@ -96,8 +109,8 @@ 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", "-"); @@ -116,29 +129,9 @@ public class MountPointSwaggerTest { .getNotes()); } final Set 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; - } - }