use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project mdsal by opendaylight.
the class AbstractDOMStoreTreeChangePublisherTest method basicTest.
@Test
public void basicTest() throws Exception {
final DataTreeCandidate dataTreeCandidate = mock(DataTreeCandidate.class);
final DataTreeCandidateNode dataTreeCandidateNode = mock(DataTreeCandidateNode.class, "dataTreeCandidateNode");
final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().node(QName.create("", "node1")).node(QName.create("", "node2")).build();
doReturn(dataTreeCandidateNode).when(dataTreeCandidate).getRootNode();
doReturn(ModificationType.WRITE).when(dataTreeCandidateNode).getModificationType();
doReturn(yangInstanceIdentifier).when(dataTreeCandidate).getRootPath();
doReturn(ImmutableList.of(dataTreeCandidateNode)).when(dataTreeCandidateNode).getChildNodes();
doReturn(yangInstanceIdentifier.getLastPathArgument()).when(dataTreeCandidateNode).getIdentifier();
final DOMDataTreeChangeListener domDataTreeChangeListener = mock(DOMDataTreeChangeListener.class);
final AbstractDOMDataTreeChangeListenerRegistration<?> abstractDOMDataTreeChangeListenerRegistration = this.registerTreeChangeListener(yangInstanceIdentifier, domDataTreeChangeListener);
assertFalse(removeInvoked);
assertFalse(notifyInvoked);
this.processCandidateTree(dataTreeCandidate);
doReturn(ModificationType.UNMODIFIED).when(dataTreeCandidateNode).getModificationType();
this.processCandidateTree(dataTreeCandidate);
abstractDOMDataTreeChangeListenerRegistration.close();
assertTrue(removeInvoked);
assertTrue(notifyInvoked);
assertTrue(abstractDOMDataTreeChangeListenerRegistration.isClosed());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project mdsal by opendaylight.
the class DOMDataTreeChangeListenerTest method receiveOnDataTreeChangeEventForPreExistingData.
@Test
public void receiveOnDataTreeChangeEventForPreExistingData() throws InterruptedException, ExecutionException {
final DOMDataTreeChangeListener listener = mock(DOMDataTreeChangeListener.class);
final ArgumentCaptor<List> candidateCapture = ArgumentCaptor.forClass(List.class);
doNothing().when(listener).onDataTreeChanged(any());
final ContainerNode testNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build()).build();
DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
assertNotNull(writeTx);
writeTx.write(TestModel.TEST_PATH, testNode);
DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
cohort.preCommit().get();
cohort.commit().get();
domStore.registerTreeChangeListener(TestModel.TEST_PATH, listener);
verify(listener, timeout(1000)).onDataTreeChanged(candidateCapture.capture());
final DataTreeCandidate firstItem = (DataTreeCandidate) candidateCapture.getValue().iterator().next();
assertEquals(TestModel.TEST_PATH, firstItem.getRootPath());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project mdsal by opendaylight.
the class DOMDataTreeListenerTest method listEntryChangeNonRootRegistrationTest.
@Test
public void listEntryChangeNonRootRegistrationTest() throws ExecutionException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
final DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
DOMDataTreeWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
writeTx.commit().get();
final TestDataTreeListener listener = new TestDataTreeListener(latch);
final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener);
final NodeIdentifierWithPredicates outerListEntryId1 = NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
final NodeIdentifierWithPredicates outerListEntryId2 = NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
final NodeIdentifierWithPredicates outerListEntryId3 = NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3);
final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
final MapEntryNode outerListEntry3 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3);
final MapNode listAfter = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry2).withChild(outerListEntry3).build();
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId1));
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId2), outerListEntry2);
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId3), outerListEntry3);
writeTx.commit();
latch.await(5, TimeUnit.SECONDS);
assertEquals(2, listener.getReceivedChanges().size());
List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
assertEquals(1, changes.size());
DataTreeCandidate candidate = changes.get(0);
assertNotNull(candidate);
DataTreeCandidateNode candidateRoot = candidate.getRootNode();
checkChange(null, OUTER_LIST, ModificationType.WRITE, candidateRoot);
changes = listener.getReceivedChanges().get(1);
assertEquals(1, changes.size());
candidate = changes.get(0);
assertNotNull(candidate);
candidateRoot = candidate.getRootNode();
checkChange(OUTER_LIST, listAfter, ModificationType.SUBTREE_MODIFIED, candidateRoot);
final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1).get();
checkChange(outerListEntry1, null, ModificationType.DELETE, entry1Canditate);
final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2).get();
checkChange(null, outerListEntry2, ModificationType.WRITE, entry2Canditate);
final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3).get();
checkChange(null, outerListEntry3, ModificationType.WRITE, entry3Canditate);
listenerReg.close();
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project mdsal by opendaylight.
the class DOMDataTreeListenerTest method rootModificationChildListenerTest.
@Test
public void rootModificationChildListenerTest() throws ExecutionException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
final DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
DOMDataTreeWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
writeTx.commit().get();
final TestDataTreeListener listener = new TestDataTreeListener(latch);
final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener);
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2);
writeTx.commit().get();
latch.await(1, TimeUnit.SECONDS);
assertEquals(2, listener.getReceivedChanges().size());
List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
assertEquals(1, changes.size());
DataTreeCandidate candidate = changes.get(0);
assertNotNull(candidate);
DataTreeCandidateNode candidateRoot = candidate.getRootNode();
checkChange(null, OUTER_LIST, ModificationType.WRITE, candidateRoot);
changes = listener.getReceivedChanges().get(1);
assertEquals(1, changes.size());
candidate = changes.get(0);
assertNotNull(candidate);
candidateRoot = candidate.getRootNode();
checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, candidateRoot);
listenerReg.close();
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project mdsal by opendaylight.
the class DOMDataTreeListenerTest method deleteContainerContainerInTreeTest.
@Test
public void deleteContainerContainerInTreeTest() throws ExecutionException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
final DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
DOMDataTreeWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
writeTx.commit().get();
final TestDataTreeListener listener = new TestDataTreeListener(latch);
final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
writeTx.commit();
latch.await(5, TimeUnit.SECONDS);
assertEquals(2, listener.getReceivedChanges().size());
List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
assertEquals(1, changes.size());
DataTreeCandidate candidate = changes.get(0);
assertNotNull(candidate);
DataTreeCandidateNode candidateRoot = candidate.getRootNode();
checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
changes = listener.getReceivedChanges().get(1);
assertEquals(1, changes.size());
candidate = changes.get(0);
assertNotNull(candidate);
candidateRoot = candidate.getRootNode();
checkChange(TEST_CONTAINER, null, ModificationType.DELETE, candidateRoot);
listenerReg.close();
}
Aggregations