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
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)));
}
@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
.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());
@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);
@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());
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();
}
/**
// 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());
* @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);
}
// 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);
@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();
// 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());
@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);
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());
@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);
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());