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;
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;
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();
+ .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()
@Test()
public void getInstanceIdentifiers() throws Exception {
- final UriInfo mockInfo = setUpSwaggerForDocGeneration();
-
assertEquals(0, this.swagger.getInstanceIdentifiers().size());
this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
// mount points
@Test
public void testGetResourceListGoodId() throws Exception {
- final UriInfo mockInfo = setUpSwaggerForDocGeneration();
+ 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);
@Test
public void testGetDataStoreApi() throws Exception {
- final UriInfo mockInfo = setUpSwaggerForDocGeneration();
+ final UriInfo mockInfo = this.helper.createMockUriInfo(HTTP_URL);
this.swagger.onMountPointCreated(INSTANCE_ID); // add this ID into the list of
// mount points
.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(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
- this.swagger.setMountService(service);
- this.swagger.setGlobalSchema(schemaService);
-
- return mockInfo;
- }
-
}