Search in sources :

Example 21 with DataTreeCandidateNode

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

the class DataTreeCandidateNodesTest method testApplyRootedNodeToCursorWithUnsupportedModificationType.

@Test
public void testApplyRootedNodeToCursorWithUnsupportedModificationType() {
    final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
    final YangInstanceIdentifier mockedRootPath = mock(YangInstanceIdentifier.class);
    final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
    doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
    final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, mockedRootPath, mockedDataTreeCandidateNode));
    assertThat(ex.getMessage(), containsString("Unsupported modification"));
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) DataTreeModificationCursor(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 22 with DataTreeCandidateNode

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

the class DataTreeCandidateNodesTest method testApplyToCursorWithWriteModificationType.

@Test
public void testApplyToCursorWithWriteModificationType() {
    final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
    final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
    doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
    final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
    doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
    DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
    verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) DataTreeModificationCursor(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 23 with DataTreeCandidateNode

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

the class DataTreeCandidatesTest method testApplyToModificationWithUnsupportedModificationType.

@Test
public void testApplyToModificationWithUnsupportedModificationType() {
    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.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
    final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate));
    assertThat(ex.getMessage(), containsString("Unsupported modification"));
}
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 24 with DataTreeCandidateNode

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

the class DataTreeCandidatesTest method testApplyToModificationWithSubtreeModifiedModificationType.

@Test
public void testApplyToModificationWithSubtreeModifiedModificationType() {
    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.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
    final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
    doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
    final PathArgument mockedPathArgument1 = mock(PathArgument.class);
    doReturn(mockedPathArgument1).when(mockedChildNode1).getIdentifier();
    final DataTreeCandidateNode mockedChildNode2 = mock(DataTreeCandidateNode.class);
    doReturn(ModificationType.WRITE).when(mockedChildNode2).getModificationType();
    final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
    doReturn(Optional.of(mockedNormalizedNode)).when(mockedChildNode2).getDataAfter();
    final PathArgument mockedPathArgument2 = mock(PathArgument.class);
    doReturn(mockedPathArgument2).when(mockedChildNode2).getIdentifier();
    final DataTreeCandidateNode mockedChildNode3 = mock(DataTreeCandidateNode.class);
    doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).getModificationType();
    final PathArgument mockedPathArgument3 = mock(PathArgument.class);
    doReturn(mockedPathArgument3).when(mockedChildNode3).getIdentifier();
    final DataTreeCandidateNode mockedChildNode3ChildNode = mock(DataTreeCandidateNode.class);
    doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).getModificationType();
    final PathArgument mockedPathArgument31 = mock(PathArgument.class);
    doReturn(mockedPathArgument3).when(mockedChildNode3).getIdentifier();
    doReturn(mockedPathArgument31).when(mockedChildNode3ChildNode).getIdentifier();
    doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).getChildNodes();
    final List<DataTreeCandidateNode> childNodes = List.of(mockedChildNode1, mockedChildNode2, mockedChildNode3);
    doReturn(childNodes).when(mockedDataTreeCandidateNode).getChildNodes();
    DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
    verify(mockedModification, times(2)).delete(any(YangInstanceIdentifier.class));
    verify(mockedModification, times(1)).write(any(YangInstanceIdentifier.class), any(NormalizedNode.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) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 25 with DataTreeCandidateNode

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

the class DataTreeCandidatesTest method testApplyToModificationWithWriteModificationType.

@Test
public void testApplyToModificationWithWriteModificationType() {
    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();
    final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
    doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
    doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
    DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
    verify(mockedModification, times(1)).write(any(YangInstanceIdentifier.class), any(NormalizedNode.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) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) 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