Search in sources :

Example 6 with DataTreeCandidate

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

the class DataTreeCandidateInputOutputTest method assertSerialization.

private static void assertSerialization(final DataTreeCandidate orig) throws IOException {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final DataOutput dos = new DataOutputStream(bos);
    try (NormalizedNodeDataOutput out = NormalizedNodeStreamVersion.current().newDataOutput(dos)) {
        DataTreeCandidateInputOutput.writeDataTreeCandidate(out, orig);
    }
    final DataTreeCandidate read = DataTreeCandidateInputOutput.readDataTreeCandidate(NormalizedNodeDataInput.newDataInput(new DataInputStream(new ByteArrayInputStream(bos.toByteArray()))));
    assertEquals(orig.getRootPath(), read.getRootPath());
    assertEqualMod(orig.getRootNode(), read.getRootNode());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataOutput(java.io.DataOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Example 7 with DataTreeCandidate

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

the class Bug3674Test method testDeleteOfNonExistingNode.

@Test
public void testDeleteOfNonExistingNode() throws DataValidationFailedException {
    final DataTreeModification mod = tree.takeSnapshot().newModification();
    mod.delete(TestModel.OUTER_LIST_PATH);
    mod.ready();
    final DataTreeCandidate candidate = tree.prepare(mod);
    final DataTreeCandidateNode root = candidate.getRootNode();
    assertEquals(ModificationType.UNMODIFIED, root.getModificationType());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) Test(org.junit.Test)

Example 8 with DataTreeCandidate

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

the class Bug4454Test method minMaxListDeleteTest.

@Test
public void minMaxListDeleteTest() throws DataValidationFailedException {
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "foo");
    final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
    mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar");
    final YangInstanceIdentifier minMaxLeafBar = MASTER_CONTAINER_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
    mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "baz");
    final YangInstanceIdentifier minMaxLeafBaz = MASTER_CONTAINER_PATH.node(MIN_MAX_LIST_QNAME).node(mapEntryPath2);
    modificationTree.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
    modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBar);
    modificationTree.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
    modificationTree.delete(minMaxLeafFoo);
    modificationTree.delete(minMaxLeafBar);
    modificationTree.delete(minMaxLeafBaz);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
    // Empty list should have disappeared, along with the container, as we are not enforcing root
    final NormalizedNode data = inMemoryDataTree.takeSnapshot().readNode(YangInstanceIdentifier.empty()).get();
    assertTrue(data instanceof ContainerNode);
    assertEquals(0, ((ContainerNode) data).size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 9 with DataTreeCandidate

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

the class Bug4454Test method minMaxLeafListPass.

@Test
public void minMaxLeafListPass() throws DataValidationFailedException {
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final NodeWithValue<?> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
    final NodeWithValue<?> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
    final LeafSetEntryNode<Object> barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(barPath).withValue("bar").build();
    final LeafSetEntryNode<Object> gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(gooPath).withValue("goo").build();
    final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)).withChildValue("foo").build();
    modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
    modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare1);
    DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
    DataTreeModification tempMod1 = test1.newModification();
    tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
    tempMod1.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
    tempMod1.ready();
    inMemoryDataTree.validate(tempMod1);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
    inMemoryDataTree.commit(prepare2);
    final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
    assertTrue(masterContainer.isPresent());
    final Optional<NormalizedNodeContainer<?>> leafList = ((DistinctNodeContainer) masterContainer.get()).findChildByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
    assertTrue(leafList.isPresent());
    assertEquals(3, leafList.get().size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DistinctNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NormalizedNodeContainer(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 10 with DataTreeCandidate

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

the class Bug4454Test method minMaxListDeleteWriteTest.

@Test
public void minMaxListDeleteWriteTest() throws DataValidationFailedException {
    final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification();
    Map<QName, Object> key = new HashMap<>();
    key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
    NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, key);
    final YangInstanceIdentifier minMaxLeafFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
    key.clear();
    key.put(MIN_MAX_KEY_LEAF_QNAME, "NON-EXISTING-LEAF");
    mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, key);
    final YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPath2).build();
    final Map<QName, Object> keyTemp = new HashMap<>();
    keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "baz");
    NodeIdentifierWithPredicates mapEntryPathTest = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, keyTemp);
    final YangInstanceIdentifier pathToBaz = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
    keyTemp.clear();
    keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "bar");
    mapEntryPathTest = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, keyTemp);
    final YangInstanceIdentifier pathToBar = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPathTest).node(MIN_MAX_VALUE_LEAF_QNAME).build();
    keyTemp.clear();
    keyTemp.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
    final NodeIdentifierWithPredicates mapEntryPathTestKey = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME, keyTemp);
    final YangInstanceIdentifier pathToKeyFoo = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME).node(mapEntryPathTestKey).node(MIN_MAX_KEY_LEAF_QNAME).build();
    final LeafNode<String> newNode = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test");
    final LeafNode<String> newNode1 = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test1");
    final LeafNode<String> newNode2 = ImmutableNodes.leafNode(MIN_MAX_VALUE_LEAF_QNAME, "test2");
    final LeafNode<String> newNodekey = ImmutableNodes.leafNode(MIN_MAX_KEY_LEAF_QNAME, "foo");
    assertFalse(inMemoryDataTree.toString().contains("list"));
    DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
    assertTrue(!minMaxListRead.isPresent());
    modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
    modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
    modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
    modificationTree1.merge(MIN_MAX_LIST_PATH, mapNodeBar);
    modificationTree1.merge(MIN_MAX_LIST_PATH, mapNodeBaz);
    modificationTree1.write(pathToKeyFoo, newNodekey);
    modificationTree1.write(pathToBaz, newNode2);
    modificationTree1.write(pathToBaz, newNode1);
    modificationTree1.write(pathToBaz, newNode);
    modificationTree1.delete(minMaxLeafFoo);
    modificationTree1.delete(minMaxLeafNel);
    modificationTree1.ready();
    inMemoryDataTree.validate(modificationTree1);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree1);
    inMemoryDataTree.commit(prepare);
    DataTreeSnapshot test = inMemoryDataTree.takeSnapshot();
    testLoop(test, "bar", "test");
    DataTreeModification tempMod = test.newModification();
    tempMod.write(pathToBaz, newNode2);
    tempMod.write(pathToBaz, newNode1);
    tempMod.merge(pathToBaz, newNode2);
    tempMod.write(pathToBaz, newNode1);
    tempMod.ready();
    inMemoryDataTree.validate(tempMod);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(tempMod);
    inMemoryDataTree.commit(prepare1);
    DataTreeSnapshot test1 = inMemoryDataTree.takeSnapshot();
    testLoop(test1, "bar", "test1");
    DataTreeModification tempMod1 = test1.newModification();
    tempMod1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
    tempMod1.ready();
    inMemoryDataTree.validate(tempMod1);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(tempMod1);
    inMemoryDataTree.commit(prepare2);
    DataTreeSnapshot test2 = inMemoryDataTree.takeSnapshot();
    minMaxListRead = test2.readNode(MIN_MAX_LIST_PATH);
    assertTrue(minMaxListRead.isPresent());
    assertEquals(3, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
    DataTreeModification tempMod2 = test2.newModification();
    tempMod2.write(MIN_MAX_LIST_PATH, mapNodeBaz);
    tempMod2.write(pathToBaz, newNode2);
    tempMod2.ready();
    inMemoryDataTree.validate(tempMod2);
    final DataTreeCandidate prepare3 = inMemoryDataTree.prepare(tempMod2);
    inMemoryDataTree.commit(prepare3);
    DataTreeSnapshot test3 = inMemoryDataTree.takeSnapshot();
    minMaxListRead = test3.readNode(MIN_MAX_LIST_PATH);
    assertTrue(minMaxListRead.isPresent());
    assertEquals(1, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
    assertThat(minMaxListRead.get().body().toString(), containsString("test2"));
    DataTreeModification tempMod3 = test3.newModification();
    tempMod3.merge(MIN_MAX_LIST_PATH, mapNodeBar);
    tempMod3.merge(pathToBar, newNode1);
    tempMod3.ready();
    inMemoryDataTree.validate(tempMod3);
    final DataTreeCandidate prepare4 = inMemoryDataTree.prepare(tempMod3);
    inMemoryDataTree.commit(prepare4);
    DataTreeSnapshot test4 = inMemoryDataTree.takeSnapshot();
    testLoop(test4, "test1", "test2");
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)181 Test (org.junit.Test)147 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)102 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)66 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)41 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)38 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)36 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)26 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)25 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)22 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)13 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException)8 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataTreeChangeService (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService)6 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)6 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)6 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)5 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)5