Search in sources :

Example 6 with AugmentationIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier in project controller by opendaylight.

the class NormalizedNodePrunerTest method testLeafNodePrunedWhenHasAugmentationParentAndSchemaMissing.

@Test
public void testLeafNodePrunedWhenHasAugmentationParentAndSchemaMissing() throws IOException {
    AugmentationIdentifier augId = new AugmentationIdentifier(Sets.newHashSet(TestModel.AUG_CONT_QNAME));
    NormalizedNodePruner pruner = prunerFullSchema(YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME).node(TestModel.AUGMENTED_LIST_QNAME).node(TestModel.AUGMENTED_LIST_QNAME).node(augId).build());
    LeafNode<Object> child = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.INVALID_QNAME)).withValue("test").build();
    NormalizedNode<?, ?> input = Builders.augmentationBuilder().withNodeIdentifier(augId).withChild(child).build();
    NormalizedNodeWriter.forStreamWriter(pruner).write(input);
    NormalizedNode<?, ?> actual = pruner.normalizedNode();
    assertEquals("normalizedNode", Builders.augmentationBuilder().withNodeIdentifier(augId).build(), actual);
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Test(org.junit.Test)

Example 7 with AugmentationIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier in project controller by opendaylight.

the class TestModel method createBaseTestContainerBuilder.

public static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createBaseTestContainerBuilder() {
    // Create a list of shoes
    // This is to test leaf list entry
    final LeafSetEntryNode<Object> nike = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(SHOE_QNAME, "nike")).withValue("nike").build();
    final LeafSetEntryNode<Object> puma = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(SHOE_QNAME, "puma")).withValue("puma").build();
    final LeafSetNode<Object> shoes = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(SHOE_QNAME)).withChild(nike).withChild(puma).build();
    // Test a leaf-list where each entry contains an identity
    final LeafSetEntryNode<Object> cap1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "capability"), DESC_QNAME)).withValue(DESC_QNAME).build();
    final LeafSetNode<Object> capabilities = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "capability"))).withChild(cap1).build();
    ContainerNode switchFeatures = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(SWITCH_FEATURES_QNAME)).withChild(capabilities).build();
    // Create a leaf list with numbers
    final LeafSetEntryNode<Object> five = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "number"), 5)).withValue(5).build();
    final LeafSetEntryNode<Object> fifteen = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(new NodeWithValue<>(QName.create(TEST_QNAME, "number"), 15)).withValue(15).build();
    final LeafSetNode<Object> numbers = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "number"))).withChild(five).withChild(fifteen).build();
    // Create augmentations
    MapEntryNode augMapEntry = createAugmentedListEntry(1, "First Test");
    // Create a bits leaf
    NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> myBits = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "my-bits"))).withValue(ImmutableSet.of("foo", "bar"));
    // Create unkeyed list entry
    UnkeyedListEntryNode unkeyedListEntry = Builders.unkeyedListEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(UNKEYED_LIST_QNAME)).withChild(ImmutableNodes.leafNode(NAME_QNAME, "unkeyed-entry-name")).build();
    // Create YangInstanceIdentifier with all path arg types.
    YangInstanceIdentifier instanceID = YangInstanceIdentifier.create(new NodeIdentifier(QName.create(TEST_QNAME, "qname")), new NodeIdentifierWithPredicates(QName.create(TEST_QNAME, "list-entry"), QName.create(TEST_QNAME, "key"), 10), new AugmentationIdentifier(ImmutableSet.of(QName.create(TEST_QNAME, "aug1"), QName.create(TEST_QNAME, "aug2"))), new NodeWithValue<>(QName.create(TEST_QNAME, "leaf-list-entry"), "foo"));
    Map<QName, Object> keyValues = new HashMap<>();
    keyValues.put(CHILDREN_QNAME, FIRST_CHILD_NAME);
    // Create the document
    return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(myBits.build()).withChild(ImmutableNodes.leafNode(DESC_QNAME, DESC)).withChild(ImmutableNodes.leafNode(BOOLEAN_LEAF_QNAME, ENABLED)).withChild(ImmutableNodes.leafNode(SHORT_LEAF_QNAME, SHORT_ID)).withChild(ImmutableNodes.leafNode(BYTE_LEAF_QNAME, BYTE_ID)).withChild(ImmutableNodes.leafNode(TestModel.BIGINTEGER_LEAF_QNAME, BigInteger.valueOf(100))).withChild(ImmutableNodes.leafNode(TestModel.BIGDECIMAL_LEAF_QNAME, BigDecimal.valueOf(1.2))).withChild(ImmutableNodes.leafNode(SOME_REF_QNAME, instanceID)).withChild(ImmutableNodes.leafNode(MYIDENTITY_QNAME, DESC_QNAME)).withChild(Builders.unkeyedListBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(UNKEYED_LIST_QNAME)).withChild(unkeyedListEntry).build()).withChild(Builders.choiceBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TWO_THREE_QNAME)).withChild(ImmutableNodes.leafNode(TWO_QNAME, "two")).build()).withChild(Builders.orderedMapBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ORDERED_LIST_QNAME)).withValue(ImmutableList.<MapEntryNode>builder().add(mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "1").build(), mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "2").build()).build()).build()).withChild(shoes).withChild(numbers).withChild(switchFeatures).withChild(mapNodeBuilder(AUGMENTED_LIST_QNAME).withChild(augMapEntry).build()).withChild(mapNodeBuilder(OUTER_LIST_QNAME).withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID)).withChild(BAR_NODE).build());
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Aggregations

AugmentationIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier)7 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)5 Test (org.junit.Test)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)3 AbstractSchemaAwareTest (org.opendaylight.controller.md.sal.binding.test.AbstractSchemaAwareTest)2 QName (org.opendaylight.yangtools.yang.common.QName)2 NodeWithValue (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)2 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)2 Sets (com.google.common.collect.Sets)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DOMSource (javax.xml.transform.dom.DOMSource)1 Assert (org.junit.Assert)1 Assert.assertEquals (org.junit.Assert.assertEquals)1