use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate 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());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class ListConstraintsValidation method minMaxLeafListPass.
@Test
public void minMaxLeafListPass() throws DataValidationFailedException {
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
final NodeWithValue<Object> barPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "bar");
final NodeWithValue<Object> gooPath = new NodeWithValue<>(MIN_MAX_LIST_QNAME, "goo");
final LeafSetEntryNode<Object> barLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(barPath).withValue("bar").build();
final LeafSetEntryNode<Object> gooLeafSetEntry = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(gooPath).withValue("goo").build();
final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME)).withChildValue("foo").build();
modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
modificationTree.merge(MIN_MAX_LEAF_LIST_PATH.node(gooPath), gooLeafSetEntry);
modificationTree.delete(MIN_MAX_LEAF_LIST_PATH.node(gooPath));
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare1);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
assertTrue(masterContainer.isPresent());
final NormalizedNodeContainer<?> leafList = (NormalizedNodeContainer<?>) ((DistinctNodeContainer) masterContainer.get()).childByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
assertNotNull(leafList);
assertEquals(2, leafList.size());
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate 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.DataTreeCandidate 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.DataTreeCandidate 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;
}
}
Aggregations