use of org.opendaylight.yangtools.yang.data.tree.api.DataTree 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.DataTree in project yangtools by opendaylight.
the class MapEntryRootTest method testMapEntryRoot.
@Test
public void testMapEntryRoot() {
final DataTreeConfiguration treeConfig = DataTreeConfiguration.builder(TreeType.OPERATIONAL).setRootPath(TestModel.TEST_PATH.node(TestModel.OUTER_LIST_QNAME).node(NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, (short) 12))).build();
final DataTree dataTree = new InMemoryDataTreeFactory().create(treeConfig, SCHEMA_CONTEXT);
assertTrue(dataTree instanceof InMemoryDataTree);
final InMemoryDataTree imdt = (InMemoryDataTree) dataTree;
final InMemoryDataTreeModification mod = imdt.takeSnapshot().newModification();
final ModificationApplyOperation strategy = mod.getStrategy();
assertThat(strategy, instanceOf(MapEntryModificationStrategy.class));
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTree in project yangtools by opendaylight.
the class DataTreeCandidatesTest method testRootedCandidate.
@Test
public void testRootedCandidate() throws DataValidationFailedException {
final DataTree innerDataTree = new InMemoryDataTreeFactory().create(new DataTreeConfiguration.Builder(TreeType.OPERATIONAL).setMandatoryNodesValidation(true).setRootPath(TestModel.INNER_CONTAINER_PATH).setUniqueIndexes(true).build(), SCHEMA_CONTEXT);
final LeafNode<String> leaf = ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.VALUE_QNAME)).withValue("testing-value").build();
final DataTreeModification modification = innerDataTree.takeSnapshot().newModification();
modification.write(TestModel.VALUE_PATH, leaf);
modification.ready();
dataTree.validate(modification);
final DataTreeCandidate candidate = dataTree.prepare(modification);
dataTree.commit(candidate);
final DataTreeModification newModification = dataTree.takeSnapshot().newModification();
final DataTreeCandidate newCandidate = DataTreeCandidates.newDataTreeCandidate(TestModel.INNER_CONTAINER_PATH, candidate.getRootNode());
try {
// lets see if getting the identifier of the root node throws an exception
newCandidate.getRootNode().getIdentifier();
fail();
} catch (IllegalStateException e) {
LOG.debug("Cannot get identifier of root node candidate which is correct", e);
}
// lets see if we can apply this rooted candidate to a new dataTree
DataTreeCandidates.applyToModification(newModification, newCandidate);
final LeafNode<?> readLeaf = (LeafNode<?>) newModification.readNode(TestModel.INNER_VALUE_PATH).get();
assertEquals(readLeaf, leaf);
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTree in project yangtools by opendaylight.
the class ConfigStatementValidationTest method testOnDataCaseLeafFail.
@Test(expected = SchemaValidationFailedException.class)
public void testOnDataCaseLeafFail() throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id);
final ChoiceNode choice1 = Builders.choiceBuilder().withNodeIdentifier(choice1Id).withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case1-leaf1"), "leaf-value")).build();
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(ii, choice1);
modificationTree.ready();
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTree in project yangtools by opendaylight.
the class ConfigStatementValidationTest method testOnDataFail.
@Test(expected = SchemaValidationFailedException.class)
public void testOnDataFail() throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(TestModel.TEST_PATH, createFooTestContainerNode());
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
}
Aggregations