use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.
the class ListConstraintsValidation method unkeyedListTestFail.
@Test
public void unkeyedListTestFail() {
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 UnkeyedListEntryNode bar = ImmutableUnkeyedListEntryNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LEAF_QNAME)).withChild(ImmutableNodes.leafNode(UNKEYED_LEAF_QNAME, "bar")).build();
final List<UnkeyedListEntryNode> unkeyedEntries = new ArrayList<>();
unkeyedEntries.add(foo);
unkeyedEntries.add(bar);
final UnkeyedListNode unkeyedListNode = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)).withValue(unkeyedEntries).build();
modificationTree.write(UNKEYED_LIST_PATH, unkeyedListNode);
final MinMaxElementsValidationFailedException ex = assertThrows(MinMaxElementsValidationFailedException.class, () -> modificationTree.ready());
assertEquals("(urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?" + "revision=2015-02-02)unkeyed-list has too many elements (2), can have at most 1", ex.getMessage());
assertTooManyElements(ex);
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.
the class MandatoryLeafTest method testDisabledValidation.
@Test
public void testDisabledValidation() throws DataValidationFailedException {
final DataTree inMemoryDataTree = initDataTree(false);
final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
final ContainerNode container = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(Builders.choiceBuilder().withNodeIdentifier(choice1Id).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "case2-cont"))).withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf2"), "leaf-value2")).build()).build()).build();
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(TestModel.TEST_PATH, container);
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 MandatoryLeafTest method testCorrectMandatoryLeafChoiceWrite.
@Test
public void testCorrectMandatoryLeafChoiceWrite() throws DataValidationFailedException {
final DataTree inMemoryDataTree = initDataTree(true);
// Container write
final ContainerNode container = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build();
final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification();
modificationTree1.write(TestModel.TEST_PATH, container);
modificationTree1.ready();
inMemoryDataTree.validate(modificationTree1);
final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
inMemoryDataTree.commit(prepare1);
// Choice write
final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
final ChoiceNode choice = Builders.choiceBuilder().withNodeIdentifier(choice1Id).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "case2-cont"))).withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf1"), "leaf-value")).withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf2"), "leaf-value2")).build()).build();
final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
modificationTree2.write(TestModel.TEST_PATH.node(choice1Id), choice);
modificationTree2.ready();
inMemoryDataTree.validate(modificationTree2);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.
the class MandatoryLeafTest method testMandatoryLeafViolationChoiceWrite.
@Test(expected = IllegalArgumentException.class)
public void testMandatoryLeafViolationChoiceWrite() throws DataValidationFailedException {
final DataTree inMemoryDataTree = initDataTree(true);
// Container write
final ContainerNode container = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build();
final DataTreeModification modificationTree1 = inMemoryDataTree.takeSnapshot().newModification();
modificationTree1.write(TestModel.TEST_PATH, container);
modificationTree1.ready();
inMemoryDataTree.validate(modificationTree1);
final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
inMemoryDataTree.commit(prepare1);
// Choice write
final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
final ChoiceNode choice = Builders.choiceBuilder().withNodeIdentifier(choice1Id).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "case2-cont"))).withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf2"), "leaf-value2")).build()).build();
try {
final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
modificationTree2.write(TestModel.TEST_PATH.node(choice1Id), choice);
modificationTree2.ready();
inMemoryDataTree.validate(modificationTree2);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
} catch (final IllegalArgumentException e) {
assertEquals("Node (urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?" + "revision=2014-03-13)choice1 is missing mandatory descendant /(urn:opendaylight:params:xml:ns:" + "yang:controller:md:sal:dom:store:test?revision=2014-03-13)case2-cont/case2-leaf1", e.getMessage());
throw e;
}
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification in project yangtools by opendaylight.
the class ConcurrentTreeModificationTest method deleteWriteFooBar2ndLevelEmptyContainerTest.
@Test
public void deleteWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
initialDataTreeModification.ready();
inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification();
final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification();
modificationTree1.delete(TestModel.TEST_PATH);
modificationTree2.write(OUTER_LIST_2_PATH, BAR_NODE);
modificationTree1.ready();
modificationTree2.ready();
inMemoryDataTree.validate(modificationTree1);
final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
inMemoryDataTree.commit(prepare1);
try {
inMemoryDataTree.validate(modificationTree2);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
fail("Exception should have been thrown");
} catch (final ConflictingModificationAppliedException e) {
LOG.debug("Exception was thrown because path no longer exist in tree", e);
}
final DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent());
}
Aggregations