use of org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory 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.impl.di.InMemoryDataTreeFactory in project yangtools by opendaylight.
the class ListConstraintsValidation method prepare.
@Before
public void prepare() throws DataValidationFailedException {
inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, schemaContext);
final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
final DataTreeModification modificationTree = initialDataTreeSnapshot.newModification();
modificationTree.write(MASTER_CONTAINER_PATH, ImmutableNodes.containerNode(MASTER_CONTAINER_QNAME));
modificationTree.ready();
inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree));
}
use of org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory in project yangtools by opendaylight.
the class YT892Test method setup.
@Before
public void setup() {
final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/yt892");
leafRefContext = LeafRefContext.create(schemaContext);
dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
}
use of org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory 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.impl.di.InMemoryDataTreeFactory 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