package org.opendaylight.restconf.nb.rfc8040;
import com.google.common.base.Preconditions;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
- @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
- private static volatile DOMMountPointServiceHandler mountPointServiceHandler;
-
private final DOMRpcService rpcService;
private final DOMNotificationService notificationService;
- private final DOMMountPointService mountPointService;
private final DOMSchemaService domSchemaService;
private final TransactionChainHandler transactionChainHandler;
private final DOMDataBroker dataBroker;
private final SchemaContextHandler schemaCtxHandler;
+ private final DOMMountPointServiceHandler mountPointServiceHandler;
private final T wrapperServices;
public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
final DOMRpcService rpcService, final DOMNotificationService notificationService,
- final DOMMountPointService mountPointService, final TransactionChainHandler transactionChainHandler,
- final SchemaContextHandler schemaCtxHandler, final T wrapperServices) {
+ final TransactionChainHandler transactionChainHandler,
+ final SchemaContextHandler schemaCtxHandler, final DOMMountPointServiceHandler mountPointServiceHandler,
+ final T wrapperServices) {
this.wrapperServices = wrapperServices;
this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
this.rpcService = Preconditions.checkNotNull(rpcService);
this.notificationService = Preconditions.checkNotNull(notificationService);
- this.mountPointService = Preconditions.checkNotNull(mountPointService);
this.transactionChainHandler = Preconditions.checkNotNull(transactionChainHandler);
this.dataBroker = Preconditions.checkNotNull(domDataBroker);
this.schemaCtxHandler = Preconditions.checkNotNull(schemaCtxHandler);
+ this.mountPointServiceHandler = Preconditions.checkNotNull(mountPointServiceHandler);
}
public synchronized void start() {
- mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
-
final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
new NotificationServiceHandler(notificationService);
if (wrapperServices != null) {
- wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
+ wrapperServices.setHandlers(this.schemaCtxHandler, mountPointServiceHandler,
transactionChainHandler, brokerHandler, rpcServiceHandler,
notificationServiceHandler, domSchemaService);
}
}
- public DOMMountPointServiceHandler getMountPointServiceHandler() {
- return mountPointServiceHandler;
- }
-
- /**
- * Get current {@link DOMMountPointService} from {@link DOMMountPointServiceHandler}.
- * @return {@link DOMMountPointService}
- */
- public static DOMMountPointService getMountPointService() {
- return mountPointServiceHandler.get();
- }
-
@Override
public void close() {
- mountPointServiceHandler = null;
}
}
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeJsonBodyWriter;
public class RestconfApplication extends Application {
private final SchemaContextHandler schemaContextHandler = SchemaContextHandler.instance();
+ private final DOMMountPointServiceHandler mountPointServiceHandler = DOMMountPointServiceHandler.instance();
@Override
public Set<Class<?>> getClasses() {
public Set<Object> getSingletons() {
final Set<Object> singletons = new HashSet<>();
singletons.add(ServicesWrapperImpl.getInstance());
- singletons.add(new JsonNormalizedNodeBodyReader(schemaContextHandler));
- singletons.add(new JsonToPatchBodyReader(schemaContextHandler));
- singletons.add(new XmlNormalizedNodeBodyReader(schemaContextHandler));
- singletons.add(new XmlToPatchBodyReader(schemaContextHandler));
+ singletons.add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
+ singletons.add(new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
+ singletons.add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
+ singletons.add(new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
return singletons;
}
}
* Implementation of {@link DOMMountPointServiceHandler}.
*
*/
-public class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
- private final DOMMountPointService domMountPointService;
+public final class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
+ private static final DOMMountPointServiceHandler INSTANCE = new DOMMountPointServiceHandler();
+
+ private DOMMountPointService domMountPointService;
/**
* Prepare mount point service for Restconf services.
* @param domMountPointService
* mount point service
*/
- public DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
+ private DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
this.domMountPointService = Objects.requireNonNull(domMountPointService);
}
+ @Deprecated
+ private DOMMountPointServiceHandler() {
+ }
+
+ @Deprecated
+ public static DOMMountPointServiceHandler instance() {
+ return INSTANCE;
+ }
+
+ public static DOMMountPointServiceHandler newInstance(DOMMountPointService domMountPointService) {
+ INSTANCE.domMountPointService = domMountPointService;
+ return INSTANCE;
+ }
+
@Override
public DOMMountPointService get() {
return this.domMountPointService;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractNormalizedNodeBodyReader;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
public class JsonNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader {
private static final Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
- public JsonNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler) {
- super(schemaContextHandler);
+ public JsonNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
}
@SuppressWarnings("checkstyle:IllegalCatch")
import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractNormalizedNodeBodyReader;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
public class XmlNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader {
private static final Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
- public XmlNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler) {
- super(schemaContextHandler);
+ public XmlNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
}
@SuppressWarnings("checkstyle:IllegalCatch")
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.patch.PatchContext;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
* @author Robert Varga
*/
abstract class AbstractToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider<PatchContext> {
- protected AbstractToPatchBodyReader(SchemaContextHandler schemaContextHandler) {
- super(schemaContextHandler);
+ protected AbstractToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
}
@Override
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchEditOperation;
import org.opendaylight.restconf.common.patch.PatchEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
import org.opendaylight.restconf.nb.rfc8040.codecs.StringModuleInstanceIdentifierCodec;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
private static final Logger LOG = LoggerFactory.getLogger(JsonToPatchBodyReader.class);
- public JsonToPatchBodyReader(SchemaContextHandler schemaContextHandler) {
- super(schemaContextHandler);
+ public JsonToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
}
@SuppressWarnings("checkstyle:IllegalCatch")
try {
return readFrom(
ParserIdentifier.toInstanceIdentifier(uriPath, getSchemaContext(),
- Optional.of(RestConnectorProvider.getMountPointService())), entityStream);
+ Optional.fromNullable(getMountPointService())), entityStream);
} catch (final Exception e) {
propagateExceptionAs(e);
return null; // no-op
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
import org.opendaylight.restconf.nb.rfc8040.codecs.StringModuleInstanceIdentifierCodec;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
private static final Logger LOG = LoggerFactory.getLogger(XmlToPatchBodyReader.class);
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
- public XmlToPatchBodyReader(SchemaContextHandler schemaContextHandler) {
- super(schemaContextHandler);
+ public XmlToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
}
@SuppressWarnings("checkstyle:IllegalCatch")
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.MessageBodyReader;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
private Request request;
private final SchemaContextHandler schemaContextHandler;
+ private final DOMMountPointServiceHandler mountPointServiceHandler;
- protected AbstractIdentifierAwareJaxRsProvider(SchemaContextHandler schemaContextHandler) {
+ protected AbstractIdentifierAwareJaxRsProvider(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
this.schemaContextHandler = schemaContextHandler;
+ this.mountPointServiceHandler = mountPointServiceHandler;
}
@Override
private InstanceIdentifierContext<?> getInstanceIdentifierContext() {
return ParserIdentifier.toInstanceIdentifier(getIdentifier(), getSchemaContext(),
- Optional.of(RestConnectorProvider.getMountPointService()));
+ Optional.fromNullable(getMountPointService()));
}
protected UriInfo getUriInfo() {
return schemaContextHandler.get();
}
+ protected DOMMountPointService getMountPointService() {
+ return mountPointServiceHandler.get();
+ }
+
protected boolean isPost() {
return HttpMethod.POST.equals(this.request.getMethod());
}
import javax.ws.rs.core.UriInfo;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
/**
@Beta
public abstract class AbstractNormalizedNodeBodyReader
extends AbstractIdentifierAwareJaxRsProvider<NormalizedNodeContext> {
- protected AbstractNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler) {
- super(schemaContextHandler);
+ protected AbstractNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
}
public final void injectParams(final UriInfo uriInfo, final Request request) {
final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
- JsonToPatchBodyReader jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler);
+ JsonToPatchBodyReader jsonToPatchBodyReader =
+ new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
final PatchContext context = jsonToPatchBodyReader.readFrom(uriPath, entityStream);
LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
<argument ref="domSchemaService"/>
</bean>
+ <bean id="mountPointServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler"
+ factory-method="newInstance">
+ <argument ref="domMountPointService"/>
+ </bean>
+
<bean id="restconfProvider" class="org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider"
init-method="start" destroy-method="close">
<argument ref="domDataBroker"/>
<argument ref="domSchemaService"/>
<argument ref="domRpcService"/>
<argument ref="domNotificationService"/>
- <argument ref="domMountPointService"/>
<argument ref="transactionChainHandler"/>
<argument ref="schemaContextHandler"/>
+ <argument ref="mountPointServiceHandler"/>
<argument ref="wrapper"/>
</bean>
class="org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl"
destroy-method="close">
<argument ref="wrapper"/>
- <argument>
- <bean factory-ref="restconfProvider" factory-method="getMountPointServiceHandler" />
- </argument>
+ <argument ref="mountPointServiceHandler"/>
<argument ref="schemaContextHandler"/>
</bean>
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(mockDataBroker);
this.connectorProvider = new RestConnectorProvider<>(mockDataBroker, domSchemaService, mockRpcService,
- mockNotificationService, mockMountPointService, transactionChainHandler,
+ mockNotificationService, transactionChainHandler,
SchemaContextHandler.newInstance(transactionChainHandler, domSchemaService),
+ DOMMountPointServiceHandler.newInstance(mockMountPointService),
ServicesWrapperImpl.getInstance());
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.io.File;
import java.io.InputStream;
import java.net.URI;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
public XmlBodyReaderMountPointTest() throws Exception {
super(schemaContext);
- this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler);
+ this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-
- final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
- final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService);
- when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
- when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
}
@Test
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
public JsonPatchBodyReaderMountPointTest() throws Exception {
super(schemaContext);
- jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler);
+ jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-
- final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
- final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService);
- when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
- when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
}
@Test
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
public JsonPatchBodyReaderTest() throws Exception {
super(schemaContext);
- jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler);
+ jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
}
@Test
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
public XmlPatchBodyReaderMountPointTest() throws Exception {
super(schemaContext);
- xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler);
+ xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-
- final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
- final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService);
- when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
- when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
}
@Test
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
public XmlPatchBodyReaderTest() throws Exception {
super(schemaContext);
- xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler);
+ xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
}
@Test
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.test;
import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.lang.reflect.Field;
+import com.google.common.base.Optional;
import java.util.Collections;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.TestUtils;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public abstract class AbstractBodyReaderTest {
- protected static final DOMMountPointServiceHandler MOUNT_POINT_SERVICE_HANDLER =
- mock(DOMMountPointServiceHandler.class);
-
protected final MediaType mediaType;
protected final SchemaContextHandler schemaContextHandler;
+ protected final DOMMountPointServiceHandler mountPointServiceHandler;
protected AbstractBodyReaderTest(SchemaContext schemaContext) throws NoSuchFieldException, IllegalAccessException {
mediaType = getMediaType();
- final Field mountPointServiceHandlerField =
- RestConnectorProvider.class.getDeclaredField("mountPointServiceHandler");
- mountPointServiceHandlerField.setAccessible(true);
- mountPointServiceHandlerField.set(RestConnectorProvider.class, MOUNT_POINT_SERVICE_HANDLER);
-
schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
+
+ final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
+ final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+ doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
+ doReturn(schemaContext).when(mountPoint).getSchemaContext();
+
+ mountPointServiceHandler = DOMMountPointServiceHandler.newInstance(mountPointService);
}
protected abstract MediaType getMediaType();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import com.google.common.collect.Sets;
import java.io.File;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader;
public JsonBodyReaderTest() throws Exception {
super(schemaContext);
- this.jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler);
+ this.jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
}
@Test
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import com.google.common.collect.Sets;
import java.io.File;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
public XmlBodyReaderTest() throws Exception {
super(schemaContext);
- this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler);
+ this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
testFiles.addAll(TestRestconfUtils.loadFiles("/foo-xml-test/yang"));
schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
}
@Test
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.TestUtils;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockDOMDataBroker);
final DOMMountPointServiceHandler mountPointServiceHandler =
- new DOMMountPointServiceHandler(mockMountPointService);
+ DOMMountPointServiceHandler.newInstance(mockMountPointService);
final DOMNotificationService mockNotificationService = mock(DOMNotificationService.class);
ServicesWrapperImpl.getInstance().setHandlers(schemaContextHandler, mountPointServiceHandler,
service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler,
schemaContextHandler);
-
- new RestConnectorProvider<>(mockDOMDataBroker, domSchemaService, mockRpcService, mockNotificationService,
- mockMountPointService, txChainHandler, schemaContextHandler, null).start();
}
private static String loadData(final String path) throws IOException {
@Mock
private DOMDataWriteTransaction write;
@Mock
- private DOMMountPointServiceHandler mountPointServiceHandler;
- @Mock
private DOMMountPointService mountPointService;
@Mock
private DOMMountPoint mountPoint;
schemaContextHandler.onGlobalContextUpdated(this.contextRef.get());
this.dataService = new RestconfDataServiceImpl(schemaContextHandler, this.transactionChainHandler,
- this.mountPointServiceHandler, this.delegRestconfSubscrService);
- doReturn(this.mountPointService).when(this.mountPointServiceHandler).get();
+ DOMMountPointServiceHandler.newInstance(mountPointService), this.delegRestconfSubscrService);
doReturn(Optional.of(this.mountPoint)).when(this.mountPointService)
.getMountPoint(any(YangInstanceIdentifier.class));
doReturn(this.contextRef.get()).when(this.mountPoint).getSchemaContext();
this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"));
this.schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
- this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
+ this.domMountPointServiceHandler = DOMMountPointServiceHandler.newInstance(this.domMountPointService);
final QNameModule module1 = QNameModule.create(URI.create("module:1"));
final QNameModule module2 = QNameModule.create(URI.create("module:2"));
@Mock
private SchemaContextHandler mockContextHandler;
@Mock
- private DOMMountPointServiceHandler mockMountPointHandler;
- @Mock
private DOMYangTextSourceProvider sourceProvider;
// schema context with modules
this.mountPointService = new DOMMountPointServiceImpl();
((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPointWithNullSchemaContext);
- when(this.mockMountPointHandler.get()).thenReturn(this.mountPointService);
- this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler,
- sourceProvider);
+ this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler,
+ DOMMountPointServiceHandler.newInstance(mountPointService), sourceProvider);
}
/**