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