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:
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.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 {
import org.opendaylight.netconf.sal.restconf.impl.StatisticsRestconfServiceWrapper;
public class RestconfApplication extends Application {
final Set<Object> singletons = new HashSet<>();
final ControllerContext controllerContext = ControllerContext.getInstance();
final BrokerFacade brokerFacade = BrokerFacade.getInstance();
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);
final SchemaRetrievalServiceImpl schemaRetrieval = new SchemaRetrievalServiceImpl(controllerContext);
- restconfImpl.setBroker(brokerFacade);
- restconfImpl.setControllerContext(controllerContext);
singletons.add(controllerContext);
singletons.add(brokerFacade);
singletons.add(schemaRetrieval);
singletons.add(controllerContext);
singletons.add(brokerFacade);
singletons.add(schemaRetrieval);
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
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;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.rest.impl.JsonToPatchBodyReader;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];
private final ControllerContext controllerContext;
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.controllerContext = controllerContext;
+ this.restconfService = restconfService;
}
@SuppressWarnings("checkstyle:IllegalCatch")
}
@SuppressWarnings("checkstyle:IllegalCatch")
LOG.debug("Parsed NormalizedNode: {}", context.getData());
try {
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");
}
} catch (final Exception e) {
propagateExceptionAs(uriPath, e, "PUT");
}
LOG.debug("Parsed NormalizedNode: {}", context.getData());
try {
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");
}
} catch (final Exception e) {
propagateExceptionAs(uriPath, e, "POST");
}
LOG.debug("delete: uriPath: {}", uriPath);
try {
LOG.debug("delete: uriPath: {}", uriPath);
try {
- RestconfImpl.getInstance().deleteConfigurationData(uriPath);
+ restconfService.deleteConfigurationData(uriPath);
} catch (final Exception e) {
propagateExceptionAs(uriPath, e, "DELETE");
}
} catch (final Exception e) {
propagateExceptionAs(uriPath, e, "DELETE");
}
NormalizedNodeContext readData;
final SimpleUriInfo uriInfo = new SimpleUriInfo(uriPath);
if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
NormalizedNodeContext readData;
final SimpleUriInfo uriInfo = new SimpleUriInfo(uriPath);
if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
- readData = RestconfImpl.getInstance().readConfigurationData(uriPath, uriInfo);
+ readData = restconfService.readConfigurationData(uriPath, uriInfo);
- readData = RestconfImpl.getInstance().readOperationalData(uriPath, uriInfo);
+ readData = restconfService.readOperationalData(uriPath, uriInfo);
}
final Optional<String> result = Optional.of(toJson(readData));
}
final Optional<String> result = Optional.of(toJson(readData));
.getInstanceIdentifier());
LOG.debug("Parsed NormalizedNode: {}", inputContext.getData());
.getInstanceIdentifier());
LOG.debug("Parsed NormalizedNode: {}", inputContext.getData());
- outputContext = RestconfImpl.getInstance().invokeRpc(uriPath, inputContext, null);
+ outputContext = restconfService.invokeRpc(uriPath, inputContext, null);
- outputContext = RestconfImpl.getInstance().invokeRpc(uriPath, "", null);
+ outputContext = restconfService.invokeRpc(uriPath, "", null);
}
if (outputContext.getData() != null) {
}
if (outputContext.getData() != null) {
LOG.debug("Parsed NormalizedNode: {}", context.getData());
try {
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) {
.patchConfigurationData(context, new SimpleUriInfo(uriPath));
output = toJson(patchStatusContext);
} catch (final Exception e) {
import org.slf4j.LoggerFactory;
public final class RestconfImpl implements RestconfService {
import org.slf4j.LoggerFactory;
public final class RestconfImpl implements RestconfService {
-
- private static final RestconfImpl INSTANCE = new RestconfImpl();
-
/**
* Notifications are served on port 8181.
*/
/**
* Notifications are served on port 8181.
*/
.appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true)
.appendOffset("+HH:MM", "Z").toFormatter();
.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) {
- }
-
- public void setControllerContext(final ControllerContext controllerContext) {
this.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);
implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
private final IpAddress websocketAddress;
private final PortNumber websocketPort;
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;
private Thread webSocketServerThread;
- public RestconfProviderImpl(IpAddress websocketAddress, PortNumber websocketPort) {
+ public RestconfProviderImpl(StatisticsRestconfServiceWrapper stats, IpAddress websocketAddress,
+ PortNumber websocketPort) {
super("Draft02ProviderStatistics", "restconf-connector", null);
super("Draft02ProviderStatistics", "restconf-connector", null);
+ this.stats = Preconditions.checkNotNull(stats);
this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
this.websocketPort = Preconditions.checkNotNull(websocketPort);
}
this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
this.websocketPort = Preconditions.checkNotNull(websocketPort);
}
AtomicLong failurePut = new AtomicLong();
AtomicLong failureDelete = new AtomicLong();
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;
}
private StatisticsRestconfServiceWrapper(final RestconfService delegate) {
this.delegate = delegate;
}
public static StatisticsRestconfServiceWrapper getInstance() {
return INSTANCE;
}
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();
@Override
public Object getRoot() {
return this.delegate.getRoot();
<argument ref="controllerContext"/>
</bean>
<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">
<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>
<argument ref="webSocketAddress"/>
<argument ref="webSocketPort"/>
</bean>
class="org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl"
destroy-method="close">
<argument ref="controllerContext"/>
class="org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl"
destroy-method="close">
<argument ref="controllerContext"/>
+ <argument ref="restconfImpl"/>
</bean>
<service ref="jsonRestconfServiceDraft02" odl:type="default"
</bean>
<service ref="jsonRestconfServiceDraft02" odl:type="default"
public void initialize() throws FileNotFoundException {
final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContextTestModule);
brokerFacade = mock(BrokerFacade.class);
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()))
final PutResult result = mock(PutResult.class);
when(brokerFacade.commitConfigurationDataPut(any(SchemaContext.class), any(YangInstanceIdentifier.class),
any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString()))
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
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.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;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
doReturn(mountPointContext).when(mountInstance).getSchemaContext();
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);
package org.opendaylight.controller.sal.restconf.impl.test;
import static org.junit.Assert.assertTrue;
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;
import java.io.FileNotFoundException;
import javax.ws.rs.client.Entity;
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.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.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;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@Before
public void init() throws FileNotFoundException, ReactorException {
@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);
final SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang");
controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
- restConf.setControllerContext(controllerContext);
resourceConfig = resourceConfig.registerInstances(restConf, new NormalizedNodeJsonBodyWriter(),
new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
new JsonNormalizedNodeBodyReader(controllerContext));
resourceConfig = resourceConfig.registerInstances(restConf, new NormalizedNodeJsonBodyWriter(),
new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
new JsonNormalizedNodeBodyReader(controllerContext));
- resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
private static UriInfo uriInfo;
private static SchemaContext schemaContext;
private static UriInfo uriInfo;
private static SchemaContext schemaContext;
- private final RestconfImpl restconfImpl = RestconfImpl.getInstance();
+ private final RestconfImpl restconfImpl;
private final ControllerContext controllerContext;
private final ControllerContext controllerContext;
+ private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
public InvokeRpcMethodTest() {
controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
public InvokeRpcMethodTest() {
controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
- restconfImpl.setControllerContext(controllerContext);
+ restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
assertTrue("Uri wasn't created sucessfuly", false);
}
assertTrue("Uri wasn't created sucessfuly", false);
}
- final BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
-
- restconfImpl.setBroker(mockedBrokerFacade);
-
final NormalizedNodeContext payload = prepareDomPayload();
final NormalizedNodeContext rpcResponse =
final NormalizedNodeContext payload = prepareDomPayload();
final NormalizedNodeContext rpcResponse =
final DOMRpcException exception = new DOMRpcImplementationNotAvailableException("testExeption");
final CheckedFuture<DOMRpcResult, DOMRpcException> future = Futures.immediateFailedCheckedFuture(exception);
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);
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.");
try {
this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
fail("Expected an exception to be thrown.");
final SchemaPath path = SchemaPath.create(true,
QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast"));
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);
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.");
try {
this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
fail("Expected an exception to be thrown.");
final QName qname = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
final SchemaPath path = SchemaPath.create(true, qname);
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);
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());
final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
assertNotNull(output);
assertEquals(null, output.getData());
new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcInputSchemaNode,
null, schemaContext), containerBuilder.build());
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);
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);
final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:make-toast", payload, uriInfo);
assertNotNull(output);
final DOMRpcResult result = new DefaultDOMRpcResult(container);
final CheckedFuture<DOMRpcResult, DOMRpcException> future = Futures.immediateCheckedFuture(result);
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);
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());
final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:testOutput", "", uriInfo);
assertNotNull(output);
assertNotNull(output.getData());
TestRestconfUtils.newControllerContext(schemaContext, mockMountPoint);
doReturn(mountPointSchemaContext).when(mockMountPoint).getSchemaContext();
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 {
}
private static String loadData(final String path) throws IOException {
controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
controllerContext.setSchemas(schemaContext);
brokerFacade = mock(BrokerFacade.class);
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(),
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),
mountInstance = mock(DOMMountPoint.class);
controllerContext = TestRestconfUtils.newControllerContext(schemaContextYangsIetf, mountInstance);
brokerFacade = mock(BrokerFacade.class);
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(),
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),
mountInstance = mock(DOMMountPoint.class);
controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
brokerFacade = mock(BrokerFacade.class);
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,
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig = resourceConfig.registerInstances(restconfImpl,
@Before
public void init() {
@Before
public void init() {
- this.restconfService = RestconfImpl.getInstance();
this.controllerCx = TestRestconfUtils.newControllerContext(schemaContext);
this.controllerCx = TestRestconfUtils.newControllerContext(schemaContext);
- this.restconfService.setControllerContext(this.controllerCx);
+ this.restconfService = RestconfImpl.newInstance(brokerFacade, controllerCx);
.thenReturn(result);
Mockito.when(result.getFutureOfPutData()).thenReturn(checkedFuture);
Mockito.when(result.getStatus()).thenReturn(Status.OK);
.thenReturn(result);
Mockito.when(result.getFutureOfPutData()).thenReturn(checkedFuture);
Mockito.when(result.getStatus()).thenReturn(Status.OK);
- this.restconfService.setBroker(this.brokerFacade);
final ControllerContext controllerContext =
TestRestconfUtils.newControllerContext(schemaContextYangsIetf, mountInstance);
brokerFacade = mock(BrokerFacade.class);
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,
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig = resourceConfig.registerInstances(restconfImpl,
private UriInfo uriInfo;
private ControllerContext controllerContext;
private UriInfo uriInfo;
private ControllerContext controllerContext;
+ private RestconfImpl restconfImpl;
@BeforeClass
public static void init() throws FileNotFoundException {
@BeforeClass
public static void init() throws FileNotFoundException {
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
- RestconfImpl.getInstance().setBroker(this.broker);
-
controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
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"));
final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class);
final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-12-14", "localName"));
set.add(entry);
}
Mockito.when(map.entrySet()).thenReturn(set);
set.add(entry);
}
Mockito.when(map.entrySet()).thenReturn(set);
- RestconfImpl.getInstance().subscribeToStream(this.identifier, this.uriInfo);
+ restconfImpl.subscribeToStream(this.identifier, this.uriInfo);
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
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;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
private static SchemaContext schemaContext;
private static SchemaContext schemaContext;
- private RestconfImpl restconfImpl;
+ private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+ private final RestconfImpl restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
@BeforeClass
public static void init() throws FileNotFoundException, ReactorException {
@BeforeClass
public static void init() throws FileNotFoundException, ReactorException {
assertNotNull(allModules);
}
assertNotNull(allModules);
}
- @Before
- public void initMethod() {
- this.restconfImpl = RestconfImpl.getInstance();
- this.restconfImpl.setControllerContext(controllerContext);
- }
-
@Test
public void binaryKeyTest() {
final List<Byte> al = new ArrayList<>();
@Test
public void binaryKeyTest() {
final List<Byte> al = new ArrayList<>();
public void testExample() throws FileNotFoundException, ParseException {
@SuppressWarnings("rawtypes")
final NormalizedNode normalizedNodeData = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData();
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));
when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(normalizedNodeData);
assertEquals(normalizedNodeData,
brokerFacade.readOperationalData(null));
when(map.entrySet()).thenReturn(set);
when(uriInfo.getQueryParameters()).thenReturn(map);
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);
// subscribe to stream and verify response
final NormalizedNodeContext response = this.restconfImpl.subscribeToStream(identifier, uriInfo);
@Before
public void init() throws FileNotFoundException, ReactorException {
@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.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);
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.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.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;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
}
public void initMountService(final boolean withSchema) throws FileNotFoundException, ReactorException {
}
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 {
if (withSchema) {
when(mountInstance.getSchemaContext()).thenReturn(mountSchemaContext);
} else {
final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContextYangsIetf);
brokerFacade = mock(BrokerFacade.class);
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(),
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),