Search in sources :

Example 11 with DataTreeCandidate

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

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

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

Example 14 with DataTreeCandidate

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

the class Bug5968MergeTest method mergeValidMapTest.

@Test
public void mergeValidMapTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    mergeMap(modificationTree, false);
    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 DataTreeCandidate

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

the class Bug5968MergeTest method invalidMultiStepsMergeTest.

@Test
public void invalidMultiStepsMergeTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.merge(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createEmptyMapEntryBuilder("1").build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntry("1", "common-value"));
    try {
        modificationTree.ready();
        inMemoryDataTree.validate(modificationTree);
        final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
        inMemoryDataTree.commit(prepare);
        fail("Should fail due to missing mandatory leaf.");
    } catch (final IllegalArgumentException e) {
        assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=1}] is " + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
    }
}
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)

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