Search in sources :

Example 1 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project mdsal by opendaylight.

the class BindingStructuralTypeTest method basicTest.

@Test
public void basicTest() throws Exception {
    final NormalizedNode normalizedNode = mock(NormalizedNode.class);
    final Optional<?> optional = Optional.of(normalizedNode);
    final DataTreeCandidateNode dataTreeCandidateNode = mock(DataTreeCandidateNode.class);
    doReturn(optional).when(dataTreeCandidateNode).getDataAfter();
    doReturn(optional).when(dataTreeCandidateNode).getDataBefore();
    assertEquals(BindingStructuralType.UNKNOWN, BindingStructuralType.from(dataTreeCandidateNode));
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 2 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode 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());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 3 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode 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();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) CountDownLatch(java.util.concurrent.CountDownLatch) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Test(org.junit.Test)

Example 4 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode 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();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode 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();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)63 Test (org.junit.Test)48 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)36 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)23 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 DataTreeModificationCursor (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor)13 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)9 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)7 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataTreeChangeService (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService)6 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)6 ArrayList (java.util.ArrayList)5 NonNull (org.eclipse.jdt.annotation.NonNull)3 ModificationType (org.opendaylight.yangtools.yang.data.tree.api.ModificationType)3 Objects.requireNonNull (java.util.Objects.requireNonNull)2 List (java.util.List)1 BindingCodecTreeNode (org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode)1 BindingDataObjectCodecTreeNode (org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode)1 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)1