Remove static RestconfImpl 96/70996/1
authorTom Pantelis <tompantelis@gmail.com>
Mon, 16 Apr 2018 21:40:31 +0000 (17:40 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Mon, 16 Apr 2018 21:40:31 +0000 (17:40 -0400)
The RestconfImpl does not need to be static as it is indirectly
shared between the web and blueprint instantiated components via
the StatisticsRestconfServiceWrapper. Also code using the
StatisticsRestconfServiceWrapper was modified to reference it
non-statically except for the RestconfApplication. This will be
cleaned up when converted to use the new programmtic web API.

Change-Id: I96a0c7724c642db9b2fbe0d78dc79c9c6efc47ad
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
21 files changed:
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java
restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/input/to/cnsn/test/RestPutListDataTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/Bug8072Test.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CodecsExceptionsCatchingTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/JSONRestconfServiceImplTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutConfigTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/test/RestStreamTest.java

index 882ac2e9163dd2f9f77fdf00aecba9b62b79f90c..9dd5a59ddae62d96fa245afa3bc354ed46d94bd2 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYinBodyWri
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaRetrievalServiceImpl;
 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.netconf.sal.restconf.impl.StatisticsRestconfServiceWrapper;
 
 public class RestconfApplication extends Application {
@@ -38,10 +37,7 @@ public class RestconfApplication extends Application {
         final Set<Object> singletons = new HashSet<>();
         final ControllerContext controllerContext = ControllerContext.getInstance();
         final BrokerFacade brokerFacade = BrokerFacade.getInstance();
-        final RestconfImpl restconfImpl = RestconfImpl.getInstance();
         final SchemaRetrievalServiceImpl schemaRetrieval = new SchemaRetrievalServiceImpl(controllerContext);
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
         singletons.add(controllerContext);
         singletons.add(brokerFacade);
         singletons.add(schemaRetrieval);
index 47c4f487c903aab0ca7fcbc41df5c05b0e9ec98d..50b23594daf75b983e768956f872967a448011f4 100644 (file)
@@ -19,6 +19,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.List;
 import javax.ws.rs.core.MediaType;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.netconf.sal.rest.api.RestconfService;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.JsonToPatchBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
@@ -51,9 +52,11 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
     private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];
 
     private final ControllerContext controllerContext;
+    private final RestconfService restconfService;
 
-    public JSONRestconfServiceImpl(ControllerContext controllerContext) {
+    public JSONRestconfServiceImpl(ControllerContext controllerContext, RestconfService restconfService) {
         this.controllerContext = controllerContext;
+        this.restconfService = restconfService;
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
@@ -71,7 +74,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
         LOG.debug("Parsed NormalizedNode: {}", context.getData());
 
         try {
-            RestconfImpl.getInstance().updateConfigurationData(uriPath, context, new SimpleUriInfo(uriPath));
+            restconfService.updateConfigurationData(uriPath, context, new SimpleUriInfo(uriPath));
         } catch (final Exception e) {
             propagateExceptionAs(uriPath, e, "PUT");
         }
@@ -93,7 +96,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
         LOG.debug("Parsed NormalizedNode: {}", context.getData());
 
         try {
-            RestconfImpl.getInstance().createConfigurationData(uriPath, context, new SimpleUriInfo(uriPath));
+            restconfService.createConfigurationData(uriPath, context, new SimpleUriInfo(uriPath));
         } catch (final Exception e) {
             propagateExceptionAs(uriPath, e, "POST");
         }
@@ -105,7 +108,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
         LOG.debug("delete: uriPath: {}", uriPath);
 
         try {
-            RestconfImpl.getInstance().deleteConfigurationData(uriPath);
+            restconfService.deleteConfigurationData(uriPath);
         } catch (final Exception e) {
             propagateExceptionAs(uriPath, e, "DELETE");
         }
@@ -121,9 +124,9 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
             NormalizedNodeContext readData;
             final SimpleUriInfo uriInfo = new SimpleUriInfo(uriPath);
             if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
-                readData = RestconfImpl.getInstance().readConfigurationData(uriPath, uriInfo);
+                readData = restconfService.readConfigurationData(uriPath, uriInfo);
             } else {
-                readData = RestconfImpl.getInstance().readOperationalData(uriPath, uriInfo);
+                readData = restconfService.readOperationalData(uriPath, uriInfo);
             }
 
             final Optional<String> result = Optional.of(toJson(readData));
@@ -164,9 +167,9 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
                         .getInstanceIdentifier());
                 LOG.debug("Parsed NormalizedNode: {}", inputContext.getData());
 
-                outputContext = RestconfImpl.getInstance().invokeRpc(uriPath, inputContext, null);
+                outputContext = restconfService.invokeRpc(uriPath, inputContext, null);
             } else {
-                outputContext = RestconfImpl.getInstance().invokeRpc(uriPath, "", null);
+                outputContext = restconfService.invokeRpc(uriPath, "", null);
             }
 
             if (outputContext.getData() != null) {
@@ -198,7 +201,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
         LOG.debug("Parsed NormalizedNode: {}", context.getData());
 
         try {
-            PatchStatusContext patchStatusContext = RestconfImpl.getInstance()
+            PatchStatusContext patchStatusContext = restconfService
                 .patchConfigurationData(context, new SimpleUriInfo(uriPath));
             output = toJson(patchStatusContext);
         } catch (final Exception e) {
index aac9645c5a277a7a12d805ccd7037322c6af2b03..e61e97379561da5d0598c12b6a06c9e1bc2a165c 100644 (file)
@@ -117,9 +117,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class RestconfImpl implements RestconfService {
-
-    private static final RestconfImpl INSTANCE = new RestconfImpl();
-
     /**
      * Notifications are served on port 8181.
      */
@@ -174,23 +171,17 @@ public final class RestconfImpl implements RestconfService {
             .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true)
             .appendOffset("+HH:MM", "Z").toFormatter();
 
-    private BrokerFacade broker;
+    private final BrokerFacade broker;
 
-    private ControllerContext controllerContext;
+    private final ControllerContext controllerContext;
 
-    public void setBroker(final BrokerFacade broker) {
+    private RestconfImpl(BrokerFacade broker, ControllerContext controllerContext) {
         this.broker = broker;
-    }
-
-    public void setControllerContext(final ControllerContext controllerContext) {
         this.controllerContext = controllerContext;
     }
 
-    private RestconfImpl() {
-    }
-
-    public static RestconfImpl getInstance() {
-        return INSTANCE;
+    public static RestconfImpl newInstance(BrokerFacade broker, ControllerContext controllerContext) {
+        return new RestconfImpl(broker, controllerContext);
     }
 
     @Override
index 5870c5d5a787a0c3d4af4f74636d1545cf3fbb32..19d34af0704c14e782ff5ba977ef54fd2711c81b 100644 (file)
@@ -27,11 +27,13 @@ public class RestconfProviderImpl extends AbstractMXBean
         implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
     private final IpAddress websocketAddress;
     private final PortNumber websocketPort;
-    private final StatisticsRestconfServiceWrapper stats = StatisticsRestconfServiceWrapper.getInstance();
+    private final StatisticsRestconfServiceWrapper stats;
     private Thread webSocketServerThread;
 
-    public RestconfProviderImpl(IpAddress websocketAddress, PortNumber websocketPort) {
+    public RestconfProviderImpl(StatisticsRestconfServiceWrapper stats, IpAddress websocketAddress,
+            PortNumber websocketPort) {
         super("Draft02ProviderStatistics", "restconf-connector", null);
+        this.stats = Preconditions.checkNotNull(stats);
         this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
         this.websocketPort = Preconditions.checkNotNull(websocketPort);
     }
index a6c2a8d7c4f886c33c96e449a1dc11a7ea2ed2e1..e6f2839344eb2949fc3e86201e1729f75d7e495a 100644 (file)
@@ -36,19 +36,29 @@ public final class StatisticsRestconfServiceWrapper implements RestconfService {
     AtomicLong failurePut = new AtomicLong();
     AtomicLong failureDelete = new AtomicLong();
 
-    private static final StatisticsRestconfServiceWrapper INSTANCE =
-            new StatisticsRestconfServiceWrapper(RestconfImpl.getInstance());
+    private static final StatisticsRestconfServiceWrapper INSTANCE = new StatisticsRestconfServiceWrapper();
 
-    final RestconfService delegate;
+    private RestconfService delegate;
+
+    @Deprecated
+    private StatisticsRestconfServiceWrapper() {
+    }
 
     private StatisticsRestconfServiceWrapper(final RestconfService delegate) {
         this.delegate = delegate;
     }
 
+    @Deprecated
     public static StatisticsRestconfServiceWrapper getInstance() {
         return INSTANCE;
     }
 
+    public static StatisticsRestconfServiceWrapper newInstance(RestconfService delegate) {
+        INSTANCE.delegate = delegate;
+        return INSTANCE;
+        //return new StatisticsRestconfServiceWrapper(delegate);
+    }
+
     @Override
     public Object getRoot() {
         return this.delegate.getRoot();
index 4286306c21907b8171ce1b9b071d95779853aabf..aeb2b6f21bd17d503fdad420db05d4e5cd26f05b 100644 (file)
     <argument ref="controllerContext"/>
   </bean>
 
+  <bean id="restconfImpl" class="org.opendaylight.netconf.sal.restconf.impl.RestconfImpl"
+      factory-method="newInstance">
+    <argument ref="brokerFacade"/>
+    <argument ref="controllerContext"/>
+  </bean>
+
+  <bean id="statsServiceWrapper" class="org.opendaylight.netconf.sal.restconf.impl.StatisticsRestconfServiceWrapper"
+      factory-method="newInstance">
+    <argument ref="restconfImpl"/>
+  </bean>
+
   <bean id="restconfProviderDraft02" class="org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl"
           init-method="start" destroy-method="close">
+    <argument ref="statsServiceWrapper"/>
     <argument ref="webSocketAddress"/>
     <argument ref="webSocketPort"/>
   </bean>
@@ -79,6 +91,7 @@
       class="org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl"
       destroy-method="close">
     <argument ref="controllerContext"/>
+    <argument ref="restconfImpl"/>
   </bean>
 
   <service ref="jsonRestconfServiceDraft02" odl:type="default"
index 7d1d524d40009f8778b700c2016f628dad2a4e36..58358d7950584e1928192979932b52be0f28cb77 100644 (file)
@@ -71,9 +71,7 @@ public class RestPutListDataTest {
     public void initialize() throws FileNotFoundException {
         final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContextTestModule);
         brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
         final PutResult result = mock(PutResult.class);
         when(brokerFacade.commitConfigurationDataPut(any(SchemaContext.class), any(YangInstanceIdentifier.class),
                 any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString()))
index a6dbef2c3a93b7bd4024cccb5e3cb00e5d4d501e..1ff1f706a24236ed4e531d87a2dfe06658dad843 100644 (file)
@@ -20,9 +20,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
-import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -47,11 +45,6 @@ public class Bug8072Test {
         final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
         doReturn(mountPointContext).when(mountInstance).getSchemaContext();
-
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
-        final RestconfImpl restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
     }
 
     @BeforeClass
index a671a6c85a42481b3aab3af52d234a981244a9dc..bd5af828b365f098883029ee86f0fc5edc1b8933 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.sal.restconf.impl.test;
 
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
 
 import java.io.FileNotFoundException;
 import javax.ws.rs.client.Entity;
@@ -24,8 +25,8 @@ import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
-import org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper;
 import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
+import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -38,10 +39,9 @@ public class CodecsExceptionsCatchingTest extends JerseyTest {
 
     @Before
     public void init() throws FileNotFoundException, ReactorException {
-        restConf = RestconfImpl.getInstance();
+        restConf = RestconfImpl.newInstance(mock(BrokerFacade.class), controllerContext);
         final SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang");
         controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
-        restConf.setControllerContext(controllerContext);
     }
 
     @Override
@@ -55,7 +55,6 @@ public class CodecsExceptionsCatchingTest extends JerseyTest {
         resourceConfig = resourceConfig.registerInstances(restConf, new NormalizedNodeJsonBodyWriter(),
             new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
             new JsonNormalizedNodeBodyReader(controllerContext));
-        resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
         return resourceConfig;
     }
 
index 8f97a1e7565be80991e2b829dbbe09f7d27b368d..664a00cbb0675f556f4ac82316ccaec8366d370a 100644 (file)
@@ -73,12 +73,13 @@ public class InvokeRpcMethodTest {
     private static UriInfo uriInfo;
     private static SchemaContext schemaContext;
 
-    private final RestconfImpl restconfImpl = RestconfImpl.getInstance();
+    private final RestconfImpl restconfImpl;
     private final ControllerContext controllerContext;
+    private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
 
     public InvokeRpcMethodTest() {
         controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
     }
 
     @BeforeClass
@@ -109,10 +110,6 @@ public class InvokeRpcMethodTest {
             assertTrue("Uri wasn't created sucessfuly", false);
         }
 
-        final BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
-
-        restconfImpl.setBroker(mockedBrokerFacade);
-
         final NormalizedNodeContext payload = prepareDomPayload();
 
         final NormalizedNodeContext rpcResponse =
@@ -164,15 +161,11 @@ public class InvokeRpcMethodTest {
         final DOMRpcException exception = new DOMRpcImplementationNotAvailableException("testExeption");
         final CheckedFuture<DOMRpcResult, DOMRpcException> future = Futures.immediateFailedCheckedFuture(exception);
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
-
         final QName qname = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
         final SchemaPath type = SchemaPath.create(true, qname);
 
         when(brokerFacade.invokeRpc(eq(type), any(NormalizedNode.class))).thenReturn(future);
 
-        this.restconfImpl.setBroker(brokerFacade);
-
         try {
             this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
             fail("Expected an exception to be thrown.");
@@ -218,11 +211,8 @@ public class InvokeRpcMethodTest {
         final SchemaPath path = SchemaPath.create(true,
                 QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast"));
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.invokeRpc(eq(path), any(NormalizedNode.class))).thenReturn(future);
 
-        this.restconfImpl.setBroker(brokerFacade);
-
         try {
             this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
             fail("Expected an exception to be thrown.");
@@ -243,11 +233,8 @@ public class InvokeRpcMethodTest {
         final QName qname = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
         final SchemaPath path = SchemaPath.create(true, qname);
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.invokeRpc(eq(path), any(NormalizedNode.class))).thenReturn(future);
 
-        this.restconfImpl.setBroker(brokerFacade);
-
         final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
         assertNotNull(output);
         assertEquals(null, output.getData());
@@ -311,9 +298,7 @@ public class InvokeRpcMethodTest {
                 new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcInputSchemaNode,
                 null, schemaContext), containerBuilder.build());
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.invokeRpc(eq(path), any(NormalizedNode.class))).thenReturn(future);
-        this.restconfImpl.setBroker(brokerFacade);
 
         final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:make-toast", payload, uriInfo);
         assertNotNull(output);
@@ -367,11 +352,8 @@ public class InvokeRpcMethodTest {
         final DOMRpcResult result = new DefaultDOMRpcResult(container);
         final CheckedFuture<DOMRpcResult, DOMRpcException> future = Futures.immediateCheckedFuture(result);
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.invokeRpc(eq(rpcDef.getPath()), any(NormalizedNode.class))).thenReturn(future);
 
-        this.restconfImpl.setBroker(brokerFacade);
-
         final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:testOutput", "", uriInfo);
         assertNotNull(output);
         assertNotNull(output.getData());
index 390a87f719fa2f2b0dcd02216b6f75e83f28b2ef..5ac807007203169e260a001c237bda98204e1357 100644 (file)
@@ -123,9 +123,8 @@ public class JSONRestconfServiceImplTest {
                 TestRestconfUtils.newControllerContext(schemaContext, mockMountPoint);
         doReturn(mountPointSchemaContext).when(mockMountPoint).getSchemaContext();
 
-        service = new JSONRestconfServiceImpl(controllerContext);
-        RestconfImpl.getInstance().setBroker(brokerFacade);
-        RestconfImpl.getInstance().setControllerContext(controllerContext);
+        service = new JSONRestconfServiceImpl(controllerContext,
+                RestconfImpl.newInstance(brokerFacade, controllerContext));
     }
 
     private static String loadData(final String path) throws IOException {
index 72da87bacfde684a4bdb8c2fa5f981d7fae9efe3..ac5ffbcc82ded28f7bf07f71a4cdede718e4185e 100644 (file)
@@ -66,9 +66,7 @@ public class RestDeleteOperationTest extends JerseyTest {
         controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
         controllerContext.setSchemas(schemaContext);
         brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
 
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),
index ebe05da1b141c7e5c5bf10fe5bf325d143f159bf..d8b7c52962fcafd0f574f98041c6f65eb90c3256 100644 (file)
@@ -120,9 +120,7 @@ public class RestGetOperationTest extends JerseyTest {
         mountInstance = mock(DOMMountPoint.class);
         controllerContext = TestRestconfUtils.newControllerContext(schemaContextYangsIetf, mountInstance);
         brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
 
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),
index 0f5ef01fc9a85fd2f24774bfeacf9ed23024885c..d9c9f55299fa7c8b7cd4e8da5bbaba9b4ab2f9f3 100644 (file)
@@ -83,9 +83,7 @@ public class RestPostOperationTest extends JerseyTest {
         mountInstance = mock(DOMMountPoint.class);
         controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
         brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
 
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfImpl,
index 043f78b807ef931459cf82642c4a18db82d599e2..94a8284d82e980b8e6af0fd8970ec3a281888df6 100644 (file)
@@ -55,9 +55,8 @@ public class RestPutConfigTest {
 
     @Before
     public void init() {
-        this.restconfService = RestconfImpl.getInstance();
         this.controllerCx = TestRestconfUtils.newControllerContext(schemaContext);
-        this.restconfService.setControllerContext(this.controllerCx);
+        this.restconfService = RestconfImpl.newInstance(brokerFacade, controllerCx);
     }
 
     @Test
@@ -140,6 +139,5 @@ public class RestPutConfigTest {
                 .thenReturn(result);
         Mockito.when(result.getFutureOfPutData()).thenReturn(checkedFuture);
         Mockito.when(result.getStatus()).thenReturn(Status.OK);
-        this.restconfService.setBroker(this.brokerFacade);
     }
 }
index 981c9d29f5b030f5d546bfa7455fc0ebaa835b96..45d3920c6bd5ccce9ac28e404a80a301ca6a4578 100644 (file)
@@ -96,9 +96,7 @@ public class RestPutOperationTest extends JerseyTest {
         final ControllerContext controllerContext =
                 TestRestconfUtils.newControllerContext(schemaContextYangsIetf, mountInstance);
         brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
 
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfImpl,
index 54742ce0d866fb0ac3a7371561d317177d531504..8447150262579081ff9fc49de3a65e1066f79677 100644 (file)
@@ -58,6 +58,7 @@ public class RestconfImplNotificationSubscribingTest {
     private UriInfo uriInfo;
 
     private ControllerContext controllerContext;
+    private RestconfImpl restconfImpl;
 
     @BeforeClass
     public static void init() throws FileNotFoundException {
@@ -68,10 +69,8 @@ public class RestconfImplNotificationSubscribingTest {
     public void setup() throws Exception {
         MockitoAnnotations.initMocks(this);
 
-        RestconfImpl.getInstance().setBroker(this.broker);
-
         controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
-        RestconfImpl.getInstance().setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(broker, controllerContext);
 
         final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class);
         final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-12-14", "localName"));
@@ -240,7 +239,7 @@ public class RestconfImplNotificationSubscribingTest {
             set.add(entry);
         }
         Mockito.when(map.entrySet()).thenReturn(set);
-        RestconfImpl.getInstance().subscribeToStream(this.identifier, this.uriInfo);
+        restconfImpl.subscribeToStream(this.identifier, this.uriInfo);
     }
 
 }
index 26dc6587420325bfced3f3af1551e6cb8803118c..6067e419d7c09b4d9816911bf5c0c0441fb24317 100644 (file)
@@ -35,7 +35,6 @@ import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -76,8 +75,9 @@ public class RestconfImplTest {
 
     private static SchemaContext schemaContext;
 
-    private RestconfImpl restconfImpl;
+    private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
     private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+    private final RestconfImpl restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
 
     @BeforeClass
     public static void init() throws FileNotFoundException, ReactorException {
@@ -86,12 +86,6 @@ public class RestconfImplTest {
         assertNotNull(allModules);
     }
 
-    @Before
-    public void initMethod() {
-        this.restconfImpl = RestconfImpl.getInstance();
-        this.restconfImpl.setControllerContext(controllerContext);
-    }
-
     @Test
     public void binaryKeyTest() {
         final List<Byte> al = new ArrayList<>();
@@ -135,7 +129,6 @@ public class RestconfImplTest {
     public void testExample() throws FileNotFoundException, ParseException {
         @SuppressWarnings("rawtypes")
         final NormalizedNode normalizedNodeData = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData();
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(normalizedNodeData);
         assertEquals(normalizedNodeData,
                 brokerFacade.readOperationalData(null));
@@ -227,9 +220,6 @@ public class RestconfImplTest {
         when(map.entrySet()).thenReturn(set);
         when(uriInfo.getQueryParameters()).thenReturn(map);
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
-        this.restconfImpl.setBroker(brokerFacade);
-
         // subscribe to stream and verify response
         final NormalizedNodeContext response = this.restconfImpl.subscribeToStream(identifier, uriInfo);
 
index f7fbd80bdca415ae8b73891817e478576756dcde..f15d1dd996bee5aa0dbc019de53648948e0a0e09 100644 (file)
@@ -64,12 +64,10 @@ public class URIParametersParsing {
 
     @Before
     public void init() throws FileNotFoundException, ReactorException {
-        this.restconf = RestconfImpl.getInstance();
         this.mockedBrokerFacade = mock(BrokerFacade.class);
         this.controllerContext = TestRestconfUtils.newControllerContext(
                 TestUtils.loadSchemaContext("/datastore-and-scope-specification"));
-        this.restconf.setControllerContext(this.controllerContext);
-        this.restconf.setBroker(this.mockedBrokerFacade);
+        this.restconf = RestconfImpl.newInstance(mockedBrokerFacade, controllerContext);
     }
 
     @Test
index 164a241565bf5c78144c863c4d219e3b0bfb658f..74350d37e5bb4cc72558fb14cd2148460dfc4fdb 100644 (file)
@@ -22,9 +22,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
-import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -150,11 +148,6 @@ public class URITest {
     }
 
     public void initMountService(final boolean withSchema) throws FileNotFoundException, ReactorException {
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
-        final RestconfImpl restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
-
         if (withSchema) {
             when(mountInstance.getSchemaContext()).thenReturn(mountSchemaContext);
         } else {
index 6400c3225892b57e194ca70f91c0963856ad8994..951bb92c46320c8224a09e6e1edee7e4ceca17e7 100644 (file)
@@ -62,9 +62,7 @@ public class RestStreamTest extends JerseyTest {
 
         final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContextYangsIetf);
         brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
 
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),