use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5830Test method initDataTree.
private static DataTree initDataTree(final EffectiveModelContext schemaContext) throws DataValidationFailedException {
DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
final SystemMapNode taskNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(TASK)).build();
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(YangInstanceIdentifier.of(TASK_CONTAINER).node(TASK), taskNode);
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
return inMemoryDataTree;
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5830Test method testMandatoryLeaf2IsPresent.
private static void testMandatoryLeaf2IsPresent(final EffectiveModelContext schemaContext, final boolean withPresenceContianer) throws DataValidationFailedException {
final DataTree inMemoryDataTree = initDataTree(schemaContext);
final MapEntryNode taskEntryNode = Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(TASK, ImmutableMap.of(TASK_ID, "123"))).withChild(ImmutableNodes.leafNode(TASK_ID, "123")).withChild(ImmutableNodes.leafNode(TASK_MANDATORY_LEAF, "mandatory data")).withChild(createTaskDataMultipleContainer(withPresenceContianer)).build();
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(YangInstanceIdentifier.of(TASK_CONTAINER).node(TASK).node(NodeIdentifierWithPredicates.of(TASK, ImmutableMap.of(TASK_ID, "123"))), taskEntryNode);
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5968Test method initDataTree.
private static DataTree initDataTree(final EffectiveModelContext schemaContext, final boolean withMapNode) throws DataValidationFailedException {
final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(ROOT));
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(YangInstanceIdentifier.of(ROOT), withMapNode ? root.withChild(Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST)).build()).build() : root.build());
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
return inMemoryDataTree;
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5968Test method writeInvalidMapEntryTest.
@Test
public void writeInvalidMapEntryTest() throws DataValidationFailedException {
final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
writeMapEntry(modificationTree, "1", null, "common-value");
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());
}
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate in project yangtools by opendaylight.
the class Bug5968Test method writeInvalidContainerTest.
@Test
public void writeInvalidContainerTest() throws DataValidationFailedException {
final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final SystemMapNode myList = createMap(true);
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());
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());
}
}
Aggregations