InstanceIdentifierContext does not take generics
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / BrokerFacadeTest.java
index dad0907a7ecf49467ebf39521f5341a34c41b0a7..e58a14f195e3c2585c1eaeb48a4dad1e1fc8e3ca 100644 (file)
@@ -111,9 +111,9 @@ public class BrokerFacadeTest {
 
     private BrokerFacade brokerFacade;
     private final NormalizedNode dummyNode = createDummyNode("test:module", "2014-01-09", "interfaces");
-    private final FluentFuture<Optional<NormalizedNode>> dummyNodeInFuture = wrapDummyNode(this.dummyNode);
+    private final FluentFuture<Optional<NormalizedNode>> dummyNodeInFuture = wrapDummyNode(dummyNode);
     private final QName qname = TestUtils.buildQName("interfaces","test:module", "2014-01-09");
-    private final YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(this.qname).build();
+    private final YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(qname).build();
     private ControllerContext controllerContext;
 
     @Before
@@ -123,9 +123,9 @@ public class BrokerFacadeTest {
 
         brokerFacade = BrokerFacade.newInstance(mockRpcService, domDataBroker, domNotification, controllerContext);
 
-        when(this.domDataBroker.newReadOnlyTransaction()).thenReturn(this.readTransaction);
-        when(this.domDataBroker.newReadWriteTransaction()).thenReturn(this.rwTransaction);
-        when(this.domDataBroker.getExtensions()).thenReturn(ImmutableClassToInstanceMap.of(
+        when(domDataBroker.newReadOnlyTransaction()).thenReturn(readTransaction);
+        when(domDataBroker.newReadWriteTransaction()).thenReturn(rwTransaction);
+        when(domDataBroker.getExtensions()).thenReturn(ImmutableClassToInstanceMap.of(
             DOMDataTreeChangeService.class, Mockito.mock(DOMDataTreeChangeService.class)));
     }
 
@@ -148,22 +148,22 @@ public class BrokerFacadeTest {
 
     @Test
     public void testReadConfigurationData() {
-        when(this.readTransaction.read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class))).thenReturn(
-                this.dummyNodeInFuture);
+        when(readTransaction.read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class))).thenReturn(
+                dummyNodeInFuture);
 
-        final NormalizedNode actualNode = this.brokerFacade.readConfigurationData(this.instanceID);
+        final NormalizedNode actualNode = brokerFacade.readConfigurationData(instanceID);
 
-        assertSame("readConfigurationData", this.dummyNode, actualNode);
+        assertSame("readConfigurationData", dummyNode, actualNode);
     }
 
     @Test
     public void testReadOperationalData() {
-        when(this.readTransaction.read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class))).thenReturn(
-                this.dummyNodeInFuture);
+        when(readTransaction.read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class))).thenReturn(
+                dummyNodeInFuture);
 
-        final NormalizedNode actualNode = this.brokerFacade.readOperationalData(this.instanceID);
+        final NormalizedNode actualNode = brokerFacade.readOperationalData(instanceID);
 
-        assertSame("readOperationalData", this.dummyNode, actualNode);
+        assertSame("readOperationalData", dummyNode, actualNode);
     }
 
     @Test
@@ -176,7 +176,7 @@ public class BrokerFacadeTest {
                 .when(readTransaction).read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
 
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
-            () -> brokerFacade.readConfigurationData(this.instanceID, "explicit"));
+            () -> brokerFacade.readConfigurationData(instanceID, "explicit"));
         final List<RestconfError> errors = ex.getErrors();
         assertEquals(1, errors.size());
         assertEquals("getErrorTag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
@@ -187,10 +187,10 @@ public class BrokerFacadeTest {
     @Test
     public void testInvokeRpc() throws Exception {
         final DOMRpcResult expResult = mock(DOMRpcResult.class);
-        doReturn(immediateFluentFuture(expResult)).when(this.mockRpcService).invokeRpc(this.qname, this.dummyNode);
+        doReturn(immediateFluentFuture(expResult)).when(mockRpcService).invokeRpc(qname, dummyNode);
 
-        final ListenableFuture<? extends DOMRpcResult> actualFuture = this.brokerFacade.invokeRpc(this.qname,
-            this.dummyNode);
+        final ListenableFuture<? extends DOMRpcResult> actualFuture = brokerFacade.invokeRpc(qname,
+            dummyNode);
         assertNotNull("Future is null", actualFuture);
         final DOMRpcResult actualResult = actualFuture.get();
         assertSame("invokeRpc", expResult, actualResult);
@@ -198,49 +198,49 @@ public class BrokerFacadeTest {
 
     @Test
     public void testCommitConfigurationDataPut() throws Exception {
-        doReturn(CommitInfo.emptyFluentFuture()).when(this.rwTransaction).commit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(rwTransaction).commit();
 
-        doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(this.rwTransaction)
-        .read(LogicalDatastoreType.CONFIGURATION, this.instanceID);
+        doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(rwTransaction)
+        .read(LogicalDatastoreType.CONFIGURATION, instanceID);
 
-        final PutResult result = this.brokerFacade.commitConfigurationDataPut(mock(EffectiveModelContext.class),
-                this.instanceID, this.dummyNode, null, null);
+        final PutResult result = brokerFacade.commitConfigurationDataPut(mock(EffectiveModelContext.class),
+                instanceID, dummyNode, null, null);
 
         assertSame("commitConfigurationDataPut", CommitInfo.emptyFluentFuture(), result.getFutureOfPutData());
 
-        final InOrder inOrder = inOrder(this.domDataBroker, this.rwTransaction);
-        inOrder.verify(this.domDataBroker).newReadWriteTransaction();
-        inOrder.verify(this.rwTransaction).put(LogicalDatastoreType.CONFIGURATION, this.instanceID, this.dummyNode);
-        inOrder.verify(this.rwTransaction).commit();
+        final InOrder inOrder = inOrder(domDataBroker, rwTransaction);
+        inOrder.verify(domDataBroker).newReadWriteTransaction();
+        inOrder.verify(rwTransaction).put(LogicalDatastoreType.CONFIGURATION, instanceID, dummyNode);
+        inOrder.verify(rwTransaction).commit();
     }
 
     @Test
     public void testCommitConfigurationDataPost() {
-        when(this.rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, this.instanceID))
+        when(rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, instanceID))
                 .thenReturn(wrapExistence(false));
 
-        doReturn(CommitInfo.emptyFluentFuture()).when(this.rwTransaction).commit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(rwTransaction).commit();
 
-        final FluentFuture<? extends CommitInfo> actualFuture = this.brokerFacade
-                .commitConfigurationDataPost(mock(EffectiveModelContext.class), this.instanceID, this.dummyNode, null,
+        final FluentFuture<? extends CommitInfo> actualFuture = brokerFacade
+                .commitConfigurationDataPost(mock(EffectiveModelContext.class), instanceID, dummyNode, null,
                         null);
 
         assertSame("commitConfigurationDataPost", CommitInfo.emptyFluentFuture(), actualFuture);
 
-        final InOrder inOrder = inOrder(this.domDataBroker, this.rwTransaction);
-        inOrder.verify(this.domDataBroker).newReadWriteTransaction();
-        inOrder.verify(this.rwTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.instanceID);
-        inOrder.verify(this.rwTransaction).put(LogicalDatastoreType.CONFIGURATION, this.instanceID, this.dummyNode);
-        inOrder.verify(this.rwTransaction).commit();
+        final InOrder inOrder = inOrder(domDataBroker, rwTransaction);
+        inOrder.verify(domDataBroker).newReadWriteTransaction();
+        inOrder.verify(rwTransaction).exists(LogicalDatastoreType.CONFIGURATION, instanceID);
+        inOrder.verify(rwTransaction).put(LogicalDatastoreType.CONFIGURATION, instanceID, dummyNode);
+        inOrder.verify(rwTransaction).commit();
     }
 
     @Test(expected = RestconfDocumentedException.class)
     public void testCommitConfigurationDataPostAlreadyExists() {
-        when(this.rwTransaction.exists(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class)))
+        when(rwTransaction.exists(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class)))
                 .thenReturn(immediateTrueFluentFuture());
         try {
             // Schema context is only necessary for ensuring parent structure
-            this.brokerFacade.commitConfigurationDataPost((EffectiveModelContext) null, this.instanceID, this.dummyNode,
+            brokerFacade.commitConfigurationDataPost((EffectiveModelContext) null, instanceID, dummyNode,
                     null, null);
         } catch (final RestconfDocumentedException e) {
             assertEquals("getErrorTag", ErrorTag.DATA_EXISTS, e.getErrors().get(0).getErrorTag());
@@ -257,20 +257,20 @@ public class BrokerFacadeTest {
         prepareDataForDelete(true);
 
         // expected result
-        doReturn(CommitInfo.emptyFluentFuture()).when(this.rwTransaction).commit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(rwTransaction).commit();
 
         // test
-        final FluentFuture<? extends CommitInfo> actualFuture = this.brokerFacade
-                .commitConfigurationDataDelete(this.instanceID);
+        final FluentFuture<? extends CommitInfo> actualFuture = brokerFacade
+                .commitConfigurationDataDelete(instanceID);
 
         // verify result and interactions
         assertSame("commitConfigurationDataDelete", CommitInfo.emptyFluentFuture(), actualFuture);
 
         // check exists, delete, submit
-        final InOrder inOrder = inOrder(this.domDataBroker, this.rwTransaction);
-        inOrder.verify(this.rwTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.instanceID);
-        inOrder.verify(this.rwTransaction).delete(LogicalDatastoreType.CONFIGURATION, this.instanceID);
-        inOrder.verify(this.rwTransaction).commit();
+        final InOrder inOrder = inOrder(domDataBroker, rwTransaction);
+        inOrder.verify(rwTransaction).exists(LogicalDatastoreType.CONFIGURATION, instanceID);
+        inOrder.verify(rwTransaction).delete(LogicalDatastoreType.CONFIGURATION, instanceID);
+        inOrder.verify(rwTransaction).commit();
     }
 
     /**
@@ -283,7 +283,7 @@ public class BrokerFacadeTest {
 
         // try to delete and expect DATA_MISSING error
         final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
-            () -> brokerFacade.commitConfigurationDataDelete(this.instanceID));
+            () -> brokerFacade.commitConfigurationDataDelete(instanceID));
         final List<RestconfError> errors = ex.getErrors();
         assertEquals(1, errors.size());
         assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
@@ -296,30 +296,30 @@ public class BrokerFacadeTest {
      * @param assumeDataExists boolean to assume if data exists
      */
     private void prepareDataForDelete(final boolean assumeDataExists) {
-        when(this.rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, this.instanceID))
+        when(rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, instanceID))
                 .thenReturn(immediateBooleanFluentFuture(assumeDataExists));
     }
 
     @Test
     public void testRegisterToListenDataChanges() {
-        final ListenerAdapter listener = Notificator.createListener(this.instanceID, "stream",
+        final ListenerAdapter listener = Notificator.createListener(instanceID, "stream",
                 NotificationOutputType.XML, controllerContext);
 
         @SuppressWarnings("unchecked")
         final ListenerRegistration<ListenerAdapter> mockRegistration = mock(ListenerRegistration.class);
 
-        DOMDataTreeChangeService changeService = this.domDataBroker.getExtensions()
+        DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
                 .getInstance(DOMDataTreeChangeService.class);
-        DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, this.instanceID);
+        DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, instanceID);
         when(changeService.registerDataTreeChangeListener(eq(loc), eq(listener))).thenReturn(mockRegistration);
 
-        this.brokerFacade.registerToListenDataChanges(LogicalDatastoreType.CONFIGURATION, Scope.BASE, listener);
+        brokerFacade.registerToListenDataChanges(LogicalDatastoreType.CONFIGURATION, Scope.BASE, listener);
 
         verify(changeService).registerDataTreeChangeListener(loc, listener);
 
         assertEquals("isListening", true, listener.isListening());
 
-        this.brokerFacade.registerToListenDataChanges(LogicalDatastoreType.CONFIGURATION, Scope.BASE, listener);
+        brokerFacade.registerToListenDataChanges(LogicalDatastoreType.CONFIGURATION, Scope.BASE, listener);
         verifyNoMoreInteractions(changeService);
     }
 
@@ -337,20 +337,20 @@ public class BrokerFacadeTest {
 
         // mock registration
         final ListenerRegistration<NotificationListenerAdapter> registration = mock(ListenerRegistration.class);
-        when(this.domNotification.registerNotificationListener(listener,
+        when(domNotification.registerNotificationListener(listener,
             Absolute.of(ImmutableList.copyOf(listener.getSchemaPath().getPathFromRoot()))))
                 .thenReturn(registration);
 
         // test to register listener for the first time
-        this.brokerFacade.registerToListenNotification(listener);
+        brokerFacade.registerToListenNotification(listener);
         assertEquals("Registration was not successful", true, listener.isListening());
 
         // try to register for the second time
-        this.brokerFacade.registerToListenNotification(listener);
+        brokerFacade.registerToListenNotification(listener);
         assertEquals("Registration was not successful", true, listener.isListening());
 
         // registrations should be invoked only once
-        verify(this.domNotification, times(1)).registerNotificationListener(listener,
+        verify(domNotification, times(1)).registerNotificationListener(listener,
             Absolute.of(ImmutableList.copyOf(listener.getSchemaPath().getPathFromRoot())));
 
         final DOMTransactionChain transactionChain = mock(DOMTransactionChain.class);
@@ -366,7 +366,7 @@ public class BrokerFacadeTest {
     @Test
     public void testPatchConfigurationDataWithinTransactionServer() throws Exception {
         final PatchContext patchContext = mock(PatchContext.class);
-        final InstanceIdentifierContext<?> identifierContext = mock(InstanceIdentifierContext.class);
+        final InstanceIdentifierContext identifierContext = mock(InstanceIdentifierContext.class);
 
         when(patchContext.getData()).thenReturn(new ArrayList<>());
         doReturn(identifierContext).when(patchContext).getInstanceIdentifierContext();
@@ -374,9 +374,9 @@ public class BrokerFacadeTest {
         // no mount point
         when(identifierContext.getMountPoint()).thenReturn(null);
 
-        doReturn(CommitInfo.emptyFluentFuture()).when(this.rwTransaction).commit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(rwTransaction).commit();
 
-        final PatchStatusContext status = this.brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
+        final PatchStatusContext status = brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
 
         // assert success
         assertTrue("Patch operation should be successful on server", status.isOk());
@@ -388,7 +388,7 @@ public class BrokerFacadeTest {
     @Test
     public void testPatchConfigurationDataWithinTransactionMount() throws Exception {
         final PatchContext patchContext = mock(PatchContext.class);
-        final InstanceIdentifierContext<?> identifierContext = mock(InstanceIdentifierContext.class);
+        final InstanceIdentifierContext identifierContext = mock(InstanceIdentifierContext.class);
         final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
         final DOMDataBroker mountDataBroker = mock(DOMDataBroker.class);
         final DOMDataTreeReadWriteTransaction transaction = mock(DOMDataTreeReadWriteTransaction.class);
@@ -403,7 +403,7 @@ public class BrokerFacadeTest {
         when(mountDataBroker.newReadWriteTransaction()).thenReturn(transaction);
         doReturn(CommitInfo.emptyFluentFuture()).when(transaction).commit();
 
-        final PatchStatusContext status = this.brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
+        final PatchStatusContext status = brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
 
         // assert success
         assertTrue("Patch operation should be successful on mounted device", status.isOk());
@@ -416,7 +416,7 @@ public class BrokerFacadeTest {
     @Test
     public void testPatchConfigurationDataWithinTransactionMountFail() throws Exception {
         final PatchContext patchContext = mock(PatchContext.class);
-        final InstanceIdentifierContext<?> identifierContext = mock(InstanceIdentifierContext.class);
+        final InstanceIdentifierContext identifierContext = mock(InstanceIdentifierContext.class);
         final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
         final DOMDataBroker mountDataBroker = mock(DOMDataBroker.class);
         final DOMDataTreeReadWriteTransaction transaction = mock(DOMDataTreeReadWriteTransaction.class);
@@ -429,7 +429,7 @@ public class BrokerFacadeTest {
         when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.empty());
 
 
-        final PatchStatusContext status = this.brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
+        final PatchStatusContext status = brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
 
         // assert not successful operation with error
         assertNotNull(status.getGlobalErrors());