*/
package org.opendaylight.controller.config.yangjmxgenerator;
-import java.net.URI;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
import org.opendaylight.yangtools.yang.common.QName;
public class ConfigConstants {
public static final QName RPC_CONTEXT_REF_GROUPING_LEAF = createRpcXQName("context-instance");
public static final QName RPC_CONTEXT_INSTANCE_EXTENSION_QNAME = createRpcXQName("rpc-context-instance");
- public static QName createConfigQName(String localName) {
- return createQName(CONFIG_NAMESPACE, "2013-04-05", localName);
+ public static QName createConfigQName(final String localName) {
+ // FIXME: pre-construct QNameModule
+ return QName.create(CONFIG_NAMESPACE, "2013-04-05", localName);
}
- public static QName createRpcXQName(String localName) {
- return createQName("urn:ietf:params:xml:ns:yang:rpc-context",
+ public static QName createRpcXQName(final String localName) {
+ // FIXME: pre-construct QNameModule
+ return QName.create("urn:ietf:params:xml:ns:yang:rpc-context",
"2013-06-17", localName);
}
-
- /**
- *
- * @param uri
- * @param revisionDate
- * in format yyyy-MM-dd
- * @param localName
- * @return
- */
- private static QName createQName(String uri, String revisionDate,
- String localName) {
- SimpleDateFormat revisionFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date revision;
- try {
- revision = revisionFormat.parse(revisionDate);
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- return new QName(URI.create(uri), revision, localName);
- }
-
}
import com.google.common.collect.Collections2;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import javax.annotation.Nullable;
+
import org.opendaylight.controller.config.yangjmxgenerator.attribute.AbstractDependencyAttribute;
import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute;
private TypeProviderWrapper typeProviderWrapper;
private String packageName;
- public ModuleMXBeanEntryBuilder setModule(Module module) {
+ public ModuleMXBeanEntryBuilder setModule(final Module module) {
this.currentModule = module;
return this;
}
- public ModuleMXBeanEntryBuilder setqNamesToSIEs(Map<QName, ServiceInterfaceEntry> qNamesToSIEs) {
+ public ModuleMXBeanEntryBuilder setqNamesToSIEs(final Map<QName, ServiceInterfaceEntry> qNamesToSIEs) {
this.qNamesToSIEs = qNamesToSIEs;
return this;
}
- public ModuleMXBeanEntryBuilder setSchemaContext(SchemaContext schemaContext) {
+ public ModuleMXBeanEntryBuilder setSchemaContext(final SchemaContext schemaContext) {
this.schemaContext = schemaContext;
return this;
}
- public ModuleMXBeanEntryBuilder setTypeProviderWrapper(TypeProviderWrapper typeProviderWrapper) {
+ public ModuleMXBeanEntryBuilder setTypeProviderWrapper(final TypeProviderWrapper typeProviderWrapper) {
this.typeProviderWrapper = typeProviderWrapper;
return this;
}
- public ModuleMXBeanEntryBuilder setPackageName(String packageName) {
+ public ModuleMXBeanEntryBuilder setPackageName(final String packageName) {
this.packageName = packageName;
return this;
}
return result;
}
- private static void cleanUpNulls(Map<String, ModuleMXBeanEntry> result) {
+ private static void cleanUpNulls(final Map<String, ModuleMXBeanEntry> result) {
for (Map.Entry<String, ModuleMXBeanEntry> entry : result.entrySet()) {
ModuleMXBeanEntry module = entry.getValue();
if (module.getAttributes() == null) {
}
}
- private static void checkUnaugumentedIdentities(Map<String, IdentitySchemaNode> unaugmentedModuleIdentities) {
+ private static void checkUnaugumentedIdentities(final Map<String, IdentitySchemaNode> unaugmentedModuleIdentities) {
if (unaugmentedModuleIdentities.size() > 0) {
logger.warn("Augmentation not found for all currentModule identities: {}",
unaugmentedModuleIdentities.keySet());
}
}
- private static void checkAttributeNamesUniqueness(Map<String, QName> uniqueGeneratedClassesNames, Map<String, ModuleMXBeanEntry> result) {
+ private static void checkAttributeNamesUniqueness(final Map<String, QName> uniqueGeneratedClassesNames, final Map<String, ModuleMXBeanEntry> result) {
for (Map.Entry<String, ModuleMXBeanEntry> entry : result.entrySet()) {
checkUniqueRuntimeBeanAttributesName(entry.getValue(),
uniqueGeneratedClassesNames);
return moduleIdentities;
}
- private Collection<ChoiceCaseNode> castChildNodesToChoiceCases(Set<DataSchemaNode> childNodes) {
+ private Collection<ChoiceCaseNode> castChildNodesToChoiceCases(final Set<DataSchemaNode> childNodes) {
return Collections2.transform(childNodes, new Function<DataSchemaNode, ChoiceCaseNode>() {
@Nullable
@Override
- public ChoiceCaseNode apply(@Nullable DataSchemaNode input) {
+ public ChoiceCaseNode apply(@Nullable final DataSchemaNode input) {
return (ChoiceCaseNode) input;
}
});
}
- private boolean areAllChildrenChoiceCaseNodes(Set<DataSchemaNode> childNodes) {
+ private boolean areAllChildrenChoiceCaseNodes(final Set<DataSchemaNode> childNodes) {
for (DataSchemaNode childNode : childNodes) {
- if (childNode instanceof ChoiceCaseNode == false)
+ if (childNode instanceof ChoiceCaseNode == false) {
return false;
+ }
}
return true;
}
- private <HAS_CHILDREN_AND_QNAME extends DataNodeContainer & SchemaNode> void processChoiceCaseNode(Map<String, ModuleMXBeanEntry> result,
- Map<String, QName> uniqueGeneratedClassesNames, String configModulePrefix,
- Map<String, IdentitySchemaNode> moduleIdentities,
- Map<String, IdentitySchemaNode> unaugmentedModuleIdentities, AugmentationSchema augmentation,
- DataSchemaNode when) {
+ private <HAS_CHILDREN_AND_QNAME extends DataNodeContainer & SchemaNode> void processChoiceCaseNode(final Map<String, ModuleMXBeanEntry> result,
+ final Map<String, QName> uniqueGeneratedClassesNames, final String configModulePrefix,
+ final Map<String, IdentitySchemaNode> moduleIdentities,
+ final Map<String, IdentitySchemaNode> unaugmentedModuleIdentities, final AugmentationSchema augmentation,
+ final DataSchemaNode when) {
ChoiceCaseNode choiceCaseNode = (ChoiceCaseNode) when;
if (choiceCaseNode.getConstraints() == null || choiceCaseNode.getConstraints().getWhenCondition() == null) {
}
checkState(Objects.equals(nullableDummyContainerName, moduleMXBeanEntry.getNullableDummyContainerName()),
"Mismatch in module " + moduleMXBeanEntry.toString() + " - dummy container must be present/missing in" +
- " both state and configuration");
+ " both state and configuration");
} else {
ModuleMXBeanEntry.ModuleMXBeanEntryInitial initial = new ModuleMXBeanEntry.ModuleMXBeanEntryInitialBuilder()
- .setIdSchemaNode(moduleIdentity).setPackageName(packageName).setJavaNamePrefix(javaNamePrefix)
- .setNamespace(currentModule.getNamespace().toString()).setqName(ModuleUtil.getQName(currentModule))
- .build();
+ .setIdSchemaNode(moduleIdentity).setPackageName(packageName).setJavaNamePrefix(javaNamePrefix)
+ .setNamespace(currentModule.getNamespace().toString()).setqName(ModuleUtil.getQName(currentModule))
+ .build();
// construct ModuleMXBeanEntry
ModuleMXBeanEntry moduleMXBeanEntry = new ModuleMXBeanEntry(initial, yangToAttributes, providedServices,
}
}
- private void checkUniqueRuntimeBeansGeneratedClasses(Map<String, QName> uniqueGeneratedClassesNames,
- DataSchemaNode when, Collection<RuntimeBeanEntry> runtimeBeans) {
+ private void checkUniqueRuntimeBeansGeneratedClasses(final Map<String, QName> uniqueGeneratedClassesNames,
+ final DataSchemaNode when, final Collection<RuntimeBeanEntry> runtimeBeans) {
for (RuntimeBeanEntry runtimeBean : runtimeBeans) {
final String javaNameOfRuntimeMXBean = runtimeBean.getJavaNameOfRuntimeMXBean();
if (uniqueGeneratedClassesNames.containsKey(javaNameOfRuntimeMXBean)) {
}
}
- private static void checkUniqueRuntimeBeanAttributesName(ModuleMXBeanEntry mxBeanEntry,
- Map<String, QName> uniqueGeneratedClassesNames) {
+ private static void checkUniqueRuntimeBeanAttributesName(final ModuleMXBeanEntry mxBeanEntry,
+ final Map<String, QName> uniqueGeneratedClassesNames) {
for (RuntimeBeanEntry runtimeBeanEntry : mxBeanEntry.getRuntimeBeans()) {
for (String runtimeAttName : runtimeBeanEntry.getYangPropertiesToTypesMap().keySet()) {
if (mxBeanEntry.getAttributes().keySet().contains(runtimeAttName)) {
}
}
- private void checkUniqueAttributesWithGeneratedClass(Map<String, QName> uniqueGeneratedClassNames,
- QName parentQName, Map<String, AttributeIfc> yangToAttributes) {
+ private void checkUniqueAttributesWithGeneratedClass(final Map<String, QName> uniqueGeneratedClassNames,
+ final QName parentQName, final Map<String, AttributeIfc> yangToAttributes) {
for (Map.Entry<String, AttributeIfc> attr : yangToAttributes.entrySet()) {
if (attr.getValue() instanceof TOAttribute) {
checkUniqueTOAttr(uniqueGeneratedClassNames, parentQName, (TOAttribute) attr.getValue());
}
}
- private void checkUniqueTOAttr(Map<String, QName> uniqueGeneratedClassNames, QName parentQName, TOAttribute attr) {
+ private void checkUniqueTOAttr(final Map<String, QName> uniqueGeneratedClassNames, final QName parentQName, final TOAttribute attr) {
final String upperCaseCamelCase = attr.getUpperCaseCammelCase();
if (uniqueGeneratedClassNames.containsKey(upperCaseCamelCase)) {
QName firstDefinedQName = uniqueGeneratedClassNames.get(upperCaseCamelCase);
}
}
- private Collection<RuntimeBeanEntry> fillRuntimeBeans(DataNodeContainer dataNodeContainer, Module currentModule,
- TypeProviderWrapper typeProviderWrapper, String packageName, String moduleLocalNameFromXPath,
- String javaNamePrefix) {
+ private Collection<RuntimeBeanEntry> fillRuntimeBeans(final DataNodeContainer dataNodeContainer, final Module currentModule,
+ final TypeProviderWrapper typeProviderWrapper, final String packageName, final String moduleLocalNameFromXPath,
+ final String javaNamePrefix) {
return RuntimeBeanEntry.extractClassNameToRuntimeBeanMap(packageName, dataNodeContainer, moduleLocalNameFromXPath,
typeProviderWrapper, javaNamePrefix, currentModule).values();
* @param choiceCaseNode state or configuration case statement
* @return either choiceCaseNode or its only child container
*/
- private <HAS_CHILDREN_AND_QNAME extends DataNodeContainer & SchemaNode> HAS_CHILDREN_AND_QNAME getDataNodeContainer(ChoiceCaseNode choiceCaseNode) {
+ private <HAS_CHILDREN_AND_QNAME extends DataNodeContainer & SchemaNode> HAS_CHILDREN_AND_QNAME getDataNodeContainer(final ChoiceCaseNode choiceCaseNode) {
Set<DataSchemaNode> childNodes = choiceCaseNode.getChildNodes();
if (childNodes.size() == 1) {
DataSchemaNode onlyChild = childNodes.iterator().next();
return (HAS_CHILDREN_AND_QNAME) choiceCaseNode;
}
- private Map<String, AttributeIfc> fillConfiguration(DataNodeContainer dataNodeContainer, Module currentModule,
- TypeProviderWrapper typeProviderWrapper, Map<QName, ServiceInterfaceEntry> qNamesToSIEs,
- SchemaContext schemaContext, String packageName) {
+ private Map<String, AttributeIfc> fillConfiguration(final DataNodeContainer dataNodeContainer, final Module currentModule,
+ final TypeProviderWrapper typeProviderWrapper, final Map<QName, ServiceInterfaceEntry> qNamesToSIEs,
+ final SchemaContext schemaContext, final String packageName) {
Map<String, AttributeIfc> yangToAttributes = new HashMap<>();
Set<DataSchemaNode> childNodes = dataNodeContainer.getChildNodes();
for (DataSchemaNode attrNode : childNodes) {
return yangToAttributes;
}
- private Map<String, QName> findProvidedServices(IdentitySchemaNode moduleIdentity, Module currentModule,
- Map<QName, ServiceInterfaceEntry> qNamesToSIEs, SchemaContext schemaContext) {
+ private Map<String, QName> findProvidedServices(final IdentitySchemaNode moduleIdentity, final Module currentModule,
+ final Map<QName, ServiceInterfaceEntry> qNamesToSIEs, final SchemaContext schemaContext) {
Map<String, QName> result = new HashMap<>();
for (UnknownSchemaNode unknownNode : moduleIdentity.getUnknownSchemaNodes()) {
if (ConfigConstants.PROVIDED_SERVICE_EXTENSION_QNAME.equals(unknownNode.getNodeType())) {
return result;
}
- private AttributeIfc getAttributeValue(DataSchemaNode attrNode, Module currentModule,
- Map<QName, ServiceInterfaceEntry> qNamesToSIEs, TypeProviderWrapper typeProviderWrapper,
- SchemaContext schemaContext, String packageName) {
+ private AttributeIfc getAttributeValue(final DataSchemaNode attrNode, final Module currentModule,
+ final Map<QName, ServiceInterfaceEntry> qNamesToSIEs, final TypeProviderWrapper typeProviderWrapper,
+ final SchemaContext schemaContext, final String packageName) {
if (attrNode instanceof LeafSchemaNode) {
// simple type
}
}
- private Optional<? extends AbstractDependencyAttribute> extractDependency(DataNodeContainer dataNodeContainer,
- DataSchemaNode attrNode, Module currentModule, Map<QName, ServiceInterfaceEntry> qNamesToSIEs,
- SchemaContext schemaContext) {
+ private Optional<? extends AbstractDependencyAttribute> extractDependency(final DataNodeContainer dataNodeContainer,
+ final DataSchemaNode attrNode, final Module currentModule, final Map<QName, ServiceInterfaceEntry> qNamesToSIEs,
+ final SchemaContext schemaContext) {
if (dataNodeContainer.getUses().size() == 1 && getChildNodeSizeWithoutUses(dataNodeContainer) == 0) {
// reference
UsesNode usesNode = dataNodeContainer.getUses().iterator().next();
return Optional.absent();
}
- private int getChildNodeSizeWithoutUses(DataNodeContainer csn) {
+ private int getChildNodeSizeWithoutUses(final DataNodeContainer csn) {
int result = 0;
for (DataSchemaNode dsn : csn.getChildNodes()) {
if (dsn.isAddedByUses() == false) {
return result;
}
- private ServiceInterfaceEntry findSIE(String prefixAndIdentityLocalName, Module currentModule,
- Map<QName, ServiceInterfaceEntry> qNamesToSIEs, SchemaContext schemaContext) {
+ private ServiceInterfaceEntry findSIE(final String prefixAndIdentityLocalName, final Module currentModule,
+ final Map<QName, ServiceInterfaceEntry> qNamesToSIEs, final SchemaContext schemaContext) {
Matcher m = PREFIX_COLON_LOCAL_NAME.matcher(prefixAndIdentityLocalName);
Module foundModule;
foundModule = currentModule; // no prefix => SIE is in currentModule
localSIName = prefixAndIdentityLocalName;
}
- QName siQName = new QName(foundModule.getNamespace(), foundModule.getRevision(), localSIName);
+ QName siQName = QName.create(foundModule.getNamespace(), foundModule.getRevision(), localSIName);
ServiceInterfaceEntry sie = qNamesToSIEs.get(siQName);
checkState(sie != null, "Cannot find referenced Service Interface by " + prefixAndIdentityLocalName);
return sie;
}
- private ModuleImport findModuleImport(Module module, String prefix) {
+ private ModuleImport findModuleImport(final Module module, final String prefix) {
for (ModuleImport moduleImport : module.getImports()) {
if (moduleImport.getPrefix().equals(prefix)) {
return moduleImport;
}
@VisibleForTesting
- static Matcher getWhenConditionMatcher(String prefix, RevisionAwareXPath whenConstraint) {
+ static Matcher getWhenConditionMatcher(final String prefix, final RevisionAwareXPath whenConstraint) {
String xpathRegex = MODULE_CONDITION_XPATH_TEMPLATE.replace(MAGIC_STRING, prefix);
Pattern pattern = Pattern.compile(xpathRegex);
return pattern.matcher(whenConstraint.toString());
}
- String getConfigModulePrefixFromImport(Module currentModule) {
+ String getConfigModulePrefixFromImport(final Module currentModule) {
for (ModuleImport currentImport : currentModule.getImports()) {
if (currentImport.getModuleName().equals(ConfigConstants.CONFIG_MODULE)) {
return currentImport.getPrefix();
public class ModuleUtil {
- public static QName getQName(Module currentModule){
- return new QName(currentModule.getNamespace(), currentModule.getRevision(), currentModule.getName());
+ public static QName getQName(final Module currentModule) {
+ return QName.create(currentModule.getNamespace(), currentModule.getRevision(), currentModule.getName());
}
}
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+
import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute;
private final Set<Rpc> rpcs;
@VisibleForTesting
- RuntimeBeanEntry(String packageName,
- DataNodeContainer nodeForReporting, String yangName,
- String javaNamePrefix, boolean isRoot,
- Optional<String> keyYangName, List<AttributeIfc> attributes,
- List<RuntimeBeanEntry> children, Set<Rpc> rpcs) {
+ RuntimeBeanEntry(final String packageName,
+ final DataNodeContainer nodeForReporting, final String yangName,
+ final String javaNamePrefix, final boolean isRoot,
+ final Optional<String> keyYangName, final List<AttributeIfc> attributes,
+ final List<RuntimeBeanEntry> children, final Set<Rpc> rpcs) {
checkArgument(isRoot == false || keyYangName.isPresent() == false,
"Root RuntimeBeanEntry must not have key " + "set");
for (AttributeIfc a : attributes) {
checkState(map.containsKey(a.getAttributeYangName()) == false,
"Attribute already defined: " + a.getAttributeYangName()
- + " in " + nodeForReporting);
+ + " in " + nodeForReporting);
map.put(a.getAttributeYangName(), a);
}
* not contain special configuration for it.
*/
public static Map<String, RuntimeBeanEntry> extractClassNameToRuntimeBeanMap(
- String packageName, DataNodeContainer container,
- String moduleYangName, TypeProviderWrapper typeProviderWrapper,
- String javaNamePrefix, Module currentModule) {
+ final String packageName, final DataNodeContainer container,
+ final String moduleYangName, final TypeProviderWrapper typeProviderWrapper,
+ final String javaNamePrefix, final Module currentModule) {
Map<QName, Set<RpcDefinition>> identitiesToRpcs = getIdentitiesToRpcs(currentModule);
}
private static Map<QName/* of identity */, Set<RpcDefinition>> getIdentitiesToRpcs(
- Module currentModule) {
+ final Module currentModule) {
// currently only looks for local identities (found in currentModule)
Map<QName, Set<RpcDefinition>> result = new HashMap<>();
for (IdentitySchemaNode identity : currentModule.getIdentities()) {
if (input != null) {
for (UsesNode uses : input.getUses()) {
- if (uses.getGroupingPath().getPath().size() != 1)
+ if (uses.getGroupingPath().getPath().size() != 1) {
continue;
+ }
// check grouping path
QName qname = uses.getGroupingPath().getPath().get(0);
if (false == qname
- .equals(ConfigConstants.RPC_CONTEXT_REF_GROUPING_QNAME))
+ .equals(ConfigConstants.RPC_CONTEXT_REF_GROUPING_QNAME)) {
continue;
+ }
for (SchemaNode refinedNode : uses.getRefines().values()) {
.equals(unknownSchemaNode.getNodeType())) {
String localIdentityName = unknownSchemaNode
.getNodeParameter();
- QName identityQName = new QName(
+ QName identityQName = QName.create(
currentModule.getNamespace(),
currentModule.getRevision(),
localIdentityName);
* in subtree.
*/
private static AttributesRpcsAndRuntimeBeans extractSubtree(
- String packageName, DataNodeContainer subtree,
- TypeProviderWrapper typeProviderWrapper, Module currentModule,
- Map<QName, Set<RpcDefinition>> identitiesToRpcs) {
+ final String packageName, final DataNodeContainer subtree,
+ final TypeProviderWrapper typeProviderWrapper, final Module currentModule,
+ final Map<QName, Set<RpcDefinition>> identitiesToRpcs) {
List<AttributeIfc> attributes = Lists.newArrayList();
// List<JavaAttribute> javaAttributes = new ArrayList<>();
if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME
.equals(unknownSchemaNode.getNodeType())) {
String localIdentityName = unknownSchemaNode.getNodeParameter();
- QName identityQName = new QName(currentModule.getNamespace(),
+ QName identityQName = QName.create(currentModule.getNamespace(),
currentModule.getRevision(), localIdentityName);
Set<RpcDefinition> rpcDefinitions = identitiesToRpcs
.get(identityQName);
for (DataSchemaNode childNode : sortAttributes(rpcDefinition.getInput()
.getChildNodes())) {
if (childNode.isAddedByUses() == false) { // skip
- // refined
- // context-instance
+ // refined
+ // context-instance
checkArgument(childNode instanceof LeafSchemaNode, "Unexpected type of rpc input type. "
+ "Currently only leafs and empty output nodes are supported, got " + childNode);
JavaAttribute javaAttribute = new JavaAttribute(
attributes, rpcs);
}
- private static AttributeIfc getReturnTypeAttribute(DataSchemaNode child, TypeProviderWrapper typeProviderWrapper,
- String packageName) {
+ private static AttributeIfc getReturnTypeAttribute(final DataSchemaNode child, final TypeProviderWrapper typeProviderWrapper,
+ final String packageName) {
if (child instanceof LeafSchemaNode) {
LeafSchemaNode leaf = (LeafSchemaNode) child;
return new JavaAttribute(leaf, typeProviderWrapper);
}
}
- private static Collection<DataSchemaNode> sortAttributes(Set<DataSchemaNode> childNodes) {
+ private static Collection<DataSchemaNode> sortAttributes(final Set<DataSchemaNode> childNodes) {
final TreeSet<DataSchemaNode> dataSchemaNodes = new TreeSet<>(new Comparator<DataSchemaNode>() {
@Override
- public int compare(DataSchemaNode o1, DataSchemaNode o2) {
+ public int compare(final DataSchemaNode o1, final DataSchemaNode o2) {
return o1.getQName().getLocalName().compareTo(o2.getQName().getLocalName());
}
});
return dataSchemaNodes;
}
- private static boolean isInnerStateBean(DataSchemaNode child) {
+ private static boolean isInnerStateBean(final DataSchemaNode child) {
for (UnknownSchemaNode unknownSchemaNode : child
.getUnknownSchemaNodes()) {
if (unknownSchemaNode.getNodeType().equals(
- ConfigConstants.INNER_STATE_BEAN_EXTENSION_QNAME))
+ ConfigConstants.INNER_STATE_BEAN_EXTENSION_QNAME)) {
return true;
+ }
}
return false;
}
- private static RuntimeBeanEntry createHierarchical(String packageName,
- ListSchemaNode listSchemaNode,
- TypeProviderWrapper typeProviderWrapper, Module currentModule,
- Map<QName, Set<RpcDefinition>> identitiesToRpcs) {
+ private static RuntimeBeanEntry createHierarchical(final String packageName,
+ final ListSchemaNode listSchemaNode,
+ final TypeProviderWrapper typeProviderWrapper, final Module currentModule,
+ final Map<QName, Set<RpcDefinition>> identitiesToRpcs) {
// supported are numeric types, strings, enums
// get all attributes
return rbFromAttributes;
}
- private static RuntimeBeanEntry createRoot(String packageName,
- DataNodeContainer nodeForReporting, String attributeYangName,
- List<AttributeIfc> attributes, String javaNamePrefix,
- List<RuntimeBeanEntry> children, Set<Rpc> rpcs) {
+ private static RuntimeBeanEntry createRoot(final String packageName,
+ final DataNodeContainer nodeForReporting, final String attributeYangName,
+ final List<AttributeIfc> attributes, final String javaNamePrefix,
+ final List<RuntimeBeanEntry> children, final Set<Rpc> rpcs) {
return new RuntimeBeanEntry(packageName, nodeForReporting,
attributeYangName, javaNamePrefix, true,
Optional.<String> absent(), attributes, children, rpcs);
private final Set<Rpc> rpcs;
public AttributesRpcsAndRuntimeBeans(
- List<RuntimeBeanEntry> runtimeBeanEntries,
- List<AttributeIfc> attributes, Set<Rpc> rpcs) {
+ final List<RuntimeBeanEntry> runtimeBeanEntries,
+ final List<AttributeIfc> attributes, final Set<Rpc> rpcs) {
this.runtimeBeanEntries = runtimeBeanEntries;
this.attributes = attributes;
this.rpcs = rpcs;
private final AttributeIfc returnType;
private final String yangName;
- Rpc(AttributeIfc returnType, String name, String yangName,
- List<JavaAttribute> parameters) {
+ Rpc(final AttributeIfc returnType, final String name, final String yangName,
+ final List<JavaAttribute> parameters) {
this.returnType = returnType;
this.name = name;
this.parameters = parameters;
return getJavaNameOfRuntimeMXBean(javaNamePrefix);
}
- public String getFullyQualifiedName(String typeName) {
+ public String getFullyQualifiedName(final String typeName) {
return FullyQualifiedNameHelper.getFullyQualifiedName(packageName,
typeName);
}
- private static String getJavaNameOfRuntimeMXBean(String javaNamePrefix) {
+ private static String getJavaNameOfRuntimeMXBean(final String javaNamePrefix) {
return javaNamePrefix + MXBEAN_SUFFIX;
}
*/
package org.opendaylight.controller.config.yangjmxgenerator;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
import com.google.common.collect.Sets;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.SimpleType;
+
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
-import javax.management.openmbean.ArrayType;
-import javax.management.openmbean.CompositeType;
-import javax.management.openmbean.SimpleType;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
public class ModuleMXBeanEntryTest extends AbstractYangTest {
public static final String PACKAGE_NAME = "pack2";
PACKAGE_NAME,identitiesToSIs));
Map<String /* identity local name */, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry
.create(jmxImplModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context))
- , PACKAGE_NAME);
+ , PACKAGE_NAME);
Map<String, AttributeIfc> attributes = namesToMBEs.get("impl-netconf")
.getAttributes();
assertThat(threadFactoryAttribute.getType().getName(), is("ObjectName"));
}
- private void assertCorrectAttributesSize(Map<String, ModuleMXBeanEntry> namesToMBEs, Map<String, AttributeIfc> attributes) {
+ private void assertCorrectAttributesSize(final Map<String, ModuleMXBeanEntry> namesToMBEs, final Map<String, AttributeIfc> attributes) {
assertEquals(14, attributes.size());
assertEquals(1, namesToMBEs.get("impl-netconf").getRuntimeBeans().size());
assertEquals(2, namesToMBEs.get("impl-netconf").getRuntimeBeans().iterator().next().getAttributes().size());
}
protected RuntimeBeanEntry findFirstByYangName(
- Collection<RuntimeBeanEntry> runtimeBeans, String yangName) {
+ final Collection<RuntimeBeanEntry> runtimeBeans, final String yangName) {
for (RuntimeBeanEntry rb : runtimeBeans) {
- if (yangName.equals(rb.getYangName()))
+ if (yangName.equals(rb.getYangName())) {
return rb;
+ }
}
throw new IllegalArgumentException("Yang name not found:" + yangName
+ " in " + runtimeBeans);
"/config:modules/config:module/config:type=\"threadpool-dynamic\"");
}
- private void assertMatches(String prefix, String input) {
+ private void assertMatches(final String prefix, final String input) {
RevisionAwareXPath whenConstraint = mock(RevisionAwareXPath.class);
doReturn(input).when(whenConstraint).toString();
Matcher output = ModuleMXBeanEntryBuilder.getWhenConditionMatcher(prefix,
is((Type) Types.typeForClass(Long.class)));
}
// check dependency on thread factory
- QName threadfactoryQName = new QName(THREADS_NAMESPACE,
+ QName threadfactoryQName = QName.create(THREADS_NAMESPACE,
THREADS_REVISION_DATE, "threadfactory");
ServiceInterfaceEntry threadFactorySIEntry = modulesToSIEs
.get(threadfactoryQName);
DataSchemaNode mockedDataSchemaNode = mock(DataSchemaNode.class);
doReturn(Collections.emptyList()).when(mockedDataSchemaNode)
- .getUnknownSchemaNodes();
+ .getUnknownSchemaNodes();
doReturn(threadfactoryQName).when(mockedDataSchemaNode).getQName();
AttributeIfc expectedDependencyAttribute = new DependencyAttribute(
mockedDataSchemaNode, threadFactorySIEntry,
assertThat(actualThreadFactory, is(expectedDependencyAttribute));
assertThat(
dynamicThreadPool
- .getFullyQualifiedName("DynamicThreadPoolModuleMXBean"),
+ .getFullyQualifiedName("DynamicThreadPoolModuleMXBean"),
is(PACKAGE_NAME + ".DynamicThreadPoolModuleMXBean"));
assertThat(dynamicThreadPool.getNullableDescription(),
is("threadpool-dynamic description"));
*/
package org.opendaylight.controller.config.yangjmxgenerator;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
import com.google.common.collect.Sets;
+
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
public class ServiceInterfaceEntryTest extends AbstractYangTest {
public static final String PACKAGE_NAME = "packages.sis";
}
}
- public static final QName EVENTBUS_QNAME = new QName(THREADS_NAMESPACE,
+ public static final QName EVENTBUS_QNAME = QName.create(THREADS_NAMESPACE,
THREADS_REVISION_DATE, "eventbus");
- public static final QName THREADFACTORY_QNAME = new QName(
+ public static final QName THREADFACTORY_QNAME = QName.create(
THREADS_NAMESPACE, THREADS_REVISION_DATE, "threadfactory");
- public static final QName THREADPOOL_QNAME = new QName(THREADS_NAMESPACE,
+ public static final QName THREADPOOL_QNAME = QName.create(THREADS_NAMESPACE,
THREADS_REVISION_DATE, "threadpool");
- public static final QName SCHEDULED_THREADPOOL_QNAME = new QName(
+ public static final QName SCHEDULED_THREADPOOL_QNAME = QName.create(
THREADS_NAMESPACE, THREADS_REVISION_DATE, "scheduled-threadpool");
- public static final QName SCHEDULED_EXECUTOR_SERVICE_QNAME = new QName(
+ public static final QName SCHEDULED_EXECUTOR_SERVICE_QNAME = QName.create(
THREADS_NAMESPACE, THREADS_REVISION_DATE,
"scheduled-executor-service");
public static final String SCHEDULED_THREADPOOL_INTERFACE_NAME = "ScheduledThreadPoolServiceInterface";
+ SCHEDULED_THREADPOOL_INTERFACE_NAME));
}
- static String trimInnerSpacesOrNull(String input) {
- if (input == null)
+ static String trimInnerSpacesOrNull(final String input) {
+ if (input == null) {
return null;
+ }
return input.replaceAll("\\s{2,}", " ");
}
}
*/
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);
}
}
import static com.google.common.base.Preconditions.checkArgument;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-
public class YangDataOperations {
public static CompositeNode merge(final DataSchemaNode schema,
}
@SuppressWarnings({ "unchecked", "rawtypes" })
final Map<Map<QName, Object>, CompositeNode> originalMap = YangDataUtils
- .toIndexMap((List) original, node.getKeyDefinition());
+ .toIndexMap((List) original, node.getKeyDefinition());
@SuppressWarnings({ "unchecked", "rawtypes" })
final Map<Map<QName, Object>, CompositeNode> modifiedMap = YangDataUtils
- .toIndexMap((List) modified, node.getKeyDefinition());
+ .toIndexMap((List) modified, node.getKeyDefinition());
final List<Node<?>> mergedNodes = new ArrayList<Node<?>>(
original.size() + modified.size());
modified.getNodeType()));
final List<Node<?>> mergedChildNodes = new ArrayList<Node<?>>(stored
- .getChildren().size() + modified.getChildren().size());
+ .getValue().size() + modified.getValue().size());
final Set<QName> toProcess = new HashSet<QName>(stored.keySet());
toProcess.addAll(modified.keySet());
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);
*/
package org.opendaylight.controller.sal.restconf.impl;
+import com.google.common.base.Preconditions;
+
import java.net.URI;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
-import com.google.common.base.Preconditions;
-
public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, SimpleNode<Object> {
private SimpleNode<Object> simpleNode;
private URI namespace;
private QName name;
- public SimpleNodeWrapper(String localName, Object value) {
+ public SimpleNodeWrapper(final String localName, final Object value) {
this.localName = Preconditions.checkNotNull(localName);
this.value = value;
}
- public SimpleNodeWrapper(URI namespace, String localName, Object value) {
+ public SimpleNodeWrapper(final URI namespace, final String localName, final Object value) {
this(localName, value);
this.namespace = namespace;
}
@Override
- public void setQname(QName name) {
+ public void setQname(final QName name) {
Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies.");
this.name = name;
}
}
@Override
- public void setNamespace(URI namespace) {
+ public void setNamespace(final URI namespace) {
Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies.");
this.namespace = namespace;
}
localName = null;
name = null;
}
- return (SimpleNode<Object>) simpleNode;
+ return simpleNode;
}
@Override
}
@Override
+ @Deprecated
public CompositeNode getParent() {
return unwrap().getParent();
}
}
@Override
+ @Deprecated
public ModifyAction getModificationAction() {
return unwrap().getModificationAction();
}
}
@Override
- public Object setValue(Object value) {
+ public Object setValue(final Object value) {
return unwrap().setValue(value);
}
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 );
}
}
package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
import com.google.common.collect.Maps;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
import org.opendaylight.controller.config.yangjmxgenerator.PackageTranslator;
import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
public class YangStoreSnapshotImpl implements YangStoreSnapshot {
private static final Logger logger = LoggerFactory.getLogger(YangStoreSnapshotImpl.class);
private final Map<String /* Namespace from yang file */,
- Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> moduleMXBeanEntryMap;
+ Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> moduleMXBeanEntryMap;
private final Map<QName, Map<String, ModuleMXBeanEntry>> qNamesToIdentitiesToModuleMXBeanEntries;
private final SchemaContext schemaContext;
- public YangStoreSnapshotImpl(SchemaContext resolveSchemaContext) {
+ public YangStoreSnapshotImpl(final SchemaContext resolveSchemaContext) {
logger.trace("Resolved modules:{}", resolveSchemaContext.getModules());
this.schemaContext = resolveSchemaContext;
// JMX generator
qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue());
} else {
throw new IllegalStateException("Cannot add two SIE with same qname "
- + sieEntry.getValue());
+ + sieEntry.getValue());
}
}
}
TypeProviderWrapper typeProviderWrapper = new TypeProviderWrapper(
new TypeProviderImpl(resolveSchemaContext));
- QName qName = new QName(module.getNamespace(), module.getRevision(), module.getName());
+ QName qName = QName.create(module.getNamespace(), module.getRevision(), module.getName());
Map<String /* MB identity local name */, ModuleMXBeanEntry> namesToMBEs =
Collections.unmodifiableMap(ModuleMXBeanEntry.create(module, qNamesToSIEs, resolveSchemaContext,
}
@Override
- public String getModuleSource(org.opendaylight.yangtools.yang.model.api.ModuleIdentifier moduleIdentifier) {
+ public String getModuleSource(final org.opendaylight.yangtools.yang.model.api.ModuleIdentifier moduleIdentifier) {
return schemaContext.getModuleSource(moduleIdentifier).get();
}
package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.matchers.JUnitMatchers;
-import org.opendaylight.controller.config.api.LookupRegistry;
-import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
-import org.opendaylight.yangtools.yang.common.QName;
import java.net.URI;
import java.text.ParseException;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.matchers.JUnitMatchers;
+import org.opendaylight.controller.config.api.LookupRegistry;
+import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
+import org.opendaylight.yangtools.yang.common.QName;
public class NetconfOperationServiceImplTest {
Assert.assertThat(
message,
JUnitMatchers
- .containsString("missing from config subsystem but present in yangstore: [(namespace?revision=1970-01-01)qname2]"));
+ .containsString("missing from config subsystem but present in yangstore: [(namespace?revision=1970-01-01)qname2]"));
Assert.assertThat(
message,
JUnitMatchers
- .containsString("All modules present in config: [(namespace?revision=1970-01-01)qname1]"));
+ .containsString("All modules present in config: [(namespace?revision=1970-01-01)qname1]"));
}
}
- private YangStoreSnapshot mockYangStoreSnapshot(String... qnames) {
+ private YangStoreSnapshot mockYangStoreSnapshot(final String... qnames) {
YangStoreSnapshot mock = mock(YangStoreSnapshot.class);
Map<String, Map<String, ModuleMXBeanEntry>> map = Maps.newHashMap();
return mock;
}
- private ModuleMXBeanEntry mockMBeanEntry(String qname) {
+ private ModuleMXBeanEntry mockMBeanEntry(final String qname) {
ModuleMXBeanEntry mock = mock(ModuleMXBeanEntry.class);
QName q = getQName(qname);
doReturn(q).when(mock).getYangModuleQName();
return mock;
}
- private QName getQName(String qname) {
- return new QName(URI.create("namespace"), date1970_01_01, qname);
+ private QName getQName(final String qname) {
+ return QName.create(URI.create("namespace"), date1970_01_01, qname);
}
- private LookupRegistry mockJmxClient(String... visibleQNames) {
+ private LookupRegistry mockJmxClient(final String... visibleQNames) {
LookupRegistry mock = mock(LookupRegistry.class);
Set<String> qnames = Sets.newHashSet();
for (String visibleQName : visibleQNames) {