Search in sources :

Example 96 with DataTreeModification

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

the class YT776Test method testDisappearInChoice.

@Test
public void testDisappearInChoice() throws DataValidationFailedException {
    DataTreeModification mod = dataTree.takeSnapshot().newModification();
    // Initialize choice with list
    mod.write(YangInstanceIdentifier.create(BOX), containerBuilder().withNodeIdentifier(BOX).withChild(choiceBuilder().withNodeIdentifier(ANY_OF).withChild(mapBuilder().withNodeIdentifier(SOME_LIST_ID).withChild(mapEntryBuilder().withNodeIdentifier(SOME_LIST_ITEM).withChild(leafBuilder().withNodeIdentifier(SOME_LEAF_ID).withValue("foo").build()).build()).build()).build()).build());
    commit(mod);
    // Now delete the single item, causing the list to fizzle, while creating the alterinative case
    mod = dataTree.takeSnapshot().newModification();
    mod.delete(YangInstanceIdentifier.create(BOX, ANY_OF, SOME_LIST_ID, SOME_LIST_ITEM));
    mod.write(YangInstanceIdentifier.create(BOX, ANY_OF, SOME_LEAF_ID), leafBuilder().withNodeIdentifier(SOME_LEAF_ID).withValue("foo").build());
    commit(mod);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) Test(org.junit.Test)

Example 97 with DataTreeModification

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

the class YT776Test method testEmptyAndMergeOneWithListTouched.

@Test
public void testEmptyAndMergeOneWithListTouched() throws DataValidationFailedException {
    final DataTreeModification mod = dataTree.takeSnapshot().newModification();
    mod.write(YangInstanceIdentifier.create(BOX), containerBuilder().withNodeIdentifier(BOX).withChild(mapBuilder().withNodeIdentifier(OBJECT_LIST).addChild(mapEntryBuilder().withNodeIdentifier(OBJECT_ITEM).withChild(OBJECT_ID_LEAF).build()).build()).build());
    mod.merge(YangInstanceIdentifier.create(BOX), containerBuilder().withNodeIdentifier(BOX).withChild(mapBuilder().withNodeIdentifier(OBJECT_LIST).addChild(mapEntryBuilder().withNodeIdentifier(OBJECT_ITEM).withChild(OBJECT_ID_LEAF).withChild(leafSetBuilder().withNodeIdentifier(ATTRIBUTES).withChildValue("object1").build()).build()).build()).build());
    mod.delete(YangInstanceIdentifier.create(BOX, OBJECT_LIST, OBJECT_ITEM, NESTED_LIST, NESTED_ITEM));
    commit(mod);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) Test(org.junit.Test)

Example 98 with DataTreeModification

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

the class YT776Test method testEmptyAndMergeOne.

@Test
public void testEmptyAndMergeOne() throws DataValidationFailedException {
    final DataTreeModification mod = dataTree.takeSnapshot().newModification();
    mod.write(YangInstanceIdentifier.create(BOX), containerBuilder().withNodeIdentifier(BOX).withChild(mapBuilder().withNodeIdentifier(OBJECT_LIST).addChild(mapEntryBuilder().withNodeIdentifier(OBJECT_ITEM).withChild(OBJECT_ID_LEAF).build()).build()).build());
    mod.merge(YangInstanceIdentifier.create(BOX), containerBuilder().withNodeIdentifier(BOX).withChild(mapBuilder().withNodeIdentifier(OBJECT_LIST).addChild(mapEntryBuilder().withNodeIdentifier(OBJECT_ITEM).withChild(OBJECT_ID_LEAF).withChild(leafSetBuilder().withNodeIdentifier(ATTRIBUTES).withChildValue("object1").build()).build()).build()).build());
    commit(mod);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) Test(org.junit.Test)

Example 99 with DataTreeModification

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

the class YT776Test method testEmptyAttributes.

@Test
public void testEmptyAttributes() throws DataValidationFailedException {
    final DataTreeModification mod = write(containerBuilder().withNodeIdentifier(BOX).withChild(mapBuilder().withNodeIdentifier(OBJECT_LIST).addChild(mapEntryBuilder().withNodeIdentifier(OBJECT_ITEM).withChild(OBJECT_ID_LEAF).withChild(leafSetBuilder().withNodeIdentifier(ATTRIBUTES).build()).build()).build()).build());
    final IllegalArgumentException ex = assertThrows(MinMaxElementsValidationFailedException.class, mod::ready);
    assertEquals("(yt776)attributes does not have enough elements (0), needs at least 1", ex.getMessage());
    assertTooFewElements(ex);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) Test(org.junit.Test)

Example 100 with DataTreeModification

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

the class Bug8713Test method dataTreeCanditateValidationTest.

@Test
public void dataTreeCanditateValidationTest() throws Exception {
    final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/bug8713/");
    final LeafRefContext rootLeafRefContext = LeafRefContext.create(context);
    final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
    final ContainerNode root = createRootContainer();
    final YangInstanceIdentifier rootPath = YangInstanceIdentifier.of(foo("root"));
    final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
    writeModification.write(rootPath, root);
    writeModification.ready();
    final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(writeModification);
    LeafRefValidation.validate(writeContributorsCandidate, rootLeafRefContext);
    inMemoryDataTree.commit(writeContributorsCandidate);
}
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) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) 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