Search in sources :

Example 6 with DataTreeSnapshot

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

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot 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 8 with DataTreeSnapshot

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot 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 9 with DataTreeSnapshot

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

the class ListConstraintsValidation method minMaxListTestPass.

@Test
public void minMaxListTestPass() throws DataValidationFailedException {
    final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "foo");
    final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME, "bar");
    final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME)).withChild(fooEntryNode).build();
    final MapNode mapNode2 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME)).withChild(barEntryNode).build();
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(MIN_MAX_LIST_PATH, mapNode1);
    modificationTree.merge(MIN_MAX_LIST_PATH, mapNode2);
    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_PATH);
    assertTrue(minMaxListRead.isPresent());
    assertEquals(2, ((NormalizedNodeContainer<?>) minMaxListRead.get()).size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 10 with DataTreeSnapshot

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

the class ListConstraintsValidation method unkeyedListTestPass.

@Test
public void unkeyedListTestPass() throws DataValidationFailedException {
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final UnkeyedListEntryNode foo = ImmutableUnkeyedListEntryNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LEAF_QNAME)).withChild(ImmutableNodes.leafNode(UNKEYED_LEAF_QNAME, "foo")).build();
    final List<UnkeyedListEntryNode> unkeyedEntries = new ArrayList<>();
    unkeyedEntries.add(foo);
    final UnkeyedListNode unkeyedListNode = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)).withValue(unkeyedEntries).build();
    modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME));
    modificationTree.merge(UNKEYED_LIST_PATH, unkeyedListNode);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare1);
    final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
    final Optional<NormalizedNode> unkeyedListRead = snapshotAfterCommit.readNode(UNKEYED_LIST_PATH);
    assertTrue(unkeyedListRead.isPresent());
    assertEquals(1, ((UnkeyedListNode) unkeyedListRead.get()).size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) Test(org.junit.Test)

Aggregations

DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)41 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)36 Test (org.junit.Test)30 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)25 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)18 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)11 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException)9 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)4 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)2 QName (org.opendaylight.yangtools.yang.common.QName)2 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)2 NodeWithValue (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)2 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)2 NormalizedNodeContainer (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer)2 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)2