From: Tom Pantelis Date: Mon, 16 Apr 2018 21:40:31 +0000 (-0400) Subject: Remove static RestconfImpl X-Git-Tag: release/fluorine~91 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=26910f0052a4ac3022067f33ceccf4b056004691;p=netconf.git Remove static RestconfImpl 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 --- diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java index 882ac2e916..9dd5a59dda 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java @@ -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 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); diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java index 47c4f487c9..50b23594da 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java @@ -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 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) { diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java index aac9645c5a..e61e973795 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java @@ -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 diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java index 5870c5d5a7..19d34af070 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java @@ -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); } diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java index a6c2a8d7c4..e6f2839344 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java @@ -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(); diff --git a/restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml b/restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml index 4286306c21..aeb2b6f21b 100644 --- a/restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml +++ b/restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml @@ -68,8 +68,20 @@ + + + + + + + + + + @@ -79,6 +91,7 @@ class="org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl" destroy-method="close"> + 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 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()); diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/JSONRestconfServiceImplTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/JSONRestconfServiceImplTest.java index 390a87f719..5ac8070072 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/JSONRestconfServiceImplTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/JSONRestconfServiceImplTest.java @@ -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 { diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java index 72da87bacf..ac5ffbcc82 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java @@ -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(), diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java index ebe05da1b1..d8b7c52962 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java @@ -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(), diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java index 0f5ef01fc9..d9c9f55299 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java @@ -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, diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutConfigTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutConfigTest.java index 043f78b807..94a8284d82 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutConfigTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutConfigTest.java @@ -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); } } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java index 981c9d29f5..45d3920c6b 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java @@ -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, diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java index 54742ce0d8..8447150262 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java @@ -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); } } diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java index 26dc658742..6067e419d7 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java @@ -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 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); diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java index f7fbd80bdc..f15d1dd996 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java @@ -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 diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java index 164a241565..74350d37e5 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java @@ -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 { diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/test/RestStreamTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/test/RestStreamTest.java index 6400c32258..951bb92c46 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/test/RestStreamTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/test/RestStreamTest.java @@ -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(),