Search in sources :

Example 26 with DataTreeModification

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

the class ListConstraintsValidation method unkeyedListTestFail.

@Test
public void unkeyedListTestFail() {
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final UnkeyedListEntryNode foo = ImmutableUnkeyedListEntryNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LEAF_QNAME)).withChild(ImmutableNodes.leafNode(UNKEYED_LEAF_QNAME, "foo")).build();
    final UnkeyedListEntryNode bar = ImmutableUnkeyedListEntryNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LEAF_QNAME)).withChild(ImmutableNodes.leafNode(UNKEYED_LEAF_QNAME, "bar")).build();
    final List<UnkeyedListEntryNode> unkeyedEntries = new ArrayList<>();
    unkeyedEntries.add(foo);
    unkeyedEntries.add(bar);
    final UnkeyedListNode unkeyedListNode = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)).withValue(unkeyedEntries).build();
    modificationTree.write(UNKEYED_LIST_PATH, unkeyedListNode);
    final MinMaxElementsValidationFailedException ex = assertThrows(MinMaxElementsValidationFailedException.class, () -> modificationTree.ready());
    assertEquals("(urn:opendaylight:params:xml:ns:yang:list-constraints-validation-test-model?" + "revision=2015-02-02)unkeyed-list has too many elements (2), can have at most 1", ex.getMessage());
    assertTooManyElements(ex);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) Test(org.junit.Test)

Example 27 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification 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 28 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification 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)

Example 29 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification 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 30 with DataTreeModification

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

the class ConcurrentTreeModificationTest method deleteWriteFooBar2ndLevelEmptyContainerTest.

@Test
public void deleteWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
    final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
    initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
    initialDataTreeModification.ready();
    inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
    final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
    final DataTreeModification modificationTree1 = initialDataTreeSnapshot.newModification();
    final DataTreeModification modificationTree2 = initialDataTreeSnapshot.newModification();
    modificationTree1.delete(TestModel.TEST_PATH);
    modificationTree2.write(OUTER_LIST_2_PATH, BAR_NODE);
    modificationTree1.ready();
    modificationTree2.ready();
    inMemoryDataTree.validate(modificationTree1);
    final DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
    inMemoryDataTree.commit(prepare1);
    try {
        inMemoryDataTree.validate(modificationTree2);
        final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
        inMemoryDataTree.commit(prepare2);
        fail("Exception should have been thrown");
    } catch (final ConflictingModificationAppliedException e) {
        LOG.debug("Exception was thrown because path no longer exist in tree", e);
    }
    final DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) Test(org.junit.Test)

Aggregations

DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)162 Test (org.junit.Test)112 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)102 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)44 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)43 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)36 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)32 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)31 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)23 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)17 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)11 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException)10 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)9 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)9 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)7 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 Measurement (org.openjdk.jmh.annotations.Measurement)6 Warmup (org.openjdk.jmh.annotations.Warmup)6 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)5