From 92f1fd15e99ce5b9e52612c0b52f70cd661b99cc Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 1 Jul 2014 17:21:37 +0200 Subject: [PATCH] BUG-868: do not use deprecated InstanceIdentifier methods This removes the use of the deprecated constructor and some of the getPath() call sites in favor of getPathArguments() and InstanceIdentifier.create()/.node() methods. Change-Id: I2f4ed36645408c6f780031d848af829cbe2a40d6 Signed-off-by: Robert Varga --- .../impl/BindingToNormalizedNodeCodec.java | 38 +-- .../compat/DataNormalizationOperation.java | 24 +- .../impl/util/compat/DataNormalizer.java | 17 +- .../impl/util/compat/DataNormalizerTest.java | 142 ++++---- .../BackwardsCompatibleTransaction.java | 34 +- .../sal/dom/broker/MountPointImpl.java | 66 ++-- .../sal/restconf/impl/RestCodec.java | 41 ++- ...nSnToXmlAndJsonInstanceIdentifierTest.java | 4 +- .../impl/test/RestGetOperationTest.java | 320 +++++++++--------- 9 files changed, 342 insertions(+), 344 deletions(-) diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java index 003f57cd72..6b519955ac 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java @@ -120,7 +120,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { */ public Optional> toBinding( final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized) - throws DeserializationException { + throws DeserializationException { PathArgument lastArgument = Iterables.getLast(normalized.getPathArguments()); // Used instance-identifier codec do not support serialization of last @@ -137,7 +137,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { private Optional> toBindingAugmented( final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized) - throws DeserializationException { + throws DeserializationException { Optional> potential = toBindingImpl(normalized); // Shorthand check, if codec already supports deserialization // of AugmentationIdentifier we will return @@ -154,9 +154,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { // path. LOG.trace("Looking for candidates to match {}", normalized); for (QName child : lastArgument.getPossibleChildNames()) { - org.opendaylight.yangtools.yang.data.api.InstanceIdentifier childPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier( - ImmutableList. builder().addAll(normalized.getPathArguments()).add(new NodeIdentifier(child)) - .build()); + org.opendaylight.yangtools.yang.data.api.InstanceIdentifier childPath = normalized.node(child); try { if (isNotRepresentable(childPath)) { LOG.trace("Path {} is not BI-representable, skipping it", childPath); @@ -189,7 +187,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { private Optional> toBindingImpl( final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized) - throws DeserializationException { + throws DeserializationException { org.opendaylight.yangtools.yang.data.api.InstanceIdentifier legacyPath; try { @@ -219,7 +217,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { private DataNormalizationOperation findNormalizationOperation( final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized) - throws DataNormalizationException { + throws DataNormalizationException { DataNormalizationOperation current = legacyToNormalized.getRootOperation(); for (PathArgument arg : normalized.getPathArguments()) { current = current.getChild(arg); @@ -264,7 +262,7 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { public Optional, DataObject>> toBinding( final Entry> normalized) - throws DeserializationException { + throws DeserializationException { Optional> potentialPath = toBinding(normalized.getKey()); if (potentialPath.isPresent()) { InstanceIdentifier bindingPath = potentialPath.get(); @@ -375,18 +373,18 @@ public class BindingToNormalizedNodeCodec implements SchemaContextListener { try { return ClassLoaderUtils.withClassLoader(method.getDeclaringClass().getClassLoader(), new Supplier() { - @Override - public Class get() { - Type listResult = ClassLoaderUtils.getFirstGenericParameter(method - .getGenericReturnType()); - if (listResult instanceof Class - && DataObject.class.isAssignableFrom((Class) listResult)) { - return (Class) listResult; - } - return null; - } - - }); + @Override + public Class get() { + Type listResult = ClassLoaderUtils.getFirstGenericParameter(method + .getGenericReturnType()); + if (listResult instanceof Class + && DataObject.class.isAssignableFrom((Class) listResult)) { + return (Class) listResult; + } + return null; + } + + }); } catch (Exception e) { LOG.debug("Could not get YANG modeled entity for {}", method, e); return null; diff --git a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java index 7ce475dd59..2b9694bed7 100644 --- a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java +++ b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java @@ -14,6 +14,7 @@ import com.google.common.base.Optional; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; + import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -21,6 +22,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; + import org.opendaylight.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.CompositeNode; @@ -156,7 +158,7 @@ public abstract class DataNormalizationOperation impleme } private static abstract class CompositeNodeNormalizationOperation extends - DataNormalizationOperation { + DataNormalizationOperation { protected CompositeNodeNormalizationOperation(final T identifier) { super(identifier); @@ -218,7 +220,7 @@ public abstract class DataNormalizationOperation impleme } private static abstract class DataContainerNormalizationOperation extends - CompositeNodeNormalizationOperation { + CompositeNodeNormalizationOperation { private final DataNodeContainer schema; private final Map> byQName; @@ -276,7 +278,7 @@ public abstract class DataNormalizationOperation impleme } private static final class ListItemNormalization extends - DataContainerNormalizationOperation { + DataContainerNormalizationOperation { private final List keyDefinition; @@ -356,7 +358,7 @@ public abstract class DataNormalizationOperation impleme } private static abstract class MixinNormalizationOp extends - CompositeNodeNormalizationOperation { + CompositeNodeNormalizationOperation { protected MixinNormalizationOp(final T identifier) { super(identifier); @@ -615,25 +617,25 @@ public abstract class DataNormalizationOperation impleme private static class AnyXmlNormalization extends DataNormalizationOperation { - protected AnyXmlNormalization( NodeIdentifier identifier ) { + protected AnyXmlNormalization( final NodeIdentifier identifier ) { super( identifier ); } @Override - public DataNormalizationOperation getChild( PathArgument child ) throws DataNormalizationException { + public DataNormalizationOperation getChild( final PathArgument child ) throws DataNormalizationException { return null; } @Override - public DataNormalizationOperation getChild( QName child ) throws DataNormalizationException { + public DataNormalizationOperation getChild( final QName child ) throws DataNormalizationException { return null; } @Override - public NormalizedNode normalize( Node legacyData ) { + public NormalizedNode normalize( final Node legacyData ) { NormalizedNodeAttrBuilder, AnyXmlNode> builder = Builders.anyXmlBuilder().withNodeIdentifier( - new NodeIdentifier( legacyData.getNodeType() ) ); + new NodeIdentifier( legacyData.getNodeType() ) ); builder.withValue(legacyData); return builder.build(); } @@ -644,7 +646,7 @@ public abstract class DataNormalizationOperation impleme } @Override - public NormalizedNode createDefault( PathArgument currentArg ) { + public NormalizedNode createDefault( final PathArgument currentArg ) { return null; } } @@ -694,7 +696,7 @@ public abstract class DataNormalizationOperation impleme for (DataSchemaNode child : augmentation.getChildNodes()) { potentialChildren.add(child.getQName()); } - return new AugmentationIdentifier(null, potentialChildren.build()); + return new AugmentationIdentifier(potentialChildren.build()); } private static DataNodeContainer augmentationProxy(final AugmentationSchema augmentation, final DataNodeContainer schema) { diff --git a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java index ec8ce6ecd5..113d3dc9f7 100644 --- a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java +++ b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java @@ -14,10 +14,12 @@ import com.google.common.base.Predicates; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; + import java.util.AbstractMap; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; + import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; @@ -48,7 +50,7 @@ public class DataNormalizer { ImmutableList.Builder normalizedArgs = ImmutableList.builder(); DataNormalizationOperation currentOp = operation; - Iterator arguments = legacy.getPath().iterator(); + Iterator arguments = legacy.getPathArguments().iterator(); try { while (arguments.hasNext()) { @@ -67,7 +69,7 @@ public class DataNormalizer { throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e); } - return new InstanceIdentifier(normalizedArgs.build()); + return InstanceIdentifier.create(normalizedArgs.build()); } public Map.Entry> toNormalized( @@ -81,7 +83,7 @@ public class DataNormalizer { InstanceIdentifier normalizedPath = toNormalized(legacyPath); DataNormalizationOperation currentOp = operation; - for (PathArgument arg : normalizedPath.getPath()) { + for (PathArgument arg : normalizedPath.getPathArguments()) { try { currentOp = currentOp.getChild(arg); } catch (DataNormalizationException e) { @@ -103,9 +105,7 @@ public class DataNormalizer { if (potentialOp.getIdentifier() instanceof AugmentationIdentifier) { currentOp = potentialOp; - ArrayList reworkedArgs = new ArrayList<>(normalizedPath.getPath()); - reworkedArgs.add(potentialOp.getIdentifier()); - normalizedPath = new InstanceIdentifier(reworkedArgs); + normalizedPath = normalizedPath.node(potentialOp.getIdentifier()); } } @@ -117,15 +117,14 @@ public class DataNormalizer { public InstanceIdentifier toLegacy(final InstanceIdentifier normalized) throws DataNormalizationException { ImmutableList.Builder legacyArgs = ImmutableList.builder(); - PathArgument previous = null; DataNormalizationOperation currentOp = operation; - for (PathArgument normalizedArg : normalized.getPath()) { + for (PathArgument normalizedArg : normalized.getPathArguments()) { currentOp = currentOp.getChild(normalizedArg); if(!currentOp.isMixin()) { legacyArgs.add(normalizedArg); } } - return new InstanceIdentifier(legacyArgs.build()); + return InstanceIdentifier.create(legacyArgs.build()); } public CompositeNode toLegacy(final InstanceIdentifier normalizedPath, final NormalizedNode normalizedData) { diff --git a/opendaylight/md-sal/sal-common-impl/src/test/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizerTest.java b/opendaylight/md-sal/sal-common-impl/src/test/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizerTest.java index ce861f7e7a..1b3ff305bc 100644 --- a/opendaylight/md-sal/sal-common-impl/src/test/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizerTest.java +++ b/opendaylight/md-sal/sal-common-impl/src/test/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizerTest.java @@ -17,6 +17,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; + import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; @@ -26,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; + import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.CompositeNode; @@ -68,7 +70,7 @@ public class DataNormalizerTest { Class nodeClass; Object nodeData; // List for a container, value Object for a leaf - NormalizedNodeData(PathArgument nodeID, Class nodeClass, Object nodeData) { + NormalizedNodeData(final PathArgument nodeID, final Class nodeClass, final Object nodeData) { this.nodeID = nodeID; this.nodeClass = nodeClass; this.nodeData = nodeData; @@ -78,9 +80,9 @@ public class DataNormalizerTest { static class LegacyNodeData { QName nodeKey; Object nodeData; // List for a CompositeNode, value Object for a - // SimpeNode + // SimpeNode - LegacyNodeData(QName nodeKey, Object nodeData) { + LegacyNodeData(final QName nodeKey, final Object nodeData) { this.nodeKey = nodeKey; this.nodeData = nodeData; } @@ -144,7 +146,7 @@ public class DataNormalizerTest { OUTER_LIST_QNAME, ID_QNAME, OUTER_LIST_ID }, OUTER_CHOICE_QNAME, TWO_QNAME); } - private void verifyNormalizedInstanceIdentifier(InstanceIdentifier actual, Object... expPath) { + private void verifyNormalizedInstanceIdentifier(final InstanceIdentifier actual, final Object... expPath) { assertNotNull("Actual InstanceIdentifier is null", actual); assertEquals("InstanceIdentifier path length", expPath.length, actual.getPath().size()); @@ -256,12 +258,12 @@ public class DataNormalizerTest { expectCompositeNode(INNER_LIST_QNAME, expectSimpleNode(NAME_QNAME, "inner-name1"), expectSimpleNode(VALUE_QNAME, "inner-value1")), - expectCompositeNode(INNER_LIST_QNAME, expectSimpleNode(NAME_QNAME, "inner-name2"), - expectSimpleNode(VALUE_QNAME, "inner-value2"))), - expectCompositeNode(OUTER_LIST_QNAME, expectSimpleNode(ID_QNAME, outerListID2), - expectSimpleNode(ONE_QNAME, "one")), - expectCompositeNode(UNKEYED_LIST_QNAME, expectSimpleNode(NAME_QNAME, "unkeyed1")), - expectCompositeNode(UNKEYED_LIST_QNAME, expectSimpleNode(NAME_QNAME, "unkeyed2")))); + expectCompositeNode(INNER_LIST_QNAME, expectSimpleNode(NAME_QNAME, "inner-name2"), + expectSimpleNode(VALUE_QNAME, "inner-value2"))), + expectCompositeNode(OUTER_LIST_QNAME, expectSimpleNode(ID_QNAME, outerListID2), + expectSimpleNode(ONE_QNAME, "one")), + expectCompositeNode(UNKEYED_LIST_QNAME, expectSimpleNode(NAME_QNAME, "unkeyed1")), + expectCompositeNode(UNKEYED_LIST_QNAME, expectSimpleNode(NAME_QNAME, "unkeyed2")))); // Conversion of Mixin type nodes is not supported. @@ -366,12 +368,12 @@ public class DataNormalizerTest { expectSimpleNode(AUGMENTED_LEAF_QNAME, "augmented-value")))); } - private boolean isOrdered(QName nodeName) { + private boolean isOrdered(final QName nodeName) { return ORDERED_LEAF_LIST_QNAME.equals(nodeName) || INNER_LIST_QNAME.equals(nodeName); } @SuppressWarnings("unchecked") - private void verifyLegacyNode(Node actual, LegacyNodeData expNodeData) { + private void verifyLegacyNode(final Node actual, final LegacyNodeData expNodeData) { assertNotNull("Actual Node is null", actual); assertTrue("Expected CompositeNode instance", actual instanceof CompositeNode); @@ -390,7 +392,7 @@ public class DataNormalizerTest { Collections.sort(unorderdChildData, new Comparator() { @Override - public int compare(LegacyNodeData arg1, LegacyNodeData arg2) { + public int compare(final LegacyNodeData arg1, final LegacyNodeData arg2) { if (!(arg1.nodeData instanceof List) && !(arg2.nodeData instanceof List)) { // if neither is a list, just compare them String str1 = arg1.nodeKey.getLocalName() + arg1.nodeData; @@ -446,7 +448,7 @@ public class DataNormalizerTest { Collections.sort(unorderedChildNodes, new Comparator>() { @Override - public int compare(Node n1, Node n2) { + public int compare(final Node n1, final Node n2) { if (n1 instanceof SimpleNode && n2 instanceof SimpleNode) { // if they're SimpleNodes just compare their strings String str1 = n1.getKey().getLocalName() + ((SimpleNode)n1).getValue(); @@ -501,7 +503,7 @@ public class DataNormalizerTest { assertEquals("Child node QName", expData.nodeKey, actualChild.getKey()); if (expData.nodeData instanceof List) { // List represents a - // composite node + // composite node verifyLegacyNode(actualChild, expData); } else { // else a simple node assertTrue("Expected SimpleNode instance", actualChild instanceof SimpleNode); @@ -515,11 +517,11 @@ public class DataNormalizerTest { } } - private LegacyNodeData expectCompositeNode(QName key, LegacyNodeData... childData) { + private LegacyNodeData expectCompositeNode(final QName key, final LegacyNodeData... childData) { return new LegacyNodeData(key, Lists.newArrayList(childData)); } - private LegacyNodeData expectSimpleNode(QName key, Object value) { + private LegacyNodeData expectSimpleNode(final QName key, final Object value) { return new LegacyNodeData(key, value); } @@ -561,7 +563,7 @@ public class DataNormalizerTest { } Entry> normalizedNodeEntry = normalizer - .toNormalized(new AbstractMap.SimpleEntry(new InstanceIdentifier( + .toNormalized(new AbstractMap.SimpleEntry(InstanceIdentifier.create( ImmutableList. of(new NodeIdentifier(TEST_QNAME))), testBuilder.toInstance())); verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME); @@ -583,25 +585,25 @@ public class DataNormalizerTest { expectMapEntryNode(INNER_LIST_QNAME, NAME_QNAME, "inner-name3", expectLeafNode(NAME_QNAME, "inner-name3"), expectLeafNode(VALUE_QNAME, "inner-value3")), - expectMapEntryNode(INNER_LIST_QNAME, NAME_QNAME, "inner-name2", - expectLeafNode(NAME_QNAME, "inner-name2"), - expectLeafNode(VALUE_QNAME, "inner-value2")), - expectMapEntryNode(INNER_LIST_QNAME, NAME_QNAME, "inner-name1", - expectLeafNode(NAME_QNAME, "inner-name1"), - expectLeafNode(VALUE_QNAME, "inner-value1")))), - expectMapEntryNode( - OUTER_LIST_QNAME, - ID_QNAME, - 20, - expectLeafNode(ID_QNAME, 20), - expectChoiceNode(OUTER_CHOICE_QNAME, expectLeafNode(TWO_QNAME, "two"), - expectLeafNode(THREE_QNAME, "three")))), - expectUnkeyedListNode( - UNKEYED_LIST_QNAME, - expectUnkeyedListEntryNode(UNKEYED_LIST_QNAME, - expectLeafNode(NAME_QNAME, "unkeyed-name1")), - expectUnkeyedListEntryNode(UNKEYED_LIST_QNAME, - expectLeafNode(NAME_QNAME, "unkeyed-name2"))))); + expectMapEntryNode(INNER_LIST_QNAME, NAME_QNAME, "inner-name2", + expectLeafNode(NAME_QNAME, "inner-name2"), + expectLeafNode(VALUE_QNAME, "inner-value2")), + expectMapEntryNode(INNER_LIST_QNAME, NAME_QNAME, "inner-name1", + expectLeafNode(NAME_QNAME, "inner-name1"), + expectLeafNode(VALUE_QNAME, "inner-value1")))), + expectMapEntryNode( + OUTER_LIST_QNAME, + ID_QNAME, + 20, + expectLeafNode(ID_QNAME, 20), + expectChoiceNode(OUTER_CHOICE_QNAME, expectLeafNode(TWO_QNAME, "two"), + expectLeafNode(THREE_QNAME, "three")))), + expectUnkeyedListNode( + UNKEYED_LIST_QNAME, + expectUnkeyedListEntryNode(UNKEYED_LIST_QNAME, + expectLeafNode(NAME_QNAME, "unkeyed-name1")), + expectUnkeyedListEntryNode(UNKEYED_LIST_QNAME, + expectLeafNode(NAME_QNAME, "unkeyed-name2"))))); } @Test @@ -625,7 +627,7 @@ public class DataNormalizerTest { testBuilder.add(anyXmlLegacy); Entry> normalizedNodeEntry = normalizer - .toNormalized(new AbstractMap.SimpleEntry(new InstanceIdentifier( + .toNormalized(new AbstractMap.SimpleEntry(InstanceIdentifier.create( ImmutableList. of(new NodeIdentifier(TEST_QNAME))), testBuilder.toInstance())); verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME); @@ -649,7 +651,7 @@ public class DataNormalizerTest { testBuilder.add(outerContBuilder.toInstance()); Entry> normalizedNodeEntry = normalizer - .toNormalized(new AbstractMap.SimpleEntry(new InstanceIdentifier( + .toNormalized(new AbstractMap.SimpleEntry(InstanceIdentifier.create( ImmutableList. of(new NodeIdentifier(TEST_QNAME))), testBuilder.toInstance())); verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME); @@ -661,7 +663,7 @@ public class DataNormalizerTest { expectContainerNode(TEST_QNAME, expectContainerNode(OUTER_CONTAINER_QNAME, expAugmentation))); normalizedNodeEntry = normalizer.toNormalized(new AbstractMap.SimpleEntry( - new InstanceIdentifier(Lists.newArrayList(new NodeIdentifier(TEST_QNAME), new NodeIdentifier( + InstanceIdentifier.create(Lists.newArrayList(new NodeIdentifier(TEST_QNAME), new NodeIdentifier( OUTER_CONTAINER_QNAME))), outerContBuilder.toInstance())); verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME, OUTER_CONTAINER_QNAME, @@ -687,7 +689,7 @@ public class DataNormalizerTest { } Entry> normalizedNodeEntry = normalizer - .toNormalized(new AbstractMap.SimpleEntry(new InstanceIdentifier( + .toNormalized(new AbstractMap.SimpleEntry(InstanceIdentifier.create( ImmutableList. of(new NodeIdentifier(TEST_QNAME))), testBuilder.toInstance())); verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME); @@ -700,14 +702,14 @@ public class DataNormalizerTest { expectLeafSetEntryNode(UNORDERED_LEAF_LIST_QNAME, "unordered-value1"), expectLeafSetEntryNode(UNORDERED_LEAF_LIST_QNAME, "unordered-value2"), expectLeafSetEntryNode(UNORDERED_LEAF_LIST_QNAME, "unordered-value3")), - expectOrderedLeafSetNode(ORDERED_LEAF_LIST_QNAME, - expectLeafSetEntryNode(ORDERED_LEAF_LIST_QNAME, "ordered-value3"), - expectLeafSetEntryNode(ORDERED_LEAF_LIST_QNAME, "ordered-value2"), - expectLeafSetEntryNode(ORDERED_LEAF_LIST_QNAME, "ordered-value1")))); + expectOrderedLeafSetNode(ORDERED_LEAF_LIST_QNAME, + expectLeafSetEntryNode(ORDERED_LEAF_LIST_QNAME, "ordered-value3"), + expectLeafSetEntryNode(ORDERED_LEAF_LIST_QNAME, "ordered-value2"), + expectLeafSetEntryNode(ORDERED_LEAF_LIST_QNAME, "ordered-value1")))); } @SuppressWarnings("unchecked") - private void verifyNormalizedNode(NormalizedNode actual, NormalizedNodeData expNodeData) { + private void verifyNormalizedNode(final NormalizedNode actual, final NormalizedNodeData expNodeData) { Class expNodeClass = expNodeData.nodeClass; PathArgument expNodeID = expNodeData.nodeID; @@ -743,18 +745,18 @@ public class DataNormalizerTest { NormalizedNodeData expChildData = expNodeClass.equals(UnkeyedListNode.class) ? expChildDataList .remove(0) : expChildDataMap.remove(actualChild.getIdentifier()); - assertNotNull( - "Unexpected child node " + actualChild.getClass() + " with identifier " - + actualChild.getIdentifier() + " for parent node " + actual.getClass() - + " with identifier " + actual.getIdentifier(), expChildData); + assertNotNull( + "Unexpected child node " + actualChild.getClass() + " with identifier " + + actualChild.getIdentifier() + " for parent node " + actual.getClass() + + " with identifier " + actual.getIdentifier(), expChildData); - if (orderingMap != null) { - assertEquals("Order index for child node " + actualChild.getIdentifier(), - orderingMap.get(actualChild.getIdentifier()), Integer.valueOf(i)); - } + if (orderingMap != null) { + assertEquals("Order index for child node " + actualChild.getIdentifier(), + orderingMap.get(actualChild.getIdentifier()), Integer.valueOf(i)); + } - verifyNormalizedNode(actualChild, expChildData); - i++; + verifyNormalizedNode(actualChild, expChildData); + i++; } if (expNodeClass.equals(UnkeyedListNode.class)) { @@ -771,62 +773,62 @@ public class DataNormalizerTest { } } - private NormalizedNodeData expectOrderedLeafSetNode(QName nodeName, NormalizedNodeData... childData) { + private NormalizedNodeData expectOrderedLeafSetNode(final QName nodeName, final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifier(nodeName), OrderedLeafSetNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectLeafSetNode(QName nodeName, NormalizedNodeData... childData) { + private NormalizedNodeData expectLeafSetNode(final QName nodeName, final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifier(nodeName), LeafSetNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectLeafSetEntryNode(QName nodeName, Object value) { + private NormalizedNodeData expectLeafSetEntryNode(final QName nodeName, final Object value) { return new NormalizedNodeData(new NodeWithValue(nodeName, value), LeafSetEntryNode.class, value); } - private NormalizedNodeData expectUnkeyedListNode(QName nodeName, NormalizedNodeData... childData) { + private NormalizedNodeData expectUnkeyedListNode(final QName nodeName, final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifier(nodeName), UnkeyedListNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectUnkeyedListEntryNode(QName nodeName, NormalizedNodeData... childData) { + private NormalizedNodeData expectUnkeyedListEntryNode(final QName nodeName, final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifier(nodeName), UnkeyedListEntryNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectAugmentation(QName augmentedNodeName, NormalizedNodeData... childData) { + private NormalizedNodeData expectAugmentation(final QName augmentedNodeName, final NormalizedNodeData... childData) { return new NormalizedNodeData(new AugmentationIdentifier(Sets.newHashSet(augmentedNodeName)), AugmentationNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectAnyXmlNode(QName nodeName, Object value) { + private NormalizedNodeData expectAnyXmlNode(final QName nodeName, final Object value) { return new NormalizedNodeData(new NodeIdentifier(nodeName), AnyXmlNode.class, value); } - private NormalizedNodeData expectContainerNode(QName nodeName, NormalizedNodeData... childData) { + private NormalizedNodeData expectContainerNode(final QName nodeName, final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifier(nodeName), ContainerNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectChoiceNode(QName nodeName, NormalizedNodeData... childData) { + private NormalizedNodeData expectChoiceNode(final QName nodeName, final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifier(nodeName), ChoiceNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectLeafNode(QName nodeName, Object value) { + private NormalizedNodeData expectLeafNode(final QName nodeName, final Object value) { return new NormalizedNodeData(new NodeIdentifier(nodeName), LeafNode.class, value); } - private NormalizedNodeData expectMapEntryNode(QName nodeName, QName key, Object value, - NormalizedNodeData... childData) { + private NormalizedNodeData expectMapEntryNode(final QName nodeName, final QName key, final Object value, + final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifierWithPredicates(nodeName, key, value), MapEntryNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectMapNode(QName key, NormalizedNodeData... childData) { + private NormalizedNodeData expectMapNode(final QName key, final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifier(key), MapNode.class, Lists.newArrayList(childData)); } - private NormalizedNodeData expectOrderedMapNode(QName key, NormalizedNodeData... childData) { + private NormalizedNodeData expectOrderedMapNode(final QName key, final NormalizedNodeData... childData) { return new NormalizedNodeData(new NodeIdentifier(key), OrderedMapNode.class, Lists.newArrayList(childData)); } } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java index b3fb7b6da8..27e322f23b 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java @@ -43,7 +43,7 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ListenableFuture; public abstract class BackwardsCompatibleTransaction implements - DataModificationTransaction, Delegator { +DataModificationTransaction, Delegator { private static final Logger LOG = LoggerFactory.getLogger(BackwardsCompatibleTransaction.class); @@ -228,23 +228,23 @@ public abstract class BackwardsCompatibleTransaction currentArguments = new ArrayList<>(); - DataNormalizationOperation currentOp = getNormalizer().getRootOperation(); - Iterator iterator = normalizedPath.getPath().iterator(); - while(iterator.hasNext()) { - PathArgument currentArg = iterator.next(); - try { - currentOp = currentOp.getChild(currentArg); - } catch (DataNormalizationException e) { - throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", normalizedPath), e); + List currentArguments = new ArrayList<>(); + DataNormalizationOperation currentOp = getNormalizer().getRootOperation(); + Iterator iterator = normalizedPath.getPathArguments().iterator(); + while(iterator.hasNext()) { + PathArgument currentArg = iterator.next(); + try { + currentOp = currentOp.getChild(currentArg); + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", normalizedPath), e); + } + currentArguments.add(currentArg); + InstanceIdentifier currentPath = InstanceIdentifier.create(currentArguments); + boolean isPresent = getDelegate().read(store, currentPath).get().isPresent(); + if(isPresent == false && iterator.hasNext()) { + getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg)); + } } - currentArguments.add(currentArg); - InstanceIdentifier currentPath = new InstanceIdentifier(currentArguments); - boolean isPresent = getDelegate().read(store, currentPath).get().isPresent(); - if(isPresent == false && iterator.hasNext()) { - getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg)); - } - } } catch (InterruptedException | ExecutionException e) { LOG.error("Exception durring read.",e); } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointImpl.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointImpl.java index 623bbdb195..e69343d4fe 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointImpl.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointImpl.java @@ -54,7 +54,7 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv private SchemaContext schemaContext; - public MountPointImpl(InstanceIdentifier path) { + public MountPointImpl(final InstanceIdentifier path) { this.mountPath = path; rpcs = new SchemaAwareRpcBroker(path.toString(),this); dataReader = new DataBrokerImpl(); @@ -71,49 +71,49 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv } @Override - public void publish(CompositeNode notification) { + public void publish(final CompositeNode notification) { notificationRouter.publish(notification); } @Override - public Registration addNotificationListener(QName notification, NotificationListener listener) { + public Registration addNotificationListener(final QName notification, final NotificationListener listener) { return notificationRouter.addNotificationListener(notification, listener); } @Override - public CompositeNode readConfigurationData(InstanceIdentifier path) { + public CompositeNode readConfigurationData(final InstanceIdentifier path) { return dataReader.readConfigurationData(path); } @Override - public CompositeNode readOperationalData(InstanceIdentifier path) { + public CompositeNode readOperationalData(final InstanceIdentifier path) { return dataReader.readOperationalData(path); } @Override public Registration> registerOperationalReader( - InstanceIdentifier path, DataReader reader) { + final InstanceIdentifier path, final DataReader reader) { return dataReader.registerOperationalReader(path, reader); } @Override public Registration> registerConfigurationReader( - InstanceIdentifier path, DataReader reader) { + final InstanceIdentifier path, final DataReader reader) { return dataReader.registerConfigurationReader(path, reader); } @Override - public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) { + public RoutedRpcRegistration addRoutedRpcImplementation(final QName rpcType, final RpcImplementation implementation) { return rpcs.addRoutedRpcImplementation(rpcType, implementation); } @Override - public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) { - rpcs.setRoutedRpcDefaultDelegate(defaultImplementation); + public void setRoutedRpcDefaultDelegate(final RoutedRpcDefaultImplementation defaultImplementation) { + rpcs.setRoutedRpcDefaultDelegate(defaultImplementation); } - @Override - public RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation) + @Override + public RpcRegistration addRpcImplementation(final QName rpcType, final RpcImplementation implementation) throws IllegalArgumentException { return rpcs.addRpcImplementation(rpcType, implementation); } @@ -124,17 +124,17 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv } @Override - public ListenableFuture> invokeRpc(QName rpc, CompositeNode input) { + public ListenableFuture> invokeRpc(final QName rpc, final CompositeNode input) { return rpcs.invokeRpc(rpc, input); } @Override - public ListenerRegistration addRpcRegistrationListener(RpcRegistrationListener listener) { + public ListenerRegistration addRpcRegistrationListener(final RpcRegistrationListener listener) { return rpcs.addRpcRegistrationListener(listener); } @Override - public ListenableFuture> rpc(QName type, CompositeNode input) { + public ListenableFuture> rpc(final QName type, final CompositeNode input) { return rpcs.invokeRpc( type, input ); } @@ -144,33 +144,33 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv } @Override - public ListenerRegistration registerDataChangeListener(InstanceIdentifier path, - DataChangeListener listener) { + public ListenerRegistration registerDataChangeListener(final InstanceIdentifier path, + final DataChangeListener listener) { return dataReader.registerDataChangeListener(path, listener); } @Override public Registration> registerCommitHandler( - InstanceIdentifier path, DataCommitHandler commitHandler) { + final InstanceIdentifier path, final DataCommitHandler commitHandler) { return dataReader.registerCommitHandler(path, commitHandler); } @Override - public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) { - // NOOP + public void removeRefresher(final DataStoreIdentifier store, final DataRefresher refresher) { + // NOOP } @Override - public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) { - // NOOP + public void addRefresher(final DataStoreIdentifier store, final DataRefresher refresher) { + // NOOP } @Override - public void addValidator(DataStoreIdentifier store, DataValidator validator) { - // NOOP + public void addValidator(final DataStoreIdentifier store, final DataValidator validator) { + // NOOP } @Override - public void removeValidator(DataStoreIdentifier store, DataValidator validator) { + public void removeValidator(final DataStoreIdentifier store, final DataValidator validator) { // NOOP } @@ -180,24 +180,22 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv } @Override - public void setSchemaContext(SchemaContext schemaContext) { + public void setSchemaContext(final SchemaContext schemaContext) { this.schemaContext = schemaContext; } class ReadWrapper implements DataReader { - - - private InstanceIdentifier shortenPath(InstanceIdentifier path) { + private InstanceIdentifier shortenPath(final InstanceIdentifier path) { InstanceIdentifier ret = null; if(mountPath.contains(path)) { List newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size()); - ret = new InstanceIdentifier(newArgs); + ret = InstanceIdentifier.create(newArgs); } return ret; } @Override - public CompositeNode readConfigurationData(InstanceIdentifier path) { + public CompositeNode readConfigurationData(final InstanceIdentifier path) { InstanceIdentifier newPath = shortenPath(path); if(newPath == null) { return null; @@ -206,7 +204,7 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv } @Override - public CompositeNode readOperationalData(InstanceIdentifier path) { + public CompositeNode readOperationalData(final InstanceIdentifier path) { InstanceIdentifier newPath = shortenPath(path); if(newPath == null) { return null; @@ -217,13 +215,13 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv @Override public ListenerRegistration>> registerCommitHandlerListener( - RegistrationListener> commitHandlerListener) { + final RegistrationListener> commitHandlerListener) { return dataReader.registerCommitHandlerListener(commitHandlerListener); } @Override public > ListenerRegistration registerRouteChangeListener( - L listener) { + final L listener) { return rpcs.registerRouteChangeListener(listener); } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java index 265cc5db45..14b8282312 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java @@ -47,7 +47,7 @@ public class RestCodec { private RestCodec() { } - public static final Codec from(TypeDefinition typeDefinition, MountInstance mountPoint) { + public static final Codec from(final TypeDefinition typeDefinition, final MountInstance mountPoint) { return new ObjectCodec(typeDefinition, mountPoint); } @@ -62,7 +62,7 @@ public class RestCodec { private final TypeDefinition type; - private ObjectCodec(TypeDefinition typeDefinition, MountInstance mountPoint) { + private ObjectCodec(final TypeDefinition typeDefinition, final MountInstance mountPoint) { type = RestUtil.resolveBaseTypeFrom(typeDefinition); if (type instanceof IdentityrefTypeDefinition) { identityrefCodec = new IdentityrefCodecImpl(mountPoint); @@ -78,7 +78,7 @@ public class RestCodec { @SuppressWarnings("unchecked") @Override - public Object deserialize(Object input) { + public Object deserialize(final Object input) { try { if (type instanceof IdentityrefTypeDefinition) { if (input instanceof IdentityValuesDTO) { @@ -116,7 +116,7 @@ public class RestCodec { } } } catch (ClassCastException e) { // TODO remove this catch when - // everyone use codecs + // everyone use codecs logger.error( "ClassCastException was thrown when codec is invoked with parameter " + String.valueOf(input), e); @@ -126,7 +126,7 @@ public class RestCodec { @SuppressWarnings("unchecked") @Override - public Object serialize(Object input) { + public Object serialize(final Object input) { try { if (type instanceof IdentityrefTypeDefinition) { return identityrefCodec.serialize(input); @@ -146,7 +146,7 @@ public class RestCodec { } } } catch (ClassCastException e) { // TODO remove this catch when - // everyone use codecs + // everyone use codecs logger.error( "ClassCastException was thrown when codec is invoked with parameter " + String.valueOf(input), e); @@ -162,17 +162,17 @@ public class RestCodec { private final MountInstance mountPoint; - public IdentityrefCodecImpl(MountInstance mountPoint) { + public IdentityrefCodecImpl(final MountInstance mountPoint) { this.mountPoint = mountPoint; } @Override - public IdentityValuesDTO serialize(QName data) { + public IdentityValuesDTO serialize(final QName data) { return new IdentityValuesDTO(data.getNamespace().toString(), data.getLocalName(), data.getPrefix(),null); } @Override - public QName deserialize(IdentityValuesDTO data) { + public QName deserialize(final IdentityValuesDTO data) { IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint); if (module == null) { @@ -189,12 +189,12 @@ public class RestCodec { public static class LeafrefCodecImpl implements LeafrefCodec { @Override - public String serialize(Object data) { + public String serialize(final Object data) { return String.valueOf(data); } @Override - public Object deserialize(String data) { + public Object deserialize(final String data) { return data; } @@ -204,15 +204,14 @@ public class RestCodec { private final Logger logger = LoggerFactory.getLogger(InstanceIdentifierCodecImpl.class); private final MountInstance mountPoint; - public InstanceIdentifierCodecImpl(MountInstance mountPoint) { + public InstanceIdentifierCodecImpl(final MountInstance mountPoint) { this.mountPoint = mountPoint; } @Override - public IdentityValuesDTO serialize(InstanceIdentifier data) { - List pathArguments = data.getPath(); + public IdentityValuesDTO serialize(final InstanceIdentifier data) { IdentityValuesDTO identityValuesDTO = new IdentityValuesDTO(); - for (PathArgument pathArgument : pathArguments) { + for (PathArgument pathArgument : data.getPathArguments()) { IdentityValue identityValue = qNameToIdentityValue(pathArgument.getNodeType()); if (pathArgument instanceof NodeIdentifierWithPredicates && identityValue != null) { List predicates = keyValuesToPredicateList(((NodeIdentifierWithPredicates) pathArgument) @@ -230,7 +229,7 @@ public class RestCodec { } @Override - public InstanceIdentifier deserialize(IdentityValuesDTO data) { + public InstanceIdentifier deserialize(final IdentityValuesDTO data) { List result = new ArrayList(); IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0); Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint); @@ -293,10 +292,10 @@ public class RestCodec { } } - return result.isEmpty() ? null : new InstanceIdentifier(result); + return result.isEmpty() ? null : InstanceIdentifier.create(result); } - private List keyValuesToPredicateList(Map keyValues) { + private List keyValuesToPredicateList(final Map keyValues) { List result = new ArrayList<>(); for (QName qName : keyValues.keySet()) { Object value = keyValues.get(qName); @@ -305,7 +304,7 @@ public class RestCodec { return result; } - private IdentityValue qNameToIdentityValue(QName qName) { + private IdentityValue qNameToIdentityValue(final QName qName) { if (qName != null) { return new IdentityValue(qName.getNamespace().toString(), qName.getLocalName(), qName.getPrefix()); } @@ -313,7 +312,7 @@ public class RestCodec { } } - private static Module getModuleByNamespace(String namespace, MountInstance mountPoint) { + private static Module getModuleByNamespace(final String namespace, final MountInstance mountPoint) { URI validNamespace = resolveValidNamespace(namespace, mountPoint); Module module = null; @@ -329,7 +328,7 @@ public class RestCodec { return module; } - private static URI resolveValidNamespace(String namespace, MountInstance mountPoint) { + private static URI resolveValidNamespace(final String namespace, final MountInstance mountPoint) { URI validNamespace; if (mountPoint != null) { validNamespace = ControllerContext.getInstance().findNamespaceByModuleName(mountPoint, namespace); diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java index 07d781028b..3f2c212bd8 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java @@ -226,7 +226,7 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch pathArguments.add(new NodeIdentifier(new QName(new URI("augment:augment:module"), "lf112"))); - return new InstanceIdentifier(pathArguments); + return InstanceIdentifier.create(pathArguments); } private InstanceIdentifier createInstanceIdentifierWithLeafList() throws URISyntaxException { @@ -235,7 +235,7 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch pathArguments.add(new NodeIdentifier(new QName(new URI("instance:identifier:module"), "cont1"))); pathArguments.add(new NodeWithValue(new QName(new URI("augment:module:leaf:list"), "lflst11"), "lflst11_1")); - return new InstanceIdentifier(pathArguments); + return InstanceIdentifier.create(pathArguments); } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java index f0a232fba6..41a1c3827d 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java @@ -7,8 +7,8 @@ */ package org.opendaylight.controller.sal.restconf.impl.test; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -77,7 +77,7 @@ public class RestGetOperationTest extends JerseyTest { Object key; Object data; // List for a CompositeNode, value Object for a SimpleNode - NodeData( Object key, Object data ) { + NodeData( final Object key, final Object data ) { this.key = key; this.data = data; } @@ -186,7 +186,7 @@ public class RestGetOperationTest extends JerseyTest { */ @Test public void getDataWithSlashesBehindMountPoint() throws UnsupportedEncodingException, URISyntaxException, - ParseException { + ParseException { InstanceIdentifier awaitedInstanceIdentifier = prepareInstanceIdentifierForList(); when( brokerFacade.readConfigurationDataBehindMountPoint(any(MountInstance.class), @@ -214,7 +214,7 @@ public class RestGetOperationTest extends JerseyTest { parameters.add(new InstanceIdentifier.NodeIdentifier(qNameCont)); parameters.add(new InstanceIdentifier.NodeIdentifierWithPredicates(qNameList, qNameKeyList, "GigabitEthernet0/0/0/0")); - return new InstanceIdentifier(parameters); + return InstanceIdentifier.create(parameters); } @Test @@ -356,7 +356,7 @@ public class RestGetOperationTest extends JerseyTest { } - private Matcher validateOperationsResponseJson(String searchIn, String rpcName, String moduleName) { + private Matcher validateOperationsResponseJson(final String searchIn, final String rpcName, final String moduleName) { StringBuilder regex = new StringBuilder(); regex.append("^"); @@ -390,7 +390,7 @@ public class RestGetOperationTest extends JerseyTest { } - private Matcher validateOperationsResponseXml(String searchIn, String rpcName, String namespace) { + private Matcher validateOperationsResponseXml(final String searchIn, final String rpcName, final String namespace) { StringBuilder regex = new StringBuilder(); regex.append("^"); @@ -448,11 +448,11 @@ public class RestGetOperationTest extends JerseyTest { assertTrue( "module1-behind-mount-point in json wasn't found", prepareXmlRegex("module1-behind-mount-point", "2014-02-03", "module:1:behind:mount:point", responseBody) - .find()); + .find()); assertTrue( "module2-behind-mount-point in json wasn't found", prepareXmlRegex("module2-behind-mount-point", "2014-02-04", "module:2:behind:mount:point", responseBody) - .find()); + .find()); } @@ -488,13 +488,13 @@ public class RestGetOperationTest extends JerseyTest { assertTrue( "module1-behind-mount-point in json wasn't found", prepareXmlRegex("module1-behind-mount-point", "2014-02-03", "module:1:behind:mount:point", responseBody) - .find()); + .find()); split = responseBody.split(">() { - @Override - public MultivaluedMap answer( InvocationOnMock invocation ) { - return paramMap; - } - } ); + new Answer>() { + @Override + public MultivaluedMap answer( final InvocationOnMock invocation ) { + return paramMap; + } + } ); getDataWithInvalidDepthParameterTest( mockInfo ); @@ -821,18 +821,18 @@ public class RestGetOperationTest extends JerseyTest { getDataWithInvalidDepthParameterTest( mockInfo ); } - private void getDataWithInvalidDepthParameterTest( UriInfo uriInfo ) { + private void getDataWithInvalidDepthParameterTest( final UriInfo uriInfo ) { try { restconfImpl.readConfigurationData( "nested-module:depth1-cont", uriInfo ); fail( "Expected RestconfDocumentedException" ); } catch( RestconfDocumentedException e ) { assertTrue( "Unexpected error message: " + e.getErrors().get( 0 ).getErrorMessage(), - e.getErrors().get( 0 ).getErrorMessage().contains( "depth" ) ); + e.getErrors().get( 0 ).getErrorMessage().contains( "depth" ) ); } } - private void verifyXMLResponse( Response response, NodeData nodeData ) { + private void verifyXMLResponse( final Response response, final NodeData nodeData ) { Document doc = TestUtils.loadDocumentFrom( (InputStream) response.getEntity() ); assertNotNull( "Could not parse XML document", doc ); @@ -843,14 +843,14 @@ public class RestGetOperationTest extends JerseyTest { } @SuppressWarnings("unchecked") - private void verifyContainerElement( Element element, NodeData nodeData ) { + private void verifyContainerElement( final Element element, final NodeData nodeData ) { assertEquals( "Element local name", nodeData.key, element.getNodeName() ); NodeList childNodes = element.getChildNodes(); if( nodeData.data == null ) { // empty container assertTrue( "Expected no child elements for \"" + element.getNodeName() + "\"", - childNodes.getLength() == 0 ); + childNodes.getLength() == 0 ); return; } @@ -868,41 +868,41 @@ public class RestGetOperationTest extends JerseyTest { Element actualElement = (Element)actualChild; NodeData expChild = expChildMap.remove( actualElement.getNodeName() ); assertNotNull( "Unexpected child element for parent \"" + element.getNodeName() + - "\": " + actualElement.getNodeName(), expChild ); + "\": " + actualElement.getNodeName(), expChild ); if( expChild.data == null || expChild.data instanceof List ) { verifyContainerElement( actualElement, expChild ); } else { assertEquals( "Text content for element: " + actualElement.getNodeName(), - expChild.data, actualElement.getTextContent() ); + expChild.data, actualElement.getTextContent() ); } } if( !expChildMap.isEmpty() ) { fail( "Missing elements for parent \"" + element.getNodeName() + - "\": " + expChildMap.keySet() ); + "\": " + expChildMap.keySet() ); } } - private NodeData expectContainer( String name, NodeData... childData ) { + private NodeData expectContainer( final String name, final NodeData... childData ) { return new NodeData( name, Lists.newArrayList( childData ) ); } - private NodeData expectEmptyContainer( String name ) { + private NodeData expectEmptyContainer( final String name ) { return new NodeData( name, null ); } - private NodeData expectLeaf( String name, Object value ) { + private NodeData expectLeaf( final String name, final Object value ) { return new NodeData( name, value ); } - private QName toNestedQName( String localName ) { + private QName toNestedQName( final String localName ) { return QName.create( "urn:nested:module", "2014-06-3", localName ); } @SuppressWarnings("unchecked") - private CompositeNode toCompositeNode( NodeData nodeData ) { + private CompositeNode toCompositeNode( final NodeData nodeData ) { CompositeNodeBuilder builder = ImmutableCompositeNode.builder(); builder.setQName( (QName) nodeData.key ); @@ -918,11 +918,11 @@ public class RestGetOperationTest extends JerseyTest { return builder.toInstance(); } - private NodeData toCompositeNodeData( QName key, NodeData... childData ) { + private NodeData toCompositeNodeData( final QName key, final NodeData... childData ) { return new NodeData( key, Lists.newArrayList( childData ) ); } - private NodeData toSimpleNodeData( QName key, Object value ) { + private NodeData toSimpleNodeData( final QName key, final Object value ) { return new NodeData( key, value ); } } -- 2.36.6