Search in sources :

Example 11 with DataTree

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;
    }
}
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) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test)

Example 12 with DataTree

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

Example 13 with DataTree

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);
}
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 14 with DataTree

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();
}
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 15 with DataTree

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);
}
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

DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)45 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)43 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)41 Test (org.junit.Test)37 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)17 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)17 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)11 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)4 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)3 DataTreeConfiguration (org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration)2 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)1 InMemoryDataTree (org.opendaylight.yangtools.yang.data.tree.impl.InMemoryDataTree)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1