Search in sources :

Example 11 with DataTreeModification

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

the class Bug4454Test method prepare.

@Before
public void prepare() throws DataValidationFailedException {
    inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, schemaContext);
    final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
    final DataTreeModification modificationTree = initialDataTreeSnapshot.newModification();
    modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME));
    modificationTree.ready();
    inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Before(org.junit.Before)

Example 12 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification 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)

Example 13 with DataTreeModification

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

the class Bug4454Test method minMaxListNoMinMaxDeleteTest.

@Test
public void minMaxListNoMinMaxDeleteTest() throws DataValidationFailedException {
    final MapEntryNode fooEntryNoMinMaxNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME, "foo");
    final SystemMapNode mapNode1 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME_NO_MINMAX)).withChild(fooEntryNoMinMaxNode).build();
    final DataTreeModification modificationTree = 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_NO_MINMAX, key);
    final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH.node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2);
    key.clear();
    key.put(MIN_MAX_KEY_LEAF_QNAME, "non-existing-leaf");
    mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
    YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2).build();
    modificationTree.write(MIN_MAX_LIST_NO_MINMAX_PATH, mapNode1);
    modificationTree.delete(minMaxLeafFoo);
    modificationTree.delete(minMaxLeafNel);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
    final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    final Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_NO_MINMAX_PATH);
    // Empty list should have disappeared
    assertFalse(minMaxListRead.isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) 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) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 14 with DataTreeModification

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

the class Bug5968MergeTest method mergeValidMapEntryTest.

@Test
public void mergeValidMapEntryTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    mergeMapEntry(modificationTree, "1", "mandatory-value", "common-value");
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) Test(org.junit.Test)

Example 15 with DataTreeModification

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

the class Bug5968MergeTest method initDataTree.

private static DataTree initDataTree(final EffectiveModelContext schemaContext, final boolean withMapNode) throws DataValidationFailedException {
    final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(ROOT));
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.merge(YangInstanceIdentifier.of(ROOT), withMapNode ? root.withChild(Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST)).build()).build() : root.build());
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
    return inMemoryDataTree;
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)

Aggregations

DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)162 Test (org.junit.Test)112 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)102 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)44 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)43 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)36 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)32 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)31 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)23 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)17 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)11 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException)10 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)9 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)9 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)7 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 Measurement (org.openjdk.jmh.annotations.Measurement)6 Warmup (org.openjdk.jmh.annotations.Warmup)6 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)5