use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class Bug5968MergeTest method mergeInvalidContainerTest.
@Test
public void mergeInvalidContainerTest() 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.merge(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());
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class Bug2690Test method testWriteMerge1.
@Test
public void testWriteMerge1() throws DataValidationFailedException {
final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
final SystemMapNode mapNode1 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).withChild(fooEntryNode).build();
final SystemMapNode mapNode2 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).withChild(barEntryNode).build();
final ContainerNode cont1 = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(mapNode1).build();
final ContainerNode cont2 = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(mapNode2).build();
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(TestModel.TEST_PATH, cont1);
modificationTree.merge(TestModel.TEST_PATH, cont2);
commit(modificationTree);
final DataTreeSnapshot snapshotAfterTx = inMemoryDataTree.takeSnapshot();
final DataTreeModification modificationAfterTx = snapshotAfterTx.newModification();
final Optional<NormalizedNode> readNode = modificationAfterTx.readNode(TestModel.OUTER_LIST_PATH);
assertTrue(readNode.isPresent());
assertEquals(2, ((NormalizedNodeContainer<?>) readNode.get()).size());
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class Bug4295Test method firstModification.
private void firstModification() throws DataValidationFailedException {
/* MERGE */
SystemMapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList)).withChild(createOuterListEntry("1", "o-1")).withChild(createOuterListEntry("2", "o-2")).withChild(createOuterListEntry("3", "o-3")).build();
ContainerNode rootContainerNode = createRootContainerBuilder().withChild(createSubRootContainerBuilder().withChild(outerListNode).build()).build();
YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
modification.merge(path, rootContainerNode);
/* WRITE INNER LIST WITH ENTRIES*/
SystemMapNode innerListNode = createInnerListBuilder().withChild(createInnerListEntry("a", "i-a")).withChild(createInnerListEntry("b", "i-b")).build();
path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2")).node(innerList);
modification.write(path, innerListNode);
/* COMMIT */
modification.ready();
inMemoryDataTree.validate(modification);
inMemoryDataTree.commit(inMemoryDataTree.prepare(modification));
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class BuilderTest method immutableMapNodeBuilderTest.
@Test
public void immutableMapNodeBuilderTest() {
final LinkedList<MapEntryNode> mapEntryNodeColl = new LinkedList<>();
mapEntryNodeColl.add(LIST_MAIN_CHILD_3);
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> collectionNodeBuilder = ImmutableMapNodeBuilder.create(1);
assertNotNull(collectionNodeBuilder);
collectionNodeBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST);
collectionNodeBuilder.withValue(mapEntryNodeColl);
final SystemMapNode mapNode = collectionNodeBuilder.build();
assertNotNull(Builders.mapBuilder(mapNode));
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class ImmutableNormalizedNodeStreamWriterTest method buildOuterContainerNode.
private NormalizedNode buildOuterContainerNode() {
// my-container-1
SystemMapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myKeyedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "listkeyvalue1")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1)).withValue("listleafvalue1").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2)).withValue("listleafvalue2").build()).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "listkeyvalue2")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1)).withValue("listleafvalue12").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2)).withValue("listleafvalue22").build()).build()).build();
UserMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(myOrderedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue1")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList1)).withValue("olistleafvalue1").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList2)).withValue("olistleafvalue2").build()).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue2")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList1)).withValue("olistleafvalue12").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList2)).withValue("olistleafvalue22").build()).build()).build();
final UnkeyedListEntryNode unkeyedListEntry = Builders.unkeyedListEntryBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInUnkeyedList)).withChild(ImmutableNodes.leafNode(myLeafInUnkeyedList, "foo")).build();
final List<UnkeyedListEntryNode> unkeyedListEntries = new ArrayList<>();
unkeyedListEntries.add(unkeyedListEntry);
UnkeyedListNode myUnkeyedListNode = Builders.unkeyedListBuilder().withNodeIdentifier(new NodeIdentifier(myUnkeyedList)).withValue(unkeyedListEntries).build();
LeafNode<?> myLeaf1Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf1)).withValue("value1").build();
LeafSetNode<?> myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(myLeafList)).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myLeafList, "lflvalue1")).withValue("lflvalue1").build()).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myLeafList, "lflvalue2")).withValue("lflvalue2").build()).build();
LeafSetNode<?> myOrderedLeafListNode = Builders.orderedLeafSetBuilder().withNodeIdentifier(new NodeIdentifier(myOrderedLeafList)).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myOrderedLeafList, "olflvalue1")).withValue("olflvalue1").build()).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myOrderedLeafList, "olflvalue2")).withValue("olflvalue2").build()).build();
ContainerNode myContainer1Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer1)).withChild(myKeyedListNode).withChild(myOrderedListNode).withChild(myUnkeyedListNode).withChild(myLeaf1Node).withChild(myLeafListNode).withChild(myOrderedLeafListNode).build();
// my-container-2
ContainerNode innerContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(innerContainer)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf2)).withValue("value2").build()).build();
LeafNode<?> myLeaf3Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf3)).withValue("value3").build();
ChoiceNode myChoiceNode = Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(myChoice)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInCase2)).withValue("case2value").build()).build();
DOMSourceAnyxmlNode myAnyxmlNode = Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(myAnyxml)).withValue(anyxmlDomSource).build();
ContainerNode myContainer2Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer2)).withChild(innerContainerNode).withChild(myLeaf3Node).withChild(myChoiceNode).withChild(myAnyxmlNode).build();
// my-container-3
Map<QName, Object> keys = new HashMap<>();
keys.put(myFirstKeyLeaf, "listkeyvalue1");
keys.put(mySecondKeyLeaf, "listkeyvalue2");
MapNode myDoublyKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myDoublyKeyedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myDoublyKeyedList, keys)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList3)).withValue("listleafvalue1").build()).build()).build();
AugmentationNode myDoublyKeyedListAugNode = Builders.augmentationBuilder().withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(myDoublyKeyedList))).withChild(myDoublyKeyedListNode).build();
ContainerNode myContainer3Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer3)).withChild(myDoublyKeyedListAugNode).build();
AugmentationNode myContainer3AugNode = Builders.augmentationBuilder().withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(myContainer3))).withChild(myContainer3Node).build();
ContainerNode outerContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(outerContainer)).withChild(myContainer1Node).withChild(myContainer2Node).withChild(myContainer3AugNode).build();
return outerContainerNode;
}
Aggregations