X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-bierman02%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FBrokerFacadeTest.java;h=ae3bf69939a587aaa899f114a04e1d5a27304e12;hb=5ff13db21d041924e1d9208fb0220f173bb8cd45;hp=86a1a11682573ea199e85acc05915a0305516c5e;hpb=824baf9fe14e31465c58f3842c4cb0aa88b34757;p=netconf.git diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java index 86a1a11682..ae3bf69939 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java @@ -14,8 +14,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; @@ -28,6 +28,7 @@ import com.google.common.base.Optional; import com.google.common.collect.Lists; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; +import java.util.HashMap; import java.util.concurrent.Future; import org.junit.Before; import org.junit.Test; @@ -35,14 +36,14 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; +import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; @@ -50,6 +51,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcException; import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +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.PutResult; @@ -63,8 +65,7 @@ import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; import org.opendaylight.restconf.common.patch.PatchContext; import org.opendaylight.restconf.common.patch.PatchStatusContext; -import org.opendaylight.restconf.handlers.SchemaContextHandler; -import org.opendaylight.restconf.handlers.TransactionChainHandler; +import org.opendaylight.restconf.common.util.DataChangeScope; import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.common.QName; @@ -99,25 +100,30 @@ public class BrokerFacadeTest { @Mock private DOMDataReadWriteTransaction rwTransaction; - private final BrokerFacade brokerFacade = BrokerFacade.getInstance(); + private BrokerFacade brokerFacade; private final NormalizedNode dummyNode = createDummyNode("test:module", "2014-01-09", "interfaces"); private final CheckedFuture>, ReadFailedException> dummyNodeInFuture = wrapDummyNode(this.dummyNode); private final QName qname = TestUtils.buildQName("interfaces","test:module", "2014-01-09"); private final SchemaPath type = SchemaPath.create(true, this.qname); private final YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(this.qname).build(); + private ControllerContext controllerContext; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - this.brokerFacade.setDomDataBroker(this.domDataBroker); - this.brokerFacade.setDomNotificationService(this.domNotification); - this.brokerFacade.setRpcService(this.mockRpcService); + + controllerContext = TestRestconfUtils.newControllerContext( + TestUtils.loadSchemaContext("/full-versions/test-module", "/modules")); + + brokerFacade = BrokerFacade.newInstance(mockRpcService, domDataBroker, domNotification, controllerContext); + when(this.domDataBroker.newReadOnlyTransaction()).thenReturn(this.readTransaction); when(this.domDataBroker.newWriteOnlyTransaction()).thenReturn(this.writeTransaction); when(this.domDataBroker.newReadWriteTransaction()).thenReturn(this.rwTransaction); - - ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext("/full-versions/test-module")); + HashMap extensions = new HashMap(); + extensions.put(DOMDataTreeChangeService.class, Mockito.mock(DOMDataTreeChangeService.class)); + when(this.domDataBroker.getSupportedExtensions()).thenReturn(extensions); } private static CheckedFuture>, ReadFailedException> wrapDummyNode( @@ -158,13 +164,6 @@ public class BrokerFacadeTest { assertSame("readOperationalData", this.dummyNode, actualNode); } - @Test(expected = RestconfDocumentedException.class) - public void testReadOperationalDataWithNoDataBroker() { - this.brokerFacade.setDomDataBroker(null); - - this.brokerFacade.readOperationalData(this.instanceID); - } - @Test public void test503() throws Exception { final RpcError error = RpcResultBuilder.newError( @@ -198,12 +197,6 @@ public class BrokerFacadeTest { assertSame("invokeRpc", expResult, actualResult); } - @Test(expected = RestconfDocumentedException.class) - public void testInvokeRpcWithNoConsumerSession() { - brokerFacade.setDomDataBroker(null); - this.brokerFacade.invokeRpc(this.type, this.dummyNode); - } - @Test public void testCommitConfigurationDataPut() throws Exception { @SuppressWarnings("unchecked") @@ -326,25 +319,26 @@ public class BrokerFacadeTest { @Test public void testRegisterToListenDataChanges() { final ListenerAdapter listener = Notificator.createListener(this.instanceID, "stream", - NotificationOutputType.XML); + NotificationOutputType.XML, controllerContext); @SuppressWarnings("unchecked") - final ListenerRegistration mockRegistration = mock(ListenerRegistration.class); + final ListenerRegistration mockRegistration = mock(ListenerRegistration.class); - when(this.domDataBroker.registerDataChangeListener(any(LogicalDatastoreType.class), eq(this.instanceID), - eq(listener), eq(DataChangeScope.BASE))).thenReturn(mockRegistration); + DOMDataTreeChangeService changeService = (DOMDataTreeChangeService) + this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class); + DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, this.instanceID); + when(changeService.registerDataTreeChangeListener(eq(loc), eq(listener))).thenReturn(mockRegistration); this.brokerFacade.registerToListenDataChanges( LogicalDatastoreType.CONFIGURATION, DataChangeScope.BASE, listener); - verify(this.domDataBroker).registerDataChangeListener( - LogicalDatastoreType.CONFIGURATION, this.instanceID, listener, DataChangeScope.BASE); + verify(changeService).registerDataTreeChangeListener(loc, listener); assertEquals("isListening", true, listener.isListening()); this.brokerFacade.registerToListenDataChanges( LogicalDatastoreType.CONFIGURATION, DataChangeScope.BASE, listener); - verifyNoMoreInteractions(this.domDataBroker); + verifyNoMoreInteractions(changeService); } /** @@ -356,7 +350,7 @@ public class BrokerFacadeTest { final String identifier = "create-notification-stream/toaster:toastDone"; final SchemaPath path = SchemaPath.create(true, QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "toastDone")); - Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML"); + Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML", controllerContext); final NotificationListenerAdapter listener = Notificator.getNotificationListenerFor(identifier).get(0); // mock registration @@ -380,11 +374,6 @@ public class BrokerFacadeTest { final CheckedFuture checked = Futures.immediateCheckedFuture(null); when(wTx.submit()).thenReturn(checked); when(transactionChain.newWriteOnlyTransaction()).thenReturn(wTx); - final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(transactionChain); - final SchemaContextHandler schemaHandler = Mockito.mock(SchemaContextHandler.class); - final SchemaContext schCtx = TestUtils.loadSchemaContext("/modules"); - when(schemaHandler.get()).thenReturn(schCtx); - listener.setCloseVars(transactionChainHandler, schemaHandler); // close and remove test notification listener listener.close(); Notificator.removeListenerIfNoSubscriberExists(listener);