use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project yangtools by opendaylight.
the class BuilderTest method immutableOrderedMapBuilderTest.
@Test
public void immutableOrderedMapBuilderTest() {
final LinkedList<MapEntryNode> mapEntryNodeColl = new LinkedList<>();
mapEntryNodeColl.add(LIST_MAIN_CHILD_3);
final Map<QName, Object> keys = new HashMap<>();
keys.put(LIST_MAIN_CHILD_QNAME_1, 1);
final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(LIST_MAIN, keys);
final UserMapNode orderedMapNodeCreateNull = ImmutableUserMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST).withChild(LIST_MAIN_CHILD_1).addChild(LIST_MAIN_CHILD_2).withValue(mapEntryNodeColl).build();
final UserMapNode orderedMapNodeCreateSize = ImmutableUserMapNodeBuilder.create(SIZE).withNodeIdentifier(NODE_IDENTIFIER_LIST).build();
final UserMapNode orderedMapNodeCreateNode = ImmutableUserMapNodeBuilder.create(orderedMapNodeCreateNull).removeChild(mapEntryPath).build();
final UserMapNode orderedMapNodeSchemaAware = ImmutableUserMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).withChild(LIST_MAIN_CHILD_1).build();
final UserMapNode orderedMapNodeSchemaAwareMapNodeConst = ImmutableUserMapNodeBuilder.create(getImmutableUserMapNode()).build();
assertEquals(SIZE, orderedMapNodeCreateNull.size());
assertEquals(orderedMapNodeCreateNode.size(), orderedMapNodeCreateNull.size() - 1);
assertEquals(NODE_IDENTIFIER_LIST, orderedMapNodeCreateSize.getIdentifier());
assertEquals(LIST_MAIN_CHILD_1, orderedMapNodeCreateNull.childAt(0));
assertEquals(SIZE, orderedMapNodeCreateNull.size());
assertEquals(orderedMapNodeSchemaAware.childAt(0), orderedMapNodeSchemaAwareMapNodeConst.childAt(0));
}
use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode 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;
}
use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project yangtools by opendaylight.
the class OrderingEqualityTest method testUserMap.
@Test
public void testUserMap() {
final UserMapNode firstMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).build();
final UserMapNode secondMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
assertEquals(firstMap.asMap(), secondMap.asMap());
assertFalse(firstMap.equals(secondMap));
assertFalse(secondMap.equals(firstMap));
final UserMapNode thirdMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
assertEquals(secondMap.asMap(), thirdMap.asMap());
assertFalse(firstMap.equals(thirdMap));
assertTrue(secondMap.equals(thirdMap));
assertArrayEquals(secondMap.body().toArray(), thirdMap.body().toArray());
assertEquals(secondMap.hashCode(), thirdMap.hashCode());
// Although this map looks as secondMap, it is not equal
final SystemMapNode systemMap = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
assertEquals(secondMap.asMap(), systemMap.asMap());
assertFalse(firstMap.equals(systemMap));
assertFalse(secondMap.equals(systemMap));
}
use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project yangtools by opendaylight.
the class SchemalessXMLStreamNormalizedNodeStreamWriterTest method buildOuterContainerNode.
private NormalizedNode buildOuterContainerNode() {
// my-container-1
MapNode 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(myUnkeyedList)).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 = ImmutableNodes.leafNode(myLeaf1, "value1");
SystemLeafSetNode<?> 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();
UserLeafSetNode<?> 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).build();
// .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;
}
use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project yangtools by opendaylight.
the class TreeNodeFactoryTest method testOrderedNodeContainer.
@Test
public void testOrderedNodeContainer() {
final UserMapNode data = Mockito.mock(UserMapNode.class);
final Version version = Version.initial();
final TreeNode node = TreeNode.of(data, version);
assertTrue(node instanceof SimpleContainerNode);
checkTreeNode(node, data, version);
}
Aggregations