* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.sal.restconf.impl.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateBooleanFluentFuture;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateTrueFluentFuture;
-import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableClassToInstanceMap;
+import com.google.common.collect.ImmutableList;
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 com.google.common.util.concurrent.FluentFuture;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
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.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.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;
-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.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.PutResult;
import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
import org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapter;
import org.opendaylight.netconf.sal.streams.listeners.Notificator;
+import org.opendaylight.restconf.common.ErrorTags;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
-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.common.util.DataChangeScope;
+import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope;
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.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
/**
* Unit tests for BrokerFacade.
*
* @author Thomas Pantelis
*/
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class BrokerFacadeTest {
@Mock
@Mock
private DOMMountPoint mockMountInstance;
@Mock
- private DOMDataReadOnlyTransaction readTransaction;
+ private DOMDataTreeReadTransaction readTransaction;
@Mock
- private DOMDataWriteTransaction writeTransaction;
+ private DOMDataTreeWriteTransaction writeTransaction;
@Mock
- private DOMDataReadWriteTransaction rwTransaction;
+ private DOMDataTreeReadWriteTransaction rwTransaction;
private BrokerFacade brokerFacade;
- private final NormalizedNode<?, ?> dummyNode = createDummyNode("test:module", "2014-01-09", "interfaces");
- private final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> dummyNodeInFuture =
- wrapDummyNode(this.dummyNode);
+ private final NormalizedNode dummyNode = createDummyNode("test:module", "2014-01-09", "interfaces");
+ private final FluentFuture<Optional<NormalizedNode>> dummyNodeInFuture = wrapDummyNode(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 final YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(qname).build();
private ControllerContext controllerContext;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
-
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);
- HashMap extensions = new HashMap();
- extensions.put(DOMDataTreeChangeService.class, Mockito.mock(DOMDataTreeChangeService.class));
- when(this.domDataBroker.getSupportedExtensions()).thenReturn(extensions);
+ when(domDataBroker.newReadOnlyTransaction()).thenReturn(readTransaction);
+ when(domDataBroker.newReadWriteTransaction()).thenReturn(rwTransaction);
+ when(domDataBroker.getExtensions()).thenReturn(ImmutableClassToInstanceMap.of(
+ DOMDataTreeChangeService.class, Mockito.mock(DOMDataTreeChangeService.class)));
}
- private static CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> wrapDummyNode(
- final NormalizedNode<?, ?> dummyNode) {
- return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?, ?>>of(dummyNode));
+ private static FluentFuture<Optional<NormalizedNode>> wrapDummyNode(final NormalizedNode dummyNode) {
+ return immediateFluentFuture(Optional.of(dummyNode));
}
- private static CheckedFuture<Boolean, ReadFailedException> wrapExistence(final Boolean exists) {
- return Futures.immediateCheckedFuture(exists);
+ private static FluentFuture<Boolean> wrapExistence(final boolean exists) {
+ return immediateBooleanFluentFuture(exists);
}
/**
* Value of this node shouldn't be important for testing purposes.
*/
- private static NormalizedNode<?, ?> createDummyNode(final String namespace, final String date,
- final String localName) {
+ private static NormalizedNode createDummyNode(final String namespace, final String date, final String localName) {
return Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(QName.create(namespace, date, localName))).build();
+ .withNodeIdentifier(new NodeIdentifier(QName.create(namespace, date, localName)))
+ .build();
}
@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
public void test503() throws Exception {
final RpcError error = RpcResultBuilder.newError(
RpcError.ErrorType.TRANSPORT,
- ErrorTag.RESOURCE_DENIED.getTagValue(),
+ ErrorTag.RESOURCE_DENIED.elementBody(),
"Master is down. Please try again.");
- final ReadFailedException exception503 = new ReadFailedException("Read from transaction failed", error);
- doReturn(Futures.immediateFailedCheckedFuture(exception503))
+ doReturn(immediateFailedFluentFuture(new ReadFailedException("Read from transaction failed", error)))
.when(readTransaction).read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
- try {
- brokerFacade.readConfigurationData(this.instanceID, "explicit");
- fail("This test should fail.");
- } catch (final RestconfDocumentedException e) {
- assertEquals("getErrorTag", ErrorTag.RESOURCE_DENIED_TRANSPORT, e.getErrors().get(0).getErrorTag());
- assertEquals("getErrorType", ErrorType.TRANSPORT, e.getErrors().get(0).getErrorType());
- assertEquals("getErrorMessage", "Master is down. Please try again.",
- e.getErrors().get(0).getErrorMessage());
- }
+
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> brokerFacade.readConfigurationData(instanceID, "explicit"));
+ final List<RestconfError> errors = ex.getErrors();
+ assertEquals(1, errors.size());
+ assertEquals("getErrorTag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
+ assertEquals("getErrorType", ErrorType.TRANSPORT,errors.get(0).getErrorType());
+ assertEquals("getErrorMessage", "Master is down. Please try again.", errors.get(0).getErrorMessage());
}
@Test
public void testInvokeRpc() throws Exception {
final DOMRpcResult expResult = mock(DOMRpcResult.class);
- final CheckedFuture<DOMRpcResult, DOMRpcException> future = Futures.immediateCheckedFuture(expResult);
- when(this.mockRpcService.invokeRpc(this.type, this.dummyNode)).thenReturn(future);
+ doReturn(immediateFluentFuture(expResult)).when(mockRpcService).invokeRpc(qname, dummyNode);
- final CheckedFuture<DOMRpcResult, DOMRpcException> actualFuture = this.brokerFacade
- .invokeRpc(this.type, 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 {
- @SuppressWarnings("unchecked")
- final CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
- when(this.rwTransaction.submit()).thenReturn(expFuture);
-
- final Optional<NormalizedNode<?, ?>> optionalMock = mock(Optional.class);
- when(optionalMock.get()).thenReturn(null);
+ doReturn(CommitInfo.emptyFluentFuture()).when(rwTransaction).commit();
- final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = Futures
- .immediateCheckedFuture(optionalMock);
- when(this.rwTransaction.read(LogicalDatastoreType.CONFIGURATION, this.instanceID)).thenReturn(readFuture);
+ doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(rwTransaction)
+ .read(LogicalDatastoreType.CONFIGURATION, instanceID);
- final PutResult result = this.brokerFacade.commitConfigurationDataPut(mock(SchemaContext.class),
- this.instanceID, this.dummyNode, null, null);
+ final PutResult result = brokerFacade.commitConfigurationDataPut(mock(EffectiveModelContext.class),
+ instanceID, dummyNode, null, null);
- final Future<Void> actualFuture = result.getFutureOfPutData();
+ assertSame("commitConfigurationDataPut", CommitInfo.emptyFluentFuture(), result.getFutureOfPutData());
- assertSame("commitConfigurationDataPut", expFuture, actualFuture);
-
- 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).submit();
+ 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() {
- @SuppressWarnings("unchecked")
- final CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
-
- when(this.rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, this.instanceID))
+ when(rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, instanceID))
.thenReturn(wrapExistence(false));
- when(this.rwTransaction.submit()).thenReturn(expFuture);
+ doReturn(CommitInfo.emptyFluentFuture()).when(rwTransaction).commit();
- final CheckedFuture<Void, TransactionCommitFailedException> actualFuture = this.brokerFacade
- .commitConfigurationDataPost(mock(SchemaContext.class), this.instanceID, this.dummyNode, null, null);
+ final FluentFuture<? extends CommitInfo> actualFuture = brokerFacade
+ .commitConfigurationDataPost(mock(EffectiveModelContext.class), instanceID, dummyNode, null,
+ null);
- assertSame("commitConfigurationDataPost", expFuture, actualFuture);
+ 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).submit();
+ 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() {
- final CheckedFuture<Boolean, ReadFailedException> successFuture = Futures.immediateCheckedFuture(Boolean.TRUE);
- when(this.rwTransaction.exists(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class)))
- .thenReturn(successFuture);
+ when(rwTransaction.exists(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class)))
+ .thenReturn(immediateTrueFluentFuture());
try {
// Schema context is only necessary for ensuring parent structure
- this.brokerFacade.commitConfigurationDataPost((SchemaContext) null, this.instanceID, this.dummyNode, null,
- null);
+ brokerFacade.commitConfigurationDataPost((EffectiveModelContext) null, instanceID, dummyNode,
+ null, null);
} catch (final RestconfDocumentedException e) {
- assertEquals("getErrorTag", RestconfError.ErrorTag.DATA_EXISTS, e.getErrors().get(0).getErrorTag());
+ assertEquals("getErrorTag", ErrorTag.DATA_EXISTS, e.getErrors().get(0).getErrorTag());
throw e;
}
}
prepareDataForDelete(true);
// expected result
- @SuppressWarnings("unchecked")
- final CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
- when(this.rwTransaction.submit()).thenReturn(expFuture);
+ doReturn(CommitInfo.emptyFluentFuture()).when(rwTransaction).commit();
// test
- final CheckedFuture<Void, TransactionCommitFailedException> actualFuture = this.brokerFacade
- .commitConfigurationDataDelete(this.instanceID);
+ final FluentFuture<? extends CommitInfo> actualFuture = brokerFacade
+ .commitConfigurationDataDelete(instanceID);
// verify result and interactions
- assertSame("commitConfigurationDataDelete", expFuture, actualFuture);
+ 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).submit();
+ final InOrder inOrder = inOrder(domDataBroker, rwTransaction);
+ inOrder.verify(rwTransaction).exists(LogicalDatastoreType.CONFIGURATION, instanceID);
+ inOrder.verify(rwTransaction).delete(LogicalDatastoreType.CONFIGURATION, instanceID);
+ inOrder.verify(rwTransaction).commit();
}
/**
- * Negative test of delete operation when data to delete does not exist. Error 404 should be returned.
+ * Negative test of delete operation when data to delete does not exist. Error DATA_MISSING should be returned.
*/
@Test
public void testCommitConfigurationDataDeleteNoData() throws Exception {
// assume that data to delete does not exist
prepareDataForDelete(false);
- // try to delete and expect 404 error
- try {
- this.brokerFacade.commitConfigurationDataDelete(this.instanceID);
- fail("Delete operation should fail due to missing data");
- } catch (final RestconfDocumentedException e) {
- assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals(ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals(404, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ // try to delete and expect DATA_MISSING error
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> brokerFacade.commitConfigurationDataDelete(instanceID));
+ final List<RestconfError> errors = ex.getErrors();
+ assertEquals(1, errors.size());
+ assertEquals(ErrorType.PROTOCOL, errors.get(0).getErrorType());
+ assertEquals(ErrorTag.DATA_MISSING, errors.get(0).getErrorTag());
}
/**
* @param assumeDataExists boolean to assume if data exists
*/
private void prepareDataForDelete(final boolean assumeDataExists) {
- when(this.rwTransaction.exists(LogicalDatastoreType.CONFIGURATION, this.instanceID))
- .thenReturn(Futures.immediateCheckedFuture(new Boolean(assumeDataExists)));
+ 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 = (DOMDataTreeChangeService)
- this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
- DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, this.instanceID);
+ DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
+ .getInstance(DOMDataTreeChangeService.class);
+ DOMDataTreeIdentifier loc = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, instanceID);
when(changeService.registerDataTreeChangeListener(eq(loc), eq(listener))).thenReturn(mockRegistration);
- this.brokerFacade.registerToListenDataChanges(
- LogicalDatastoreType.CONFIGURATION, DataChangeScope.BASE, listener);
+ brokerFacade.registerToListenDataChanges(LogicalDatastoreType.CONFIGURATION, Scope.BASE, listener);
verify(changeService).registerDataTreeChangeListener(loc, listener);
assertEquals("isListening", true, listener.isListening());
- this.brokerFacade.registerToListenDataChanges(
- LogicalDatastoreType.CONFIGURATION, DataChangeScope.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, listener.getSchemaPath()))
+ 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, listener.getSchemaPath());
+ verify(domNotification, times(1)).registerNotificationListener(listener,
+ Absolute.of(ImmutableList.copyOf(listener.getSchemaPath().getPathFromRoot())));
final DOMTransactionChain transactionChain = mock(DOMTransactionChain.class);
- final DOMDataWriteTransaction wTx = mock(DOMDataWriteTransaction.class);
- final CheckedFuture<Void, TransactionCommitFailedException> checked = Futures.immediateCheckedFuture(null);
- when(wTx.submit()).thenReturn(checked);
- when(transactionChain.newWriteOnlyTransaction()).thenReturn(wTx);
+ final DOMDataTreeWriteTransaction wTx = mock(DOMDataTreeWriteTransaction.class);
// close and remove test notification listener
listener.close();
Notificator.removeListenerIfNoSubscriberExists(listener);
* Test Patch method on the server with no data.
*/
@Test
- @SuppressWarnings("unchecked")
public void testPatchConfigurationDataWithinTransactionServer() throws Exception {
final PatchContext patchContext = mock(PatchContext.class);
final InstanceIdentifierContext identifierContext = mock(InstanceIdentifierContext.class);
- final CheckedFuture<Void, TransactionCommitFailedException> expFuture = Futures.immediateCheckedFuture(null);
- when(patchContext.getData()).thenReturn(Lists.newArrayList());
- when(patchContext.getInstanceIdentifierContext()).thenReturn(identifierContext);
+ when(patchContext.getData()).thenReturn(new ArrayList<>());
+ doReturn(identifierContext).when(patchContext).getInstanceIdentifierContext();
// no mount point
when(identifierContext.getMountPoint()).thenReturn(null);
- when(this.rwTransaction.submit()).thenReturn(expFuture);
+ 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 Patch method on mounted device with no data.
*/
@Test
- @SuppressWarnings("unchecked")
public void testPatchConfigurationDataWithinTransactionMount() throws Exception {
final PatchContext patchContext = mock(PatchContext.class);
final InstanceIdentifierContext identifierContext = mock(InstanceIdentifierContext.class);
final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
final DOMDataBroker mountDataBroker = mock(DOMDataBroker.class);
- final DOMDataReadWriteTransaction transaction = mock(DOMDataReadWriteTransaction.class);
- final CheckedFuture<Void, TransactionCommitFailedException> expFuture = Futures.immediateCheckedFuture(null);
+ final DOMDataTreeReadWriteTransaction transaction = mock(DOMDataTreeReadWriteTransaction.class);
- when(patchContext.getData()).thenReturn(Lists.newArrayList());
- when(patchContext.getInstanceIdentifierContext()).thenReturn(identifierContext);
+ when(patchContext.getData()).thenReturn(new ArrayList<>());
+ doReturn(identifierContext).when(patchContext).getInstanceIdentifierContext();
// return mount point with broker
when(identifierContext.getMountPoint()).thenReturn(mountPoint);
when(mountPoint.getService(DOMDataBroker.class)).thenReturn(Optional.of(mountDataBroker));
+ when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.empty());
when(mountDataBroker.newReadWriteTransaction()).thenReturn(transaction);
- when(transaction.submit()).thenReturn(expFuture);
+ 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());
* Patch operation should fail with global error.
*/
@Test
- @SuppressWarnings("unchecked")
public void testPatchConfigurationDataWithinTransactionMountFail() throws Exception {
final PatchContext patchContext = mock(PatchContext.class);
final InstanceIdentifierContext identifierContext = mock(InstanceIdentifierContext.class);
final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
final DOMDataBroker mountDataBroker = mock(DOMDataBroker.class);
- final DOMDataReadWriteTransaction transaction = mock(DOMDataReadWriteTransaction.class);
- final CheckedFuture<Void, TransactionCommitFailedException> expFuture = Futures.immediateCheckedFuture(null);
+ final DOMDataTreeReadWriteTransaction transaction = mock(DOMDataTreeReadWriteTransaction.class);
- when(patchContext.getData()).thenReturn(Lists.newArrayList());
- when(patchContext.getInstanceIdentifierContext()).thenReturn(identifierContext);
+ doReturn(identifierContext).when(patchContext).getInstanceIdentifierContext();
when(identifierContext.getMountPoint()).thenReturn(mountPoint);
// missing broker on mounted device
- when(mountPoint.getService(DOMDataBroker.class)).thenReturn(Optional.absent());
+ when(mountPoint.getService(DOMDataBroker.class)).thenReturn(Optional.empty());
+ when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.empty());
- when(mountDataBroker.newReadWriteTransaction()).thenReturn(transaction);
- when(transaction.submit()).thenReturn(expFuture);
- final PatchStatusContext status = this.brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
+ final PatchStatusContext status = brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
// assert not successful operation with error
assertNotNull(status.getGlobalErrors());