Search in sources :

Example 1 with AugmentationIdentifier

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

the class NormalizedNodePrunerTest method countNodes.

private static int countNodes(final NormalizedNode<?, ?> normalizedNode, final String namespaceFilter) {
    if (normalizedNode == null) {
        return 0;
    }
    final AtomicInteger count = new AtomicInteger();
    new NormalizedNodeNavigator((level, parentPath, normalizedNode1) -> {
        if (!(normalizedNode1.getIdentifier() instanceof AugmentationIdentifier)) {
            if (normalizedNode1.getIdentifier().getNodeType().getNamespace().toString().contains(namespaceFilter)) {
                count.incrementAndGet();
            }
        }
    }).navigate(YangInstanceIdentifier.EMPTY.toString(), normalizedNode);
    return count.get();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) AnyXmlNode(org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode) MockitoAnnotations(org.mockito.MockitoAnnotations) TestModel(org.opendaylight.controller.cluster.datastore.util.TestModel) NormalizedNodeWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) ImmutableLeafSetNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder) ImmutableNodes.mapEntry(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ImmutableLeafSetEntryNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder) NormalizedNodeNavigator(org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeNavigator) Builders(org.opendaylight.yangtools.yang.data.impl.schema.Builders) Before(org.junit.Before) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ImmutableNodes.mapNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder) Assert.assertTrue(org.junit.Assert.assertTrue) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) IOException(java.io.IOException) Test(org.junit.Test) Sets(com.google.common.collect.Sets) ImmutableNodes.mapEntryBuilder(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder) Assert.assertNull(org.junit.Assert.assertNull) ImmutableNodes(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Mockito.mock(org.mockito.Mockito.mock) NormalizedNodeNavigator(org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeNavigator) AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with AugmentationIdentifier

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

the class TestModel method createAugmentedListEntry.

public static MapEntryNode createAugmentedListEntry(final int id, final String name) {
    Set<QName> childAugmentations = new HashSet<>();
    childAugmentations.add(AUG_CONT_QNAME);
    ContainerNode augCont = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(AUG_CONT_QNAME)).withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name)).build();
    final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(childAugmentations);
    final AugmentationNode augmentationNode = Builders.augmentationBuilder().withNodeIdentifier(augmentationIdentifier).withChild(augCont).build();
    return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(AUGMENTED_LIST_QNAME, ID_QNAME, id)).withChild(ImmutableNodes.leafNode(ID_QNAME, id)).withChild(augmentationNode).build();
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) HashSet(java.util.HashSet)

Example 3 with AugmentationIdentifier

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

the class BindingNormalizedCodecTest method testComplexAugmentationSerialization.

@Test
public void testComplexAugmentationSerialization() {
    this.codec.onGlobalContextUpdated(this.context);
    final PathArgument lastArg = this.codec.toYangInstanceIdentifier(BA_TREE_COMPLEX_USES).getLastPathArgument();
    assertTrue(lastArg instanceof AugmentationIdentifier);
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) AbstractSchemaAwareTest(org.opendaylight.controller.md.sal.binding.test.AbstractSchemaAwareTest) Test(org.junit.Test)

Example 4 with AugmentationIdentifier

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

the class AbstractNormalizedNodeDataOutput method writePathArgument.

@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The casts in the switch clauses are indirectly confirmed via the determination of 'type'.")
@Override
public void writePathArgument(final PathArgument pathArgument) throws IOException {
    byte type = PathArgumentTypes.getSerializablePathArgumentType(pathArgument);
    output.writeByte(type);
    switch(type) {
        case PathArgumentTypes.NODE_IDENTIFIER:
            NodeIdentifier nodeIdentifier = (NodeIdentifier) pathArgument;
            writeQName(nodeIdentifier.getNodeType());
            break;
        case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES:
            NodeIdentifierWithPredicates nodeIdentifierWithPredicates = (NodeIdentifierWithPredicates) pathArgument;
            writeQName(nodeIdentifierWithPredicates.getNodeType());
            writeKeyValueMap(nodeIdentifierWithPredicates.getKeyValues());
            break;
        case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE:
            NodeWithValue<?> nodeWithValue = (NodeWithValue<?>) pathArgument;
            writeQName(nodeWithValue.getNodeType());
            writeObject(nodeWithValue.getValue());
            break;
        case PathArgumentTypes.AUGMENTATION_IDENTIFIER:
            AugmentationIdentifier augmentationIdentifier = (AugmentationIdentifier) pathArgument;
            // No Qname in augmentation identifier
            writeQNameSet(augmentationIdentifier.getPossibleChildNames());
            break;
        default:
            throw new IllegalStateException("Unknown node identifier type is found : " + pathArgument.getClass().toString());
    }
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 5 with AugmentationIdentifier

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

the class BindingNormalizedCodecTest method testLeafOnlyAugmentationSerialization.

@Test
public void testLeafOnlyAugmentationSerialization() {
    this.codec.onGlobalContextUpdated(this.context);
    final PathArgument leafOnlyLastArg = this.codec.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY).getLastPathArgument();
    assertTrue(leafOnlyLastArg instanceof AugmentationIdentifier);
    assertTrue(((AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) AbstractSchemaAwareTest(org.opendaylight.controller.md.sal.binding.test.AbstractSchemaAwareTest) Test(org.junit.Test)

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