Search in sources :

Example 6 with DataTree

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

the class Bug5968MergeTest method validMapEntryMultiCommitMergeTest.

@Test
public void validMapEntryMultiCommitMergeTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createEmptyMapEntryBuilder("1").build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntryM("1", "mandatory-value"));
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
    final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree2.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntry("1", "common-value"));
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree2);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
    inMemoryDataTree.commit(prepare2);
}
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 7 with DataTree

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

the class Bug5968MergeTest method validMultiStepsMergeTest.

@Test
public void validMultiStepsMergeTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.merge(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createEmptyMapEntryBuilder("1").build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntry("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 8 with DataTree

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

the class Bug5968MergeTest method validMapEntryMultiCommitMergeTest2.

/*
     * This test consists of two transactions (i.e. data tree modifications) on
     * empty data tree. The first one writes mandatory data and second one
     * writes common data without any mandatory data.
     */
@Test
public void validMapEntryMultiCommitMergeTest2() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMapBuilder().build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createEmptyMapEntryBuilder("1").build());
    modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntryM("1", "mandatory-value"));
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
    modificationTree2.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST).node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, "1"))), createMapEntry("1", "common-value"));
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree2);
    final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
    inMemoryDataTree.commit(prepare2);
}
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 9 with DataTree

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

the class MandatoryLeafTest method testDisabledValidation.

@Test
public void testDisabledValidation() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = initDataTree(false);
    final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
    final ContainerNode container = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(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()).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) Test(org.junit.Test)

Example 10 with DataTree

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

the class MandatoryLeafTest method testCorrectMandatoryLeafChoiceWrite.

@Test
public void testCorrectMandatoryLeafChoiceWrite() 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-leaf1"), "leaf-value")).withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf2"), "leaf-value2")).build()).build();
    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);
}
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)

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