use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5968MergeTest method mergeInvalidMapEntryTest.
@Test
public void mergeInvalidMapEntryTest() throws DataValidationFailedException {
final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
mergeMapEntry(modificationTree, "1", null, "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());
}
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5968MergeTest method validMapEntryMultiCommitMergeTest.
@Test
public void validMapEntryMultiCommitMergeTest() throws DataValidationFailedException {
final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(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"))), createMapEntryM("1", "mandatory-value"));
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
modificationTree2.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntry("1", "common-value"));
modificationTree2.ready();
inMemoryDataTree.validate(modificationTree2);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5968MergeTest method validMultiStepsMergeTest.
@Test
public void validMultiStepsMergeTest() 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", "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.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5968MergeTest method validMapEntryMultiCommitMergeTest2.
/*
* This test consists of two transactions (i.e. data tree modifications) on
* empty data tree. The first one writes mandatory data and second one
* writes common data without any mandatory data.
*/
@Test
public void validMapEntryMultiCommitMergeTest2() throws DataValidationFailedException {
final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(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"))), createMapEntryM("1", "mandatory-value"));
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
modificationTree2.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntry("1", "common-value"));
modificationTree2.ready();
inMemoryDataTree.validate(modificationTree2);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate 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());
}
Aggregations