Search in sources :

Example 6 with InMemoryDataTreeFactory

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);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) DataTreeConfiguration(org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Test(org.junit.Test)

Example 7 with InMemoryDataTreeFactory

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));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Before(org.junit.Before)

Example 8 with InMemoryDataTreeFactory

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);
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Before(org.junit.Before)

Example 9 with InMemoryDataTreeFactory

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();
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Test(org.junit.Test)

Example 10 with InMemoryDataTreeFactory

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);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Test(org.junit.Test)

Aggregations

InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)21 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)17 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)13 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)11 Test (org.junit.Test)8 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)8 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)6 Before (org.junit.Before)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 BeforeClass (org.junit.BeforeClass)3 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)3 Module (org.opendaylight.yangtools.yang.model.api.Module)3 DataTreeConfiguration (org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration)2 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)1 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)1 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)1 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)1 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)1