Modernize sal-rest-docgen tests a bit
[netconf.git] / restconf / sal-rest-docgen / src / test / java / org / opendaylight / controller / sal / rest / doc / impl / ApiDocServiceImplTest.java
index 63b37dd2b971764385fc403b33501989ff1f0eb2..61ee1ed28e846691731839eb20e51db6e30593a1 100644 (file)
@@ -7,20 +7,20 @@
  */
 package org.opendaylight.controller.sal.rest.doc.impl;
 
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import java.util.Optional;
 import javax.ws.rs.core.UriInfo;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 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.api.ApiDocService;
+import org.opendaylight.netconf.sal.rest.doc.impl.AllModulesDocGenerator;
 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGeneratorDraftO2;
 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGeneratorRFC8040;
 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl;
@@ -28,50 +28,42 @@ import org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorDraf
 import org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorRFC8040;
 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 ApiDocServiceImplTest {
+public final class ApiDocServiceImplTest 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 DocGenTestHelper helper;
-    private ApiDocService apiDocService;
 
+    private ApiDocService apiDocService;
 
-    @SuppressWarnings("resource")
     @Before
-    public void setUp() throws Exception {
-        this.helper = new DocGenTestHelper();
-        this.helper.setUp();
-
-        final EffectiveModelContext context = this.helper.createMockSchemaContext();
-        final DOMSchemaService schemaService = this.helper.createMockSchemaService(context);
-
+    public void before() {
         final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-        when(mountPoint.getSchemaContext()).thenReturn(context);
+        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));
-        MountPointSwaggerGeneratorDraft02 swagger =
-                new MountPointSwaggerGeneratorDraft02(schemaService, service);
-        swagger.getMountPointSwagger().onMountPointCreated(INSTANCE_ID);
-        this.apiDocService = new ApiDocServiceImpl(
-                swagger,
-                new MountPointSwaggerGeneratorRFC8040(schemaService, service),
-                new ApiDocGeneratorDraftO2(schemaService),
-                new ApiDocGeneratorRFC8040(schemaService));
+        final MountPointSwaggerGeneratorDraft02 mountPointDraft02 =
+                new MountPointSwaggerGeneratorDraft02(SCHEMA_SERVICE, service);
+        final MountPointSwaggerGeneratorRFC8040 mountPointRFC8040 =
+                new MountPointSwaggerGeneratorRFC8040(SCHEMA_SERVICE, service);
+        final ApiDocGeneratorDraftO2 apiDocGeneratorDraftO2 = new ApiDocGeneratorDraftO2(SCHEMA_SERVICE);
+        final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040 = new ApiDocGeneratorRFC8040(SCHEMA_SERVICE);
+        mountPointDraft02.getMountPointSwagger().onMountPointCreated(INSTANCE_ID);
+        final AllModulesDocGenerator allModulesDocGenerator = new AllModulesDocGenerator(apiDocGeneratorDraftO2,
+                apiDocGeneratorRFC8040);
+        apiDocService = new ApiDocServiceImpl(mountPointDraft02, mountPointRFC8040, apiDocGeneratorDraftO2,
+                apiDocGeneratorRFC8040, allModulesDocGenerator);
     }
 
     @Test
-    public void getListOfMounts() throws java.net.URISyntaxException, JsonProcessingException {
-        final UriInfo mockInfo = this.helper.createMockUriInfo(HTTP_URL);
+    public void getListOfMounts() throws Exception {
+        final UriInfo mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
         // simulate the behavior of JacksonJaxbJsonProvider
-        ObjectMapper mapper = new ObjectMapper();
-        String result = mapper.writer().writeValueAsString(
-                apiDocService.getListOfMounts(mockInfo).getEntity());
-        Assert.assertEquals("[{\"instance\":\"/nodes/node/123/\",\"id\":1}]", result);
+        final ObjectMapper mapper = new ObjectMapper();
+        final String result = mapper.writer().writeValueAsString(apiDocService.getListOfMounts(mockInfo).getEntity());
+        assertEquals("[{\"instance\":\"/nodes/node/123/\",\"id\":1}]", result);
     }
 }