*/
public Optional<InstanceIdentifier<? extends DataObject>> 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
private Optional<InstanceIdentifier<? extends DataObject>> toBindingAugmented(
final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
+ throws DeserializationException {
Optional<InstanceIdentifier<? extends DataObject>> potential = toBindingImpl(normalized);
// Shorthand check, if codec already supports deserialization
// of AugmentationIdentifier we will return
// 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.<PathArgument> 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);
private Optional<InstanceIdentifier<? extends DataObject>> toBindingImpl(
final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
+ throws DeserializationException {
org.opendaylight.yangtools.yang.data.api.InstanceIdentifier legacyPath;
try {
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);
public Optional<Entry<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject>, DataObject>> toBinding(
final Entry<org.opendaylight.yangtools.yang.data.api.InstanceIdentifier, ? extends NormalizedNode<?, ?>> normalized)
- throws DeserializationException {
+ throws DeserializationException {
Optional<InstanceIdentifier<? extends DataObject>> potentialPath = toBinding(normalized.getKey());
if (potentialPath.isPresent()) {
InstanceIdentifier<? extends DataObject> bindingPath = potentialPath.get();
try {
return ClassLoaderUtils.withClassLoader(method.getDeclaringClass().getClassLoader(),
new Supplier<Class>() {
- @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;
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;
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;
}
private static abstract class CompositeNodeNormalizationOperation<T extends PathArgument> extends
- DataNormalizationOperation<T> {
+ DataNormalizationOperation<T> {
protected CompositeNodeNormalizationOperation(final T identifier) {
super(identifier);
}
private static abstract class DataContainerNormalizationOperation<T extends PathArgument> extends
- CompositeNodeNormalizationOperation<T> {
+ CompositeNodeNormalizationOperation<T> {
private final DataNodeContainer schema;
private final Map<QName, DataNormalizationOperation<?>> byQName;
}
private static final class ListItemNormalization extends
- DataContainerNormalizationOperation<NodeIdentifierWithPredicates> {
+ DataContainerNormalizationOperation<NodeIdentifierWithPredicates> {
private final List<QName> keyDefinition;
}
private static abstract class MixinNormalizationOp<T extends PathArgument> extends
- CompositeNodeNormalizationOperation<T> {
+ CompositeNodeNormalizationOperation<T> {
protected MixinNormalizationOp(final T identifier) {
super(identifier);
private static class AnyXmlNormalization extends DataNormalizationOperation<NodeIdentifier> {
- 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<NodeIdentifier, Node<?>, AnyXmlNode> builder =
Builders.anyXmlBuilder().withNodeIdentifier(
- new NodeIdentifier( legacyData.getNodeType() ) );
+ new NodeIdentifier( legacyData.getNodeType() ) );
builder.withValue(legacyData);
return builder.build();
}
}
@Override
- public NormalizedNode<?, ?> createDefault( PathArgument currentArg ) {
+ public NormalizedNode<?, ?> createDefault( final PathArgument currentArg ) {
return null;
}
}
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) {
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;
ImmutableList.Builder<PathArgument> normalizedArgs = ImmutableList.builder();
DataNormalizationOperation<?> currentOp = operation;
- Iterator<PathArgument> arguments = legacy.getPath().iterator();
+ Iterator<PathArgument> arguments = legacy.getPathArguments().iterator();
try {
while (arguments.hasNext()) {
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<InstanceIdentifier, NormalizedNode<?, ?>> toNormalized(
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) {
if (potentialOp.getIdentifier() instanceof AugmentationIdentifier) {
currentOp = potentialOp;
- ArrayList<PathArgument> reworkedArgs = new ArrayList<>(normalizedPath.getPath());
- reworkedArgs.add(potentialOp.getIdentifier());
- normalizedPath = new InstanceIdentifier(reworkedArgs);
+ normalizedPath = normalizedPath.node(potentialOp.getIdentifier());
}
}
public InstanceIdentifier toLegacy(final InstanceIdentifier normalized) throws DataNormalizationException {
ImmutableList.Builder<PathArgument> 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) {
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;
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;
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;
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;
}
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());
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.
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);
Collections.sort(unorderdChildData, new Comparator<LegacyNodeData>() {
@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;
Collections.sort(unorderedChildNodes, new Comparator<Node<?>>() {
@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();
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);
}
}
- 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);
}
}
Entry<InstanceIdentifier, NormalizedNode<?, ?>> normalizedNodeEntry = normalizer
- .toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(new InstanceIdentifier(
+ .toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(InstanceIdentifier.create(
ImmutableList.<PathArgument> of(new NodeIdentifier(TEST_QNAME))), testBuilder.toInstance()));
verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME);
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
testBuilder.add(anyXmlLegacy);
Entry<InstanceIdentifier, NormalizedNode<?, ?>> normalizedNodeEntry = normalizer
- .toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(new InstanceIdentifier(
+ .toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(InstanceIdentifier.create(
ImmutableList.<PathArgument> of(new NodeIdentifier(TEST_QNAME))), testBuilder.toInstance()));
verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME);
testBuilder.add(outerContBuilder.toInstance());
Entry<InstanceIdentifier, NormalizedNode<?, ?>> normalizedNodeEntry = normalizer
- .toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(new InstanceIdentifier(
+ .toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(InstanceIdentifier.create(
ImmutableList.<PathArgument> of(new NodeIdentifier(TEST_QNAME))), testBuilder.toInstance()));
verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME);
expectContainerNode(TEST_QNAME, expectContainerNode(OUTER_CONTAINER_QNAME, expAugmentation)));
normalizedNodeEntry = normalizer.toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(
- 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,
}
Entry<InstanceIdentifier, NormalizedNode<?, ?>> normalizedNodeEntry = normalizer
- .toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(new InstanceIdentifier(
+ .toNormalized(new AbstractMap.SimpleEntry<InstanceIdentifier, CompositeNode>(InstanceIdentifier.create(
ImmutableList.<PathArgument> of(new NodeIdentifier(TEST_QNAME))), testBuilder.toInstance()));
verifyNormalizedInstanceIdentifier(normalizedNodeEntry.getKey(), TEST_QNAME);
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;
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)) {
}
}
- 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));
}
}
import com.google.common.util.concurrent.ListenableFuture;
public abstract class BackwardsCompatibleTransaction<T extends DOMDataReadTransaction> implements
- DataModificationTransaction, Delegator<T> {
+DataModificationTransaction, Delegator<T> {
private static final Logger LOG = LoggerFactory.getLogger(BackwardsCompatibleTransaction.class);
LOG.trace("write {}:{} ",store,normalizedPath);
try {
- List<PathArgument> currentArguments = new ArrayList<>();
- DataNormalizationOperation<?> currentOp = getNormalizer().getRootOperation();
- Iterator<PathArgument> 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<PathArgument> currentArguments = new ArrayList<>();
+ DataNormalizationOperation<?> currentOp = getNormalizer().getRootOperation();
+ Iterator<PathArgument> 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);
}
private SchemaContext schemaContext;
- public MountPointImpl(InstanceIdentifier path) {
+ public MountPointImpl(final InstanceIdentifier path) {
this.mountPath = path;
rpcs = new SchemaAwareRpcBroker(path.toString(),this);
dataReader = new DataBrokerImpl();
}
@Override
- public void publish(CompositeNode notification) {
+ public void publish(final CompositeNode notification) {
notificationRouter.publish(notification);
}
@Override
- public Registration<NotificationListener> addNotificationListener(QName notification, NotificationListener listener) {
+ public Registration<NotificationListener> 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<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(
- InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
+ final InstanceIdentifier path, final DataReader<InstanceIdentifier, CompositeNode> reader) {
return dataReader.registerOperationalReader(path, reader);
}
@Override
public Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(
- InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader) {
+ final InstanceIdentifier path, final DataReader<InstanceIdentifier, CompositeNode> 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);
}
}
@Override
- public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
+ public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(final QName rpc, final CompositeNode input) {
return rpcs.invokeRpc(rpc, input);
}
@Override
- public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
+ public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(final RpcRegistrationListener listener) {
return rpcs.addRpcRegistrationListener(listener);
}
@Override
- public ListenableFuture<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
+ public ListenableFuture<RpcResult<CompositeNode>> rpc(final QName type, final CompositeNode input) {
return rpcs.invokeRpc( type, input );
}
}
@Override
- public ListenerRegistration<DataChangeListener> registerDataChangeListener(InstanceIdentifier path,
- DataChangeListener listener) {
+ public ListenerRegistration<DataChangeListener> registerDataChangeListener(final InstanceIdentifier path,
+ final DataChangeListener listener) {
return dataReader.registerDataChangeListener(path, listener);
}
@Override
public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
- InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
+ final InstanceIdentifier path, final DataCommitHandler<InstanceIdentifier, CompositeNode> 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
}
}
@Override
- public void setSchemaContext(SchemaContext schemaContext) {
+ public void setSchemaContext(final SchemaContext schemaContext) {
this.schemaContext = schemaContext;
}
class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
-
-
- private InstanceIdentifier shortenPath(InstanceIdentifier path) {
+ private InstanceIdentifier shortenPath(final InstanceIdentifier path) {
InstanceIdentifier ret = null;
if(mountPath.contains(path)) {
List<PathArgument> 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;
}
@Override
- public CompositeNode readOperationalData(InstanceIdentifier path) {
+ public CompositeNode readOperationalData(final InstanceIdentifier path) {
InstanceIdentifier newPath = shortenPath(path);
if(newPath == null) {
return null;
@Override
public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
- RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
+ final RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
return dataReader.registerCommitHandlerListener(commitHandlerListener);
}
@Override
public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
- L listener) {
+ final L listener) {
return rpcs.registerRouteChangeListener(listener);
}
}
private RestCodec() {
}
- public static final Codec<Object, Object> from(TypeDefinition<?> typeDefinition, MountInstance mountPoint) {
+ public static final Codec<Object, Object> from(final TypeDefinition<?> typeDefinition, final MountInstance mountPoint) {
return new ObjectCodec(typeDefinition, mountPoint);
}
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);
@SuppressWarnings("unchecked")
@Override
- public Object deserialize(Object input) {
+ public Object deserialize(final Object input) {
try {
if (type instanceof IdentityrefTypeDefinition) {
if (input instanceof IdentityValuesDTO) {
}
}
} 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);
@SuppressWarnings("unchecked")
@Override
- public Object serialize(Object input) {
+ public Object serialize(final Object input) {
try {
if (type instanceof IdentityrefTypeDefinition) {
return identityrefCodec.serialize(input);
}
}
} 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);
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) {
public static class LeafrefCodecImpl implements LeafrefCodec<String> {
@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;
}
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<PathArgument> 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<Predicate> predicates = keyValuesToPredicateList(((NodeIdentifierWithPredicates) pathArgument)
}
@Override
- public InstanceIdentifier deserialize(IdentityValuesDTO data) {
+ public InstanceIdentifier deserialize(final IdentityValuesDTO data) {
List<PathArgument> result = new ArrayList<PathArgument>();
IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint);
}
}
- return result.isEmpty() ? null : new InstanceIdentifier(result);
+ return result.isEmpty() ? null : InstanceIdentifier.create(result);
}
- private List<Predicate> keyValuesToPredicateList(Map<QName, Object> keyValues) {
+ private List<Predicate> keyValuesToPredicateList(final Map<QName, Object> keyValues) {
List<Predicate> result = new ArrayList<>();
for (QName qName : keyValues.keySet()) {
Object value = keyValues.get(qName);
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());
}
}
}
- 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;
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);
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 {
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);
}
}
*/
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;
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;
}
*/
@Test
public void getDataWithSlashesBehindMountPoint() throws UnsupportedEncodingException, URISyntaxException,
- ParseException {
+ ParseException {
InstanceIdentifier awaitedInstanceIdentifier = prepareInstanceIdentifierForList();
when(
brokerFacade.readConfigurationDataBehindMountPoint(any(MountInstance.class),
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
}
- 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("^");
}
- 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("^");
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());
}
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("<module");
assertEquals("<module element is returned more then once", 2, split.length);
}
- private void validateModulesResponseXml(Response response) {
+ private void validateModulesResponseXml(final Response response) {
assertEquals(200, response.getStatus());
String responseBody = response.readEntity(String.class);
.find());
}
- private void validateModulesResponseJson(Response response) {
+ private void validateModulesResponseJson(final Response response) {
assertEquals(200, response.getStatus());
String responseBody = response.readEntity(String.class);
.find());
}
- private Matcher prepareJsonRegex(String module, String revision, String namespace, String searchIn) {
+ private Matcher prepareJsonRegex(final String module, final String revision, final String namespace, final String searchIn) {
StringBuilder regex = new StringBuilder();
regex.append("^");
}
- private Matcher prepareXmlRegex(String module, String revision, String namespace, String searchIn) {
+ private Matcher prepareXmlRegex(final String module, final String revision, final String namespace, final String searchIn) {
StringBuilder regex = new StringBuilder();
regex.append("^");
return ptrn.matcher(searchIn);
}
- private void prepareMockForModulesTest(ControllerContext mockedControllerContext) throws FileNotFoundException {
+ private void prepareMockForModulesTest(final ControllerContext mockedControllerContext) throws FileNotFoundException {
SchemaContext schemaContext = TestUtils.loadSchemaContext("/modules");
mockedControllerContext.setGlobalSchema(schemaContext);
// when(mockedControllerContext.getGlobalSchema()).thenReturn(schemaContext);
}
- private int get(String uri, String mediaType) {
+ private int get(final String uri, final String mediaType) {
return target(uri).request(mediaType).get().getStatus();
}
ControllerContext.getInstance().setGlobalSchema( schemaContextModules );
CompositeNode depth1Cont = toCompositeNode(
- toCompositeNodeData( toNestedQName( "depth1-cont" ),
- toCompositeNodeData( toNestedQName( "depth2-cont1" ),
- toCompositeNodeData( toNestedQName( "depth3-cont1" ),
- toCompositeNodeData( toNestedQName( "depth4-cont1" ),
- toSimpleNodeData( toNestedQName( "depth5-leaf1" ), "depth5-leaf1-value" )
- ),
- toSimpleNodeData( toNestedQName( "depth4-leaf1" ), "depth4-leaf1-value" )
- ),
- toSimpleNodeData( toNestedQName( "depth3-leaf1" ), "depth3-leaf1-value" )
- ),
- toCompositeNodeData( toNestedQName( "depth2-cont2" ),
- toCompositeNodeData( toNestedQName( "depth3-cont2" ),
- toCompositeNodeData( toNestedQName( "depth4-cont2" ),
- toSimpleNodeData( toNestedQName( "depth5-leaf2" ), "depth5-leaf2-value" )
- ),
- toSimpleNodeData( toNestedQName( "depth4-leaf2" ), "depth4-leaf2-value" )
- ),
- toSimpleNodeData( toNestedQName( "depth3-leaf2" ), "depth3-leaf2-value" )
- ),
- toSimpleNodeData( toNestedQName( "depth2-leaf1" ), "depth2-leaf1-value" )
- ) );
+ toCompositeNodeData( toNestedQName( "depth1-cont" ),
+ toCompositeNodeData( toNestedQName( "depth2-cont1" ),
+ toCompositeNodeData( toNestedQName( "depth3-cont1" ),
+ toCompositeNodeData( toNestedQName( "depth4-cont1" ),
+ toSimpleNodeData( toNestedQName( "depth5-leaf1" ), "depth5-leaf1-value" )
+ ),
+ toSimpleNodeData( toNestedQName( "depth4-leaf1" ), "depth4-leaf1-value" )
+ ),
+ toSimpleNodeData( toNestedQName( "depth3-leaf1" ), "depth3-leaf1-value" )
+ ),
+ toCompositeNodeData( toNestedQName( "depth2-cont2" ),
+ toCompositeNodeData( toNestedQName( "depth3-cont2" ),
+ toCompositeNodeData( toNestedQName( "depth4-cont2" ),
+ toSimpleNodeData( toNestedQName( "depth5-leaf2" ), "depth5-leaf2-value" )
+ ),
+ toSimpleNodeData( toNestedQName( "depth4-leaf2" ), "depth4-leaf2-value" )
+ ),
+ toSimpleNodeData( toNestedQName( "depth3-leaf2" ), "depth3-leaf2-value" )
+ ),
+ toSimpleNodeData( toNestedQName( "depth2-leaf1" ), "depth2-leaf1-value" )
+ ) );
when( brokerFacade.readConfigurationData( any( InstanceIdentifier.class ) ) )
- .thenReturn( depth1Cont );
+ .thenReturn( depth1Cont );
// Test config with depth 1
Response response = target( "/config/nested-module:depth1-cont" ).queryParam( "depth", "1" )
- .request( "application/xml" ).get();
+ .request( "application/xml" ).get();
verifyXMLResponse( response, expectEmptyContainer( "depth1-cont" ) );
// Test config with depth 2
response = target( "/config/nested-module:depth1-cont" ).queryParam( "depth", "2" )
- .request( "application/xml" ).get();
+ .request( "application/xml" ).get();
-// String xml="<depth1-cont><depth2-cont1/><depth2-cont2/><depth2-leaf1>depth2-leaf1-value</depth2-leaf1></depth1-cont>";
-// Response mr=mock(Response.class);
-// when(mr.getEntity()).thenReturn( new java.io.StringBufferInputStream(xml) );
+ // String xml="<depth1-cont><depth2-cont1/><depth2-cont2/><depth2-leaf1>depth2-leaf1-value</depth2-leaf1></depth1-cont>";
+ // Response mr=mock(Response.class);
+ // when(mr.getEntity()).thenReturn( new java.io.StringBufferInputStream(xml) );
verifyXMLResponse( response,
- expectContainer( "depth1-cont",
- expectEmptyContainer( "depth2-cont1" ),
- expectEmptyContainer( "depth2-cont2" ),
- expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
- ) );
+ expectContainer( "depth1-cont",
+ expectEmptyContainer( "depth2-cont1" ),
+ expectEmptyContainer( "depth2-cont2" ),
+ expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
+ ) );
// Test config with depth 3
response = target( "/config/nested-module:depth1-cont" ).queryParam( "depth", "3" )
- .request( "application/xml" ).get();
+ .request( "application/xml" ).get();
verifyXMLResponse( response,
- expectContainer( "depth1-cont",
- expectContainer( "depth2-cont1",
- expectEmptyContainer( "depth3-cont1" ),
- expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
- ),
- expectContainer( "depth2-cont2",
- expectEmptyContainer( "depth3-cont2" ),
- expectLeaf( "depth3-leaf2", "depth3-leaf2-value" )
- ),
- expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
- ) );
+ expectContainer( "depth1-cont",
+ expectContainer( "depth2-cont1",
+ expectEmptyContainer( "depth3-cont1" ),
+ expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
+ ),
+ expectContainer( "depth2-cont2",
+ expectEmptyContainer( "depth3-cont2" ),
+ expectLeaf( "depth3-leaf2", "depth3-leaf2-value" )
+ ),
+ expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
+ ) );
// Test config with depth 4
response = target( "/config/nested-module:depth1-cont" ).queryParam( "depth", "4" )
- .request( "application/xml" ).get();
+ .request( "application/xml" ).get();
verifyXMLResponse( response,
- expectContainer( "depth1-cont",
- expectContainer( "depth2-cont1",
- expectContainer( "depth3-cont1",
- expectEmptyContainer( "depth4-cont1" ),
- expectLeaf( "depth4-leaf1", "depth4-leaf1-value" )
- ),
- expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
- ),
- expectContainer( "depth2-cont2",
- expectContainer( "depth3-cont2",
- expectEmptyContainer( "depth4-cont2" ),
- expectLeaf( "depth4-leaf2", "depth4-leaf2-value" )
- ),
- expectLeaf( "depth3-leaf2", "depth3-leaf2-value" )
- ),
- expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
- ) );
+ expectContainer( "depth1-cont",
+ expectContainer( "depth2-cont1",
+ expectContainer( "depth3-cont1",
+ expectEmptyContainer( "depth4-cont1" ),
+ expectLeaf( "depth4-leaf1", "depth4-leaf1-value" )
+ ),
+ expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
+ ),
+ expectContainer( "depth2-cont2",
+ expectContainer( "depth3-cont2",
+ expectEmptyContainer( "depth4-cont2" ),
+ expectLeaf( "depth4-leaf2", "depth4-leaf2-value" )
+ ),
+ expectLeaf( "depth3-leaf2", "depth3-leaf2-value" )
+ ),
+ expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
+ ) );
// Test config with depth 5
response = target( "/config/nested-module:depth1-cont" ).queryParam( "depth", "5" )
- .request( "application/xml" ).get();
+ .request( "application/xml" ).get();
verifyXMLResponse( response,
- expectContainer( "depth1-cont",
- expectContainer( "depth2-cont1",
- expectContainer( "depth3-cont1",
- expectContainer( "depth4-cont1",
- expectLeaf( "depth5-leaf1", "depth5-leaf1-value" )
- ),
- expectLeaf( "depth4-leaf1", "depth4-leaf1-value" )
- ),
- expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
- ),
- expectContainer( "depth2-cont2",
- expectContainer( "depth3-cont2",
- expectContainer( "depth4-cont2",
- expectLeaf( "depth5-leaf2", "depth5-leaf2-value" )
- ),
- expectLeaf( "depth4-leaf2", "depth4-leaf2-value" )
- ),
- expectLeaf( "depth3-leaf2", "depth3-leaf2-value" )
- ),
- expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
- ) );
+ expectContainer( "depth1-cont",
+ expectContainer( "depth2-cont1",
+ expectContainer( "depth3-cont1",
+ expectContainer( "depth4-cont1",
+ expectLeaf( "depth5-leaf1", "depth5-leaf1-value" )
+ ),
+ expectLeaf( "depth4-leaf1", "depth4-leaf1-value" )
+ ),
+ expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
+ ),
+ expectContainer( "depth2-cont2",
+ expectContainer( "depth3-cont2",
+ expectContainer( "depth4-cont2",
+ expectLeaf( "depth5-leaf2", "depth5-leaf2-value" )
+ ),
+ expectLeaf( "depth4-leaf2", "depth4-leaf2-value" )
+ ),
+ expectLeaf( "depth3-leaf2", "depth3-leaf2-value" )
+ ),
+ expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
+ ) );
// Test config with depth unbounded
response = target( "/config/nested-module:depth1-cont" ).queryParam( "depth", "unbounded" )
- .request( "application/xml" ).get();
+ .request( "application/xml" ).get();
verifyXMLResponse( response,
- expectContainer( "depth1-cont",
- expectContainer( "depth2-cont1",
- expectContainer( "depth3-cont1",
- expectContainer( "depth4-cont1",
- expectLeaf( "depth5-leaf1", "depth5-leaf1-value" )
- ),
- expectLeaf( "depth4-leaf1", "depth4-leaf1-value" )
- ),
- expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
- ),
- expectContainer( "depth2-cont2",
- expectContainer( "depth3-cont2",
- expectContainer( "depth4-cont2",
- expectLeaf( "depth5-leaf2", "depth5-leaf2-value" )
- ),
- expectLeaf( "depth4-leaf2", "depth4-leaf2-value" )
- ),
- expectLeaf( "depth3-leaf2", "depth3-leaf2-value" )
- ),
- expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
- ) );
+ expectContainer( "depth1-cont",
+ expectContainer( "depth2-cont1",
+ expectContainer( "depth3-cont1",
+ expectContainer( "depth4-cont1",
+ expectLeaf( "depth5-leaf1", "depth5-leaf1-value" )
+ ),
+ expectLeaf( "depth4-leaf1", "depth4-leaf1-value" )
+ ),
+ expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
+ ),
+ expectContainer( "depth2-cont2",
+ expectContainer( "depth3-cont2",
+ expectContainer( "depth4-cont2",
+ expectLeaf( "depth5-leaf2", "depth5-leaf2-value" )
+ ),
+ expectLeaf( "depth4-leaf2", "depth4-leaf2-value" )
+ ),
+ expectLeaf( "depth3-leaf2", "depth3-leaf2-value" )
+ ),
+ expectLeaf( "depth2-leaf1", "depth2-leaf1-value" )
+ ) );
// Test operational
CompositeNode depth2Cont1 = toCompositeNode(
- toCompositeNodeData( toNestedQName( "depth2-cont1" ),
- toCompositeNodeData( toNestedQName( "depth3-cont1" ),
- toCompositeNodeData( toNestedQName( "depth4-cont1" ),
- toSimpleNodeData( toNestedQName( "depth5-leaf1" ), "depth5-leaf1-value" )
- ),
- toSimpleNodeData( toNestedQName( "depth4-leaf1" ), "depth4-leaf1-value" )
- ),
- toSimpleNodeData( toNestedQName( "depth3-leaf1" ), "depth3-leaf1-value" )
- ) );
+ toCompositeNodeData( toNestedQName( "depth2-cont1" ),
+ toCompositeNodeData( toNestedQName( "depth3-cont1" ),
+ toCompositeNodeData( toNestedQName( "depth4-cont1" ),
+ toSimpleNodeData( toNestedQName( "depth5-leaf1" ), "depth5-leaf1-value" )
+ ),
+ toSimpleNodeData( toNestedQName( "depth4-leaf1" ), "depth4-leaf1-value" )
+ ),
+ toSimpleNodeData( toNestedQName( "depth3-leaf1" ), "depth3-leaf1-value" )
+ ) );
when( brokerFacade.readOperationalData( any( InstanceIdentifier.class ) ) )
- .thenReturn( depth2Cont1 );
+ .thenReturn( depth2Cont1 );
response = target( "/operational/nested-module:depth1-cont/depth2-cont1" )
- .queryParam( "depth", "3" ).request( "application/xml" ).get();
+ .queryParam( "depth", "3" ).request( "application/xml" ).get();
verifyXMLResponse( response,
- expectContainer( "depth2-cont1",
- expectContainer( "depth3-cont1",
- expectEmptyContainer( "depth4-cont1" ),
- expectLeaf( "depth4-leaf1", "depth4-leaf1-value" )
- ),
- expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
- ) );
+ expectContainer( "depth2-cont1",
+ expectContainer( "depth3-cont1",
+ expectEmptyContainer( "depth4-cont1" ),
+ expectLeaf( "depth4-leaf1", "depth4-leaf1-value" )
+ ),
+ expectLeaf( "depth3-leaf1", "depth3-leaf1-value" )
+ ) );
}
@Test
paramMap.putSingle( "depth", "1o" );
UriInfo mockInfo = mock( UriInfo.class );
when( mockInfo.getQueryParameters( false ) ).thenAnswer(
- new Answer<MultivaluedMap<String,String>>() {
- @Override
- public MultivaluedMap<String, String> answer( InvocationOnMock invocation ) {
- return paramMap;
- }
- } );
+ new Answer<MultivaluedMap<String,String>>() {
+ @Override
+ public MultivaluedMap<String, String> answer( final InvocationOnMock invocation ) {
+ return paramMap;
+ }
+ } );
getDataWithInvalidDepthParameterTest( mockInfo );
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 );
}
@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;
}
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<ImmutableCompositeNode> builder = ImmutableCompositeNode.builder();
builder.setQName( (QName) nodeData.key );
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 );
}
}