Search in sources :

Example 26 with DataTreeCandidateNode

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

the class DataTreeCandidatesTest method testApplyToCursorAwareModificationRoot.

@Test
public void testApplyToCursorAwareModificationRoot() {
    final DataTreeCandidate mockedDataTreeCandidate = mock(DataTreeCandidate.class);
    final CursorAwareDataTreeModification mockedModification = mock(CursorAwareDataTreeModification.class);
    final YangInstanceIdentifier mockedRootPath = mock(YangInstanceIdentifier.class);
    final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
    doReturn(mockedRootPath).when(mockedDataTreeCandidate).getRootPath();
    doReturn(null).when(mockedRootPath).getParent();
    doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
    doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
    IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate));
    assertEquals("Can not delete root.", thrown.getMessage());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 27 with DataTreeCandidateNode

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

the class DataTreeCandidatesTest method testApplyToModificationWithDeleteModificationType.

@Test
public void testApplyToModificationWithDeleteModificationType() {
    final DataTreeCandidate mockedDataTreeCandidate = mock(DataTreeCandidate.class);
    final DataTreeModification mockedModification = mock(DataTreeModification.class);
    final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
    doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
    final YangInstanceIdentifier mockedRootPath = mock(YangInstanceIdentifier.class);
    doReturn(mockedRootPath).when(mockedDataTreeCandidate).getRootPath();
    doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
    DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
    verify(mockedModification, times(1)).delete(any(YangInstanceIdentifier.class));
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 28 with DataTreeCandidateNode

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

the class DataTreeCandidatesAggregateTest method testLeafWriteWrite.

@Test
public void testLeafWriteWrite() {
    NormalizedNode normalizedNode1 = normalizedNode("value1");
    NormalizedNode normalizedNode2 = normalizedNode("value2");
    NormalizedNode normalizedNode3 = normalizedNode("value3");
    DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2, ModificationType.WRITE);
    DataTreeCandidate candidate1 = new DefaultDataTreeCandidate(ROOT_PATH, node1);
    DataTreeCandidateNode node2 = dataTreeCandidateNode(normalizedNode2, normalizedNode3, ModificationType.WRITE);
    DataTreeCandidate candidate2 = new DefaultDataTreeCandidate(ROOT_PATH, node2);
    DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
    assertEquals(ModificationType.WRITE, aggregationResult.getRootNode().getModificationType());
    assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
    assertEquals("value3", aggregationResult.getRootNode().getDataAfter().get().body());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 29 with DataTreeCandidateNode

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

the class DataTreeCandidatesAggregateTest method testLeafUnmodifiedDelete.

@Test
public void testLeafUnmodifiedDelete() {
    NormalizedNode normalizedNode1 = normalizedNode("value1");
    NormalizedNode normalizedNode2 = normalizedNode("value1");
    DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2, ModificationType.UNMODIFIED);
    DataTreeCandidate candidate1 = new DefaultDataTreeCandidate(ROOT_PATH, node1);
    DataTreeCandidateNode node2 = dataTreeCandidateNode(normalizedNode2, null, ModificationType.DELETE);
    DataTreeCandidate candidate2 = new DefaultDataTreeCandidate(ROOT_PATH, node2);
    DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
    assertEquals(ModificationType.DELETE, aggregationResult.getRootNode().getModificationType());
    assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
    assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 30 with DataTreeCandidateNode

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

the class DataTreeCandidatesAggregateTest method testLeafUnmodifiedUnmodified.

@Test
public void testLeafUnmodifiedUnmodified() {
    NormalizedNode normalizedNode1 = normalizedNode("value1");
    NormalizedNode normalizedNode2 = normalizedNode("value1");
    NormalizedNode normalizedNode3 = normalizedNode("value1");
    DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2, ModificationType.UNMODIFIED);
    DataTreeCandidate candidate1 = new DefaultDataTreeCandidate(ROOT_PATH, node1);
    DataTreeCandidateNode node2 = dataTreeCandidateNode(normalizedNode2, normalizedNode3, ModificationType.UNMODIFIED);
    DataTreeCandidate candidate2 = new DefaultDataTreeCandidate(ROOT_PATH, node2);
    DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
    assertEquals(ModificationType.UNMODIFIED, aggregationResult.getRootNode().getModificationType());
    assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
    assertEquals("value1", aggregationResult.getRootNode().getDataAfter().get().body());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) 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