Search in sources :

Example 26 with DataTree

use of org.opendaylight.yangtools.yang.data.tree.api.DataTree in project yangtools by opendaylight.

the class Bug5968Test method writeInvalidMapTest.

@Test
public void writeInvalidMapTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    writeMap(modificationTree, true);
    try {
        modificationTree.ready();
        inMemoryDataTree.validate(modificationTree);
        final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
        inMemoryDataTree.commit(prepare);
        fail("Should fail due to missing mandatory leaf.");
    } catch (final IllegalArgumentException e) {
        assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=1}] is " + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
    }
}
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) Test(org.junit.Test)

Example 27 with DataTree

use of org.opendaylight.yangtools.yang.data.tree.api.DataTree in project yangtools by opendaylight.

the class Bug5968Test method writeValidContainerTest.

@Test
public void writeValidContainerTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final SystemMapNode myList = createMap(false);
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(YangInstanceIdentifier.of(ROOT), root.build());
    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) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test)

Example 28 with DataTree

use of org.opendaylight.yangtools.yang.data.tree.api.DataTree in project yangtools by opendaylight.

the class Bug5968Test method writeValidMapEntryTest.

@Test
public void writeValidMapEntryTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    writeMapEntry(modificationTree, "1", "mandatory-value", "common-value");
    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) Test(org.junit.Test)

Example 29 with DataTree

use of org.opendaylight.yangtools.yang.data.tree.api.DataTree in project yangtools by opendaylight.

the class Bug5968Test method writeValidMapTest.

@Test
public void writeValidMapTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    writeMap(modificationTree, false);
    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) Test(org.junit.Test)

Example 30 with DataTree

use of org.opendaylight.yangtools.yang.data.tree.api.DataTree in project yangtools by opendaylight.

the class CaseAugmentTest method testWriteAugment.

@Test
public void testWriteAugment() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = initDataTree();
    AugmentationNode augmentationNode = Builders.augmentationBuilder().withNodeIdentifier(AUGMENT_ID).withChild(leafNode(C1L2_QNAME, "leaf-value")).build();
    final ContainerNode container = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(Builders.choiceBuilder().withNodeIdentifier(CHOICE_ID).withChild(augmentationNode).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);
}
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) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) 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