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));
}
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");
}
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());
}
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);
}
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;
}
Aggregations