import static com.google.common.base.Preconditions.checkNotNull;
import java.io.IOException;
-import java.util.*;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import javax.activation.UnsupportedDataTypeException;
import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.RestCodec;
+import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO;
+import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.IdentityValue;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.*;
-import org.opendaylight.yangtools.yang.model.api.*;
-import org.opendaylight.yangtools.yang.model.api.type.*;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.gson.stream.JsonWriter;
private final Set<LeafListSchemaNode> foundLeafLists = new HashSet<>();
private final Set<ListSchemaNode> foundLists = new HashSet<>();
+ private final Logger logger = LoggerFactory.getLogger(JsonMapper.class);
public void write(JsonWriter writer, CompositeNode data, DataNodeContainer schema) throws IOException {
Preconditions.checkNotNull(writer);
TypeDefinition<?> baseType = resolveBaseTypeFrom(type);
// TODO check InstanceIdentifierTypeDefinition,
- // IdentityrefTypeDefinition
if (baseType instanceof IdentityrefTypeDefinition) {
if (node.getValue() instanceof QName) {
- QName qName = (QName) node.getValue();
-
- ControllerContext contContext = ControllerContext.getInstance();
- String moduleName = contContext.findModuleByNamespace(qName.getNamespace());
-
- writer.value(moduleName + ":" + qName.getLocalName());
+ IdentityValuesDTO valueDTO = (IdentityValuesDTO) RestCodec.from(type).serialize(node.getValue());
+ IdentityValue valueFromDTO = valueDTO.getValuesWithNamespaces().get(0);
+ String moduleName = ControllerContext.getInstance().findModuleByNamespace(URI.create(valueFromDTO.getNamespace()));
+ writer.value(moduleName + ":" + valueFromDTO.getValue());
+ } else {
+ logger.debug("Value of " + baseType.getQName().getNamespace() + ":"
+ + baseType.getQName().getLocalName() + " is not instance of " + QName.class + " but is " + node.getValue().getClass());
+ writer.value(String.valueOf(node.getValue()));
}
-
} else if (baseType instanceof LeafrefTypeDefinition) {
ControllerContext contContext = ControllerContext.getInstance();
LeafSchemaNode lfSchemaNode = contContext.resolveTypeFromLeafref((LeafrefTypeDefinition) baseType, schema);
import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
import org.opendaylight.controller.sal.restconf.impl.EmptyNodeWrapper;
import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
+import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO;
import com.google.common.collect.Lists;
import com.google.gson.JsonElement;
}
private CompositeNodeWrapper createStructureWithRoot(String rootObjectName, JsonObject rootObject) {
- CompositeNodeWrapper firstNode = new CompositeNodeWrapper(getNamespaceFrom(rootObjectName),
- getLocalNameFrom(rootObjectName));
+ CompositeNodeWrapper firstNode = new CompositeNodeWrapper(getNamespaceFor(rootObjectName),
+ getLocalNameFor(rootObjectName));
for (Entry<String, JsonElement> childOfFirstNode : rootObject.entrySet()) {
addChildToParent(childOfFirstNode.getKey(), childOfFirstNode.getValue(), firstNode);
}
private void addChildToParent(String childName, JsonElement childType, CompositeNodeWrapper parent) {
if (childType.isJsonObject()) {
- CompositeNodeWrapper child = new CompositeNodeWrapper(getNamespaceFrom(childName),
- getLocalNameFrom(childName));
+ CompositeNodeWrapper child = new CompositeNodeWrapper(getNamespaceFor(childName),
+ getLocalNameFor(childName));
parent.addValue(child);
for (Entry<String, JsonElement> childOfChild : childType.getAsJsonObject().entrySet()) {
addChildToParent(childOfChild.getKey(), childOfChild.getValue(), child);
}
} else if (childType.isJsonArray()) {
if (childType.getAsJsonArray().size() == 1 && childType.getAsJsonArray().get(0).isJsonNull()) {
- parent.addValue(new EmptyNodeWrapper(getNamespaceFrom(childName), getLocalNameFrom(childName)));
+ parent.addValue(new EmptyNodeWrapper(getNamespaceFor(childName), getLocalNameFor(childName)));
} else {
for (JsonElement childOfChildType : childType.getAsJsonArray()) {
} else if (childType.isJsonPrimitive()) {
JsonPrimitive childPrimitive = childType.getAsJsonPrimitive();
String value = childPrimitive.getAsString();
- parent.addValue(new SimpleNodeWrapper(getNamespaceFrom(childName), getLocalNameFrom(childName), value));
+ parent.addValue(new SimpleNodeWrapper(getNamespaceFor(childName), getLocalNameFor(childName),
+ resolveValueOfElement(value)));
}
}
- private URI getNamespaceFrom(String jsonElementName) {
- int indexOfDelimeter = jsonElementName.lastIndexOf(':');
- if (indexOfDelimeter == -1) {
+ private URI getNamespaceFor(String jsonElementName) {
+ String[] moduleNameAndLocalName = jsonElementName.split(":");
+ if (moduleNameAndLocalName.length != 2) { // it is not "moduleName:localName"
return null;
}
- return URI.create(jsonElementName.substring(0, indexOfDelimeter));
+ return URI.create(moduleNameAndLocalName[0]);
}
- private String getLocalNameFrom(String jsonElementName) {
- int indexOfDelimeter = jsonElementName.lastIndexOf(':');
- if (indexOfDelimeter == -1) {
+ private String getLocalNameFor(String jsonElementName) {
+ String[] moduleNameAndLocalName = jsonElementName.split(":");
+ if (moduleNameAndLocalName.length != 2) { // it is not "moduleName:localName"
return jsonElementName;
}
- return jsonElementName.substring(indexOfDelimeter + 1, jsonElementName.length());
+ return moduleNameAndLocalName[1];
+ }
+
+ /**
+ * @param value
+ * value of json element
+ * @return if value is "moduleName:localName" then {@link IdentityValuesDTO} else
+ * the same string as parameter "value"
+ */
+ private Object resolveValueOfElement(String value) {
+ URI namespace = getNamespaceFor(value);
+ return namespace == null ? value : new IdentityValuesDTO(namespace.toString(), getLocalNameFor(value), null);
}
}
public class RestconfProvider implements BundleActivator, Provider, ServiceTrackerCustomizer<Broker, Broker> {
- public final static String NOT_INITALIZED_MSG = "Restcof is not initialized yet. Please try again later";
+ public final static String NOT_INITALIZED_MSG = "Restconf is not initialized yet. Please try again later";
private ListenerRegistration<SchemaServiceListener> listenerRegistration;
private ServiceTracker<Broker, Broker> brokerServiceTrancker;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.opendaylight.controller.sal.restconf.impl.RestCodec;
+import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO;
+import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.IdentityValue;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.Node;
TypeDefinition<?> baseType = resolveBaseTypeFrom(type);
- if (baseType instanceof IdentityrefTypeDefinition && node.getValue() instanceof QName) {
- QName value = (QName) node.getValue();
- element.setAttribute("xmlns:x", value.getNamespace().toString());
- element.setTextContent("x:" + value.getLocalName());
+ if (baseType instanceof IdentityrefTypeDefinition) {
+ if (node.getValue() instanceof QName) {
+ IdentityValuesDTO valueDTO = (IdentityValuesDTO) RestCodec.from(type).serialize(node.getValue());
+ IdentityValue value = valueDTO.getValuesWithNamespaces().get(0);
+ String prefix = "x";
+ if (value.getPrefix() != null && !value.getPrefix().isEmpty()) {
+ prefix = value.getPrefix();
+ }
+ element.setAttribute("xmlns:" + prefix, value.getNamespace());
+ element.setTextContent(prefix + ":" + value.getValue());
+ } else {
+ logger.debug("Value of " + baseType.getQName().getNamespace() + ":"
+ + baseType.getQName().getLocalName() + " is not instance of " + QName.class + " but is " + node.getValue().getClass());
+ element.setTextContent(String.valueOf(node.getValue()));
+ }
} else {
Object value = node.getValue();
if (value != null) {
import javax.xml.stream.events.XMLEvent;
import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
+import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO;
import org.opendaylight.controller.sal.restconf.impl.EmptyNodeWrapper;
import org.opendaylight.controller.sal.restconf.impl.NodeWrapper;
import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
return false;
}
+ private CompositeNodeWrapper resolveCompositeNodeFromStartElement(final StartElement startElement) {
+ checkArgument(startElement != null, "Start Element cannot be NULL!");
+ return new CompositeNodeWrapper(getNamespaceFor(startElement), getLocalNameFor(startElement));
+ }
+
private NodeWrapper<? extends Node<?>> resolveSimpleNodeFromStartElement(final StartElement startElement)
throws XMLStreamException {
checkArgument(startElement != null, "Start Element cannot be NULL!");
- String data = null;
+ String data = getValueOf(startElement);
+ if (data == null) {
+ return new EmptyNodeWrapper(getNamespaceFor(startElement), getLocalNameFor(startElement));
+ }
+ return new SimpleNodeWrapper(getNamespaceFor(startElement), getLocalNameFor(startElement),
+ resolveValueOfElement(data, startElement));
+ }
+ private String getValueOf(StartElement startElement) throws XMLStreamException {
+ String data = null;
if (eventReader.hasNext()) {
final XMLEvent innerEvent = eventReader.peek();
if (innerEvent.isCharacters()) {
}
}
}
- if(data == null) {
- return new EmptyNodeWrapper(getNamespaceFrom(startElement), getLocalNameFrom(startElement));
- }
- return new SimpleNodeWrapper(getNamespaceFrom(startElement), getLocalNameFrom(startElement), data);
+ return data;
}
- private CompositeNodeWrapper resolveCompositeNodeFromStartElement(final StartElement startElement) {
- checkArgument(startElement != null, "Start Element cannot be NULL!");
- return new CompositeNodeWrapper(getNamespaceFrom(startElement), getLocalNameFrom(startElement));
- }
-
- private String getLocalNameFrom(StartElement startElement) {
+ private String getLocalNameFor(StartElement startElement) {
return startElement.getName().getLocalPart();
}
- private URI getNamespaceFrom(StartElement startElement) {
+ private URI getNamespaceFor(StartElement startElement) {
String namespaceURI = startElement.getName().getNamespaceURI();
return namespaceURI.isEmpty() ? null : URI.create(namespaceURI);
}
+ /**
+ * @param value
+ * value of startElement
+ * @param startElement
+ * element containing value
+ * @return if value is "prefix:value" then {@link IdentityValuesDTO} else the same
+ * string as parameter "value"
+ */
+ private Object resolveValueOfElement(String value, StartElement startElement) {
+ String[] namespaceAndValue = value.split(":");
+ if (namespaceAndValue.length != 2) { // it is not "prefix:value"
+ return value;
+ }
+ String namespace = startElement.getNamespaceContext().getNamespaceURI(namespaceAndValue[0]);
+ if (namespace != null && !namespace.isEmpty()) {
+ return new IdentityValuesDTO(namespace, namespaceAndValue[1], namespaceAndValue[0]);
+ }
+ return value;
+ }
+
}
package org.opendaylight.controller.sal.restconf.impl
import com.google.common.collect.BiMap
+import com.google.common.collect.FluentIterable
import com.google.common.collect.HashBiMap
import java.net.URI
import java.net.URLDecoder
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument
+import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode
import org.opendaylight.yangtools.yang.model.api.ChoiceNode
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
import org.opendaylight.yangtools.yang.model.api.RpcDefinition
import org.opendaylight.yangtools.yang.model.api.SchemaContext
import org.opendaylight.yangtools.yang.model.api.SchemaNode
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil
+import org.slf4j.LoggerFactory
import static com.google.common.base.Preconditions.*
-import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec
-import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition
-import org.slf4j.LoggerFactory
-import com.google.common.collect.FluentIterable
class ControllerContext implements SchemaServiceListener {
val static LOG = LoggerFactory.getLogger(ControllerContext)
return getLatestModule(startModule)
}
- private def getLatestModule(String moduleName) {
+ def getLatestModule(String moduleName) {
checkPreconditions
checkArgument(moduleName !== null && !moduleName.empty)
val modules = schemas.modules.filter[m|m.name == moduleName]
var module = uriToModuleName.get(namespace)
if (module === null) {
val moduleSchemas = schemas.findModuleByNamespace(namespace);
- if(moduleSchemas === null) throw new IllegalArgumentException()
+ if(moduleSchemas === null) return null
var latestModule = moduleSchemas.head
for (m : moduleSchemas) {
if (m.revision.after(latestModule.revision)) {
latestModule = m
}
}
- if(latestModule === null) throw new IllegalArgumentException()
+ if(latestModule === null) return null
uriToModuleName.put(namespace, latestModule.name)
module = latestModule.name;
}
return module
}
+ def findNamespaceByModule(String module) {
+ var namespace = moduleNameToUri.get(module)
+ if (namespace === null) {
+ val moduleSchemas = schemas.modules.filter[it|it.name.equals(module)]
+ var latestModule = moduleSchemas.head
+ for (m : moduleSchemas) {
+ if (m.revision.after(latestModule.revision)) {
+ latestModule = m
+ }
+ }
+ if(latestModule === null) return null
+ namespace = latestModule.namespace
+ uriToModuleName.put(namespace, latestModule.name)
+ }
+ return namespace
+ }
+
def CharSequence toRestconfIdentifier(QName qname) {
checkPreconditions
var module = uriToModuleName.get(qname.namespace)
val typedef = (node as LeafSchemaNode).type;
var decoded = TypeDefinitionAwareCodec.from(typedef)?.deserialize(urlDecoded)
- if(decoded == null) {
+ if(decoded === null) {
var baseType = typedef
- while (baseType.baseType != null) {
+ while (baseType.baseType !== null) {
baseType = baseType.baseType;
}
if(baseType instanceof IdentityrefTypeDefinition) {
--- /dev/null
+package org.opendaylight.controller.sal.restconf.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public final class IdentityValuesDTO {
+
+ private final List<IdentityValue> elementData = new ArrayList<>();
+
+ public IdentityValuesDTO(String namespace, String value, String prefix) {
+ elementData.add(new IdentityValue(namespace, value, prefix));
+ }
+
+ public void add(String namespace, String value, String prefix) {
+ elementData.add(new IdentityValue(namespace, value, prefix));
+ }
+
+ public List<IdentityValue> getValuesWithNamespaces() {
+ return Collections.unmodifiableList(elementData);
+ }
+
+ public static final class IdentityValue {
+
+ private String namespace;
+ private String value;
+ private String prefix;
+
+ public IdentityValue(String namespace, String value, String prefix) {
+ this.namespace = namespace;
+ this.value = value;
+ this.prefix = prefix;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ }
+}
--- /dev/null
+package org.opendaylight.controller.sal.restconf.impl;
+
+import java.net.URI;
+
+import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.IdentityValue;
+import org.opendaylight.yangtools.concepts.Codec;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.codec.IdentityrefCodec;
+import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+
+public class RestCodec {
+
+ @SuppressWarnings("rawtypes")
+ public static final Codec IDENTITYREF_DEFAULT_CODEC = new IdentityrefCodecImpl();
+
+ private RestCodec() {
+ }
+
+ public static final Codec<Object, Object> from(TypeDefinition<?> typeDefinition) {
+ return new ObjectCodec(typeDefinition);
+ }
+
+ public static final class ObjectCodec implements Codec<Object, Object> {
+
+ private TypeDefinition<?> type;
+
+ private ObjectCodec(TypeDefinition<?> typeDefinition) {
+ type = typeDefinition;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object deserialize(Object input) {
+ if (type instanceof IdentityrefTypeDefinition) {
+ return IDENTITYREF_DEFAULT_CODEC.deserialize(input);
+ } else {
+ return TypeDefinitionAwareCodec.from(type).deserialize(String.valueOf(input));
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object serialize(Object input) {
+ if (type instanceof IdentityrefTypeDefinition) {
+ return IDENTITYREF_DEFAULT_CODEC.serialize(input);
+ } else {
+ return TypeDefinitionAwareCodec.from(type).serialize(input);
+ }
+ }
+
+ }
+
+ public static class IdentityrefCodecImpl implements IdentityrefCodec<IdentityValuesDTO> {
+
+ @Override
+ public IdentityValuesDTO serialize(QName data) {
+ return new IdentityValuesDTO(data.getNamespace().toString(), data.getLocalName(), data.getPrefix());
+ }
+
+ @Override
+ public QName deserialize(IdentityValuesDTO data) {
+ IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
+ String namespace = valueWithNamespace.getNamespace();
+ URI validNamespace = ControllerContext.getInstance().findNamespaceByModule(namespace);
+ if (validNamespace == null) {
+ validNamespace = URI.create(namespace);
+ }
+ return QName.create(validNamespace, null, valueWithNamespace.getValue());
+ }
+
+ }
+
+}
import org.opendaylight.yangtools.yang.data.api.CompositeNode
import org.opendaylight.yangtools.yang.data.api.Node
import org.opendaylight.yangtools.yang.data.impl.NodeFactory
-import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec
import org.opendaylight.yangtools.yang.model.api.ChoiceNode
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
import org.opendaylight.yangtools.yang.model.api.TypeDefinition
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition
import static javax.ws.rs.core.Response.Status.*
}
val moduleName = controllerContext.findModuleByNamespace(validQName.namespace);
if (nodeBuilder.namespace === null || nodeBuilder.namespace == validQName.namespace ||
- nodeBuilder.namespace.path == moduleName) {
+ nodeBuilder.namespace.toString == moduleName) {
nodeBuilder.qname = validQName
} else {
throw new ResponseException(BAD_REQUEST,
}
} else if (nodeBuilder instanceof SimpleNodeWrapper) {
val simpleNode = (nodeBuilder as SimpleNodeWrapper)
- val stringValue = simpleNode.value as String;
-
- val objectValue = TypeDefinitionAwareCodec.from(schema.typeDefinition)?.deserialize(stringValue);
- simpleNode.setValue(objectValue)
+ val value = simpleNode.value
+ var inputValue = value;
+
+ if (schema.typeDefinition instanceof IdentityrefTypeDefinition) {
+ if (value instanceof String) {
+ inputValue = new IdentityValuesDTO(validQName.namespace.toString, value as String, null)
+ } // else value is instance of ValuesDTO
+ }
+
+ val outputValue = RestCodec.from(schema.typeDefinition)?.deserialize(inputValue);
+ simpleNode.setValue(outputValue)
} else if (nodeBuilder instanceof EmptyNodeWrapper) {
val emptyNodeBuilder = nodeBuilder as EmptyNodeWrapper
if (schema instanceof LeafSchemaNode) {
}
private def dispatch TypeDefinition<?> typeDefinition(LeafSchemaNode node) {
- node.type
+ var baseType = node.type
+ while (baseType.baseType !== null) {
+ baseType = baseType.baseType;
+ }
+ baseType
}
private def dispatch TypeDefinition<?> typeDefinition(LeafListSchemaNode node) {
- node.type
+ var TypeDefinition<?> baseType = node.type
+ while (baseType.baseType !== null) {
+ baseType = baseType.baseType;
+ }
+ baseType
}
private def DataSchemaNode findFirstSchemaByLocalName(String localName, Set<DataSchemaNode> schemas) {
public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, SimpleNode<Object> {
- private SimpleNode<?> simpleNode;
+ private SimpleNode<Object> simpleNode;
private String localName;
private Object value;
this.value = value;
}
- public SimpleNodeWrapper(URI namespace, String localName, String value) {
+ public SimpleNodeWrapper(URI namespace, String localName, Object value) {
this(localName, value);
this.namespace = namespace;
}
--- /dev/null
+package org.opendaylight.controller.sal.restconf.impl.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringWriter;
+import java.util.Set;
+
+import javax.activation.UnsupportedDataTypeException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.rest.impl.XmlMapper;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
+import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.w3c.dom.Document;
+
+public class CnSnToXmlTest {
+
+ private static Set<Module> modules;
+ private static DataSchemaNode dataSchemaNode;
+
+ @BeforeClass
+ public static void initialization() {
+ modules = TestUtils.resolveModules("/cnsn-to-xml/identityref");
+ assertEquals(2, modules.size());
+ Module module = TestUtils.resolveModule("identityref-module", modules);
+ assertNotNull(module);
+ dataSchemaNode = TestUtils.resolveDataSchemaNode(module, "cont");
+ assertNotNull(dataSchemaNode);
+
+ }
+
+ @Test
+ public void compositeNodeToXMLTest() {
+ XmlMapper xmlMapper = new XmlMapper();
+ String xmlString = null;
+ if (dataSchemaNode instanceof DataNodeContainer) {
+ try {
+ Document doc = xmlMapper.write(prepareData(), (DataNodeContainer) dataSchemaNode);
+ DOMSource domSource = new DOMSource(doc);
+ StringWriter writer = new StringWriter();
+ StreamResult result = new StreamResult(writer);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer transformer = tf.newTransformer();
+ transformer.transform(domSource, result);
+ xmlString = writer.toString();
+
+ } catch (UnsupportedDataTypeException | TransformerException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ assertNotNull(xmlString);
+ assertTrue(xmlString.contains("<lf1 xmlns:x=\"identity:module\">x:iden</lf1>"));
+
+ }
+
+ private CompositeNode prepareData() {
+ MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
+ TestUtils.buildQName("cont", "identityref:module", "2013-12-2"), null, null, ModifyAction.CREATE, null);
+ MutableCompositeNode cont1 = NodeFactory
+ .createMutableCompositeNode(TestUtils.buildQName("cont1", "identityref:module", "2013-12-2"), cont,
+ null, ModifyAction.CREATE, null);
+ cont.getChildren().add(cont1);
+
+ MutableSimpleNode<Object> lf11 = NodeFactory.createMutableSimpleNode(
+ TestUtils.buildQName("lf1", "identityref:module", "2013-12-2"), cont1,
+ TestUtils.buildQName("iden", "identity:module", "2013-12-2"), ModifyAction.CREATE, null);
+ cont1.getChildren().add(lf11);
+ cont1.init();
+ cont.init();
+
+ return cont;
+ }
+
+}
--- /dev/null
+package org.opendaylight.controller.sal.restconf.impl.test;
+
+import static org.junit.Assert.*;
+
+import java.io.*;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
+import org.opendaylight.controller.sal.restconf.impl.*;
+import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.JsonSyntaxException;
+
+public class JsonToCnSnTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(JsonToCnSnTest.class);
+
+ @Test
+ public void simpleListTest() {
+ simpleTest("/json-to-cnsn/simple-list.json", "/json-to-cnsn/simple-list-yang", "lst", "simple:list:yang1",
+ "simple-list-yang1");
+ }
+
+ @Test
+ public void simpleContainerTest() {
+ simpleTest("/json-to-cnsn/simple-container.json", "/json-to-cnsn/simple-container-yang", "cont",
+ "simple:container:yang", "simple-container-yang");
+ }
+
+ /**
+ * test if for every leaf list item is simple node instance created
+ */
+ @Test
+ public void multipleItemsInLeafList() {
+ CompositeNode compositeNode = compositeContainerFromJson("/json-to-cnsn/multiple-leaflist-items.json", true);
+ assertNotNull(compositeNode);
+ assertEquals(3, compositeNode.getChildren().size());
+
+ boolean lflst1_1 = false;
+ boolean lflst1_2 = false;
+ boolean lflst1_3 = false;
+
+ for (Node<?> node : compositeNode.getChildren()) {
+ assertEquals("lflst1", node.getNodeType().getLocalName());
+ assertTrue(node instanceof SimpleNode<?>);
+ SimpleNode<?> simpleNode = (SimpleNode<?>) node;
+ if (simpleNode.getValue().equals("45")) {
+ lflst1_1 = true;
+ } else if (simpleNode.getValue().equals("55")) {
+ lflst1_2 = true;
+ } else if (simpleNode.getValue().equals("66")) {
+ lflst1_3 = true;
+ }
+ }
+
+ assertTrue(lflst1_1);
+ assertTrue(lflst1_2);
+ assertTrue(lflst1_3);
+
+ }
+
+ /**
+ * List contains 4 items and in every item are other elements. It is
+ * supposed that there should be: lf11, lflst11, cont11, lst11
+ */
+ @Test
+ public void multipleItemsInListTest() {
+ CompositeNode compositeNode = compositeContainerFromJson("/json-to-cnsn/multiple-items-in-list.json", true);
+ assertNotNull(compositeNode);
+
+ assertEquals("lst", compositeNode.getNodeType().getLocalName());
+
+ verityMultipleItemsInList(compositeNode);
+ }
+
+ @Test
+ public void nullArrayToSimpleNodeWithNullValueTest() {
+ CompositeNode compositeNode = compositeContainerFromJson("/json-to-cnsn/array-with-null.json", true);
+ assertNotNull(compositeNode);
+ assertEquals("cont", compositeNode.getNodeType().getLocalName());
+
+ assertNotNull(compositeNode.getChildren());
+ assertEquals(1, compositeNode.getChildren().size());
+ Node<?> lfNode = compositeNode.getChildren().iterator().next();
+
+ assertTrue(lfNode instanceof SimpleNode<?>);
+ assertEquals(null, ((SimpleNode<?>) lfNode).getValue());
+
+ }
+
+ @Test
+ public void incorrectTopLevelElementsTest() {
+ Throwable cause1 = null;
+ try {
+ compositeContainerFromJson("/json-to-cnsn/wrong-top-level1.json", true);
+ } catch (WebApplicationException e) {
+ cause1 = e;
+ }
+
+ assertNotNull(cause1);
+ assertTrue(cause1
+ .getCause()
+ .getMessage()
+ .contains(
+ "First element in Json Object has to be \"Object\" or \"Array with one Object element\". Other scenarios are not supported yet."));
+
+ Throwable cause2 = null;
+ try {
+ compositeContainerFromJson("/json-to-cnsn/wrong-top-level2.json", true);
+ } catch (WebApplicationException e) {
+ cause2 = e;
+ }
+ assertNotNull(cause2);
+ assertTrue(cause2.getCause().getMessage().contains("Json Object should contain one element"));
+
+ Throwable cause3 = null;
+ try {
+ compositeContainerFromJson("/json-to-cnsn/wrong-top-level3.json", true);
+ } catch (WebApplicationException e) {
+ cause3 = e;
+ }
+ assertNotNull(cause3);
+ assertTrue(cause3
+ .getCause()
+ .getMessage()
+ .contains(
+ "First element in Json Object has to be \"Object\" or \"Array with one Object element\". Other scenarios are not supported yet."));
+
+ }
+
+ /**
+ * if leaf list with no data is in json then no corresponding data is
+ * created in composite node. if leaf with no data then exception is raised
+ */
+ @Test
+ public void emptyDataReadTest() {
+ CompositeNode compositeNode = compositeContainerFromJson("/json-to-cnsn/empty-data.json", true);
+
+ assertNotNull(compositeNode);
+
+ assertEquals("cont", compositeNode.getNodeType().getLocalName());
+ assertTrue(compositeNode instanceof CompositeNode);
+ List<Node<?>> children = ((CompositeNode) compositeNode).getChildren();
+ assertEquals(1, children.size());
+ assertEquals("lflst2", children.get(0).getNodeType().getLocalName());
+ assertEquals("45", children.get(0).getValue());
+
+ String reason = null;
+ try {
+ compositeContainerFromJson("/json-to-cnsn/empty-data1.json", true);
+ } catch (JsonSyntaxException e) {
+ reason = e.getMessage();
+ }
+
+ assertTrue(reason.contains("Expected value at line"));
+
+ }
+
+ /**
+ * Tests whether namespace <b>stay unchanged</b> if concrete values are
+ * present in composite or simple node and if the method for update is
+ * called.
+ *
+ */
+ @Test
+ public void notSupplyNamespaceIfAlreadySupplied() {
+
+ CompositeNode compositeNode = compositeContainerFromJson("/json-to-cnsn/simple-list.json");
+ assertNotNull(compositeNode);
+
+ DataSchemaNode dataSchemaNode1 = null;
+ DataSchemaNode dataSchemaNode2 = null;
+ try {
+ dataSchemaNode1 = TestUtils.obtainSchemaFromYang("/json-to-cnsn/simple-list-yang", "simple-list-yang1");
+ dataSchemaNode2 = TestUtils.obtainSchemaFromYang("/json-to-cnsn/simple-list-yang", "simple-list-yang2");
+ } catch (FileNotFoundException e) {
+ LOG.error(e.getMessage());
+ assertTrue(false);
+ }
+ assertNotNull(dataSchemaNode1);
+ assertNotNull(dataSchemaNode2);
+
+ // supplement namespaces according to first data schema -
+ // "simple:data:types1"
+ TestUtils.supplementNamespace(dataSchemaNode1, compositeNode);
+
+ assertTrue(compositeNode instanceof CompositeNodeWrapper);
+ CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap();
+
+ assertEquals("lst", compNode.getNodeType().getLocalName());
+ verifyCompositeNode(compNode, "simple:list:yang1");
+
+ // dataSchemaNode2 should't be taken into account, because compNode
+ // isn't CompositeNodeWrapper
+ TestUtils.supplementNamespace(dataSchemaNode2, compNode);
+ verifyCompositeNode(compNode, "simple:list:yang1");
+
+ }
+
+ @Test
+ public void jsonIdentityrefToCompositeNode() {
+ CompositeNode compositeNode = compositeContainerFromJson("/json-to-cnsn/identityref/json/data.json");
+ assertNotNull(compositeNode);
+
+ Set<Module> modules = TestUtils.resolveModules("/json-to-cnsn/identityref");
+ assertEquals(2, modules.size());
+ Module module = TestUtils.resolveModule("identityref-module", modules);
+ assertNotNull(module);
+ DataSchemaNode dataSchemaNode = TestUtils.resolveDataSchemaNode(module, null);
+ assertNotNull(dataSchemaNode);
+
+ RestconfImpl restconf = RestconfImpl.getInstance();
+ ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext(modules));
+
+ TestUtils.prepareMockForRestconfBeforeNormalization(modules, dataSchemaNode, restconf);
+
+ restconf.createConfigurationData("identityref-module:cont", compositeNode);
+
+ assertEquals("cont", compositeNode.getNodeType().getLocalName());
+
+ List<Node<?>> childs = compositeNode.getChildren();
+ assertEquals(1, childs.size());
+ Node<?> nd = childs.iterator().next();
+ assertTrue(nd instanceof CompositeNode);
+ assertEquals("cont1", nd.getNodeType().getLocalName());
+
+ childs = ((CompositeNode) nd).getChildren();
+ assertEquals(4, childs.size());
+ SimpleNode<?> lf11 = null;
+ SimpleNode<?> lf12 = null;
+ SimpleNode<?> lf13 = null;
+ SimpleNode<?> lf14 = null;
+ for (Node<?> child : childs) {
+ assertTrue(child instanceof SimpleNode);
+ if (child.getNodeType().getLocalName().equals("lf11")) {
+ lf11 = (SimpleNode<?>) child;
+ } else if (child.getNodeType().getLocalName().equals("lf12")) {
+ lf12 = (SimpleNode<?>) child;
+ } else if (child.getNodeType().getLocalName().equals("lf13")) {
+ lf13 = (SimpleNode<?>) child;
+ } else if (child.getNodeType().getLocalName().equals("lf14")) {
+ lf14 = (SimpleNode<?>) child;
+ }
+ }
+
+ assertTrue(lf11.getValue() instanceof QName);
+ assertEquals("iden", ((QName) lf11.getValue()).getLocalName());
+ assertEquals("identity:module", ((QName) lf11.getValue()).getNamespace().toString());
+
+ assertTrue(lf12.getValue() instanceof QName);
+ assertEquals("iden_local", ((QName) lf12.getValue()).getLocalName());
+ assertEquals("identityref:module", ((QName) lf12.getValue()).getNamespace().toString());
+
+ assertTrue(lf13.getValue() instanceof QName);
+ assertEquals("iden_local", ((QName) lf13.getValue()).getLocalName());
+ assertEquals("identityref:module", ((QName) lf13.getValue()).getNamespace().toString());
+
+ assertTrue(lf14.getValue() instanceof QName);
+ assertEquals("iden_local", ((QName) lf14.getValue()).getLocalName());
+ assertEquals("identity:module", ((QName) lf14.getValue()).getNamespace().toString());
+ }
+
+ private void simpleTest(String jsonPath, String yangPath, String topLevelElementName, String namespace,
+ String moduleName) {
+ CompositeNode compositeNode = compositeContainerFromJson(jsonPath);
+ assertNotNull(compositeNode);
+
+ DataSchemaNode dataSchemaNode = null;
+ try {
+ dataSchemaNode = TestUtils.obtainSchemaFromYang(yangPath, moduleName);
+ } catch (FileNotFoundException e) {
+ LOG.error(e.getMessage());
+ assertTrue(false);
+ }
+ assertNotNull(dataSchemaNode);
+
+ TestUtils.supplementNamespace(dataSchemaNode, compositeNode);
+
+ assertTrue(compositeNode instanceof CompositeNodeWrapper);
+ CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap();
+
+ assertEquals(topLevelElementName, compNode.getNodeType().getLocalName());
+ verifyCompositeNode(compNode, namespace);
+ }
+
+ private void verityMultipleItemsInList(CompositeNode compositeNode) {
+ List<Node<?>> childrenNodes = compositeNode.getChildren();
+ assertEquals(4, childrenNodes.size());
+ boolean lf11Found = false;
+ boolean cont11Found = false;
+ boolean lst11Found = false;
+ for (Node<?> lst1Item : childrenNodes) {
+ assertEquals("lst1", lst1Item.getNodeType().getLocalName());
+ assertTrue(lst1Item instanceof CompositeNode);
+
+ List<Node<?>> childrenLst1 = ((CompositeNode) lst1Item).getChildren();
+ assertEquals(1, childrenLst1.size());
+ String localName = childrenLst1.get(0).getNodeType().getLocalName();
+ if (localName.equals("lf11")) {
+ assertTrue(childrenLst1.get(0) instanceof SimpleNode);
+ lf11Found = true;
+ } else if (localName.equals("lflst11")) {
+ assertTrue(childrenLst1.get(0) instanceof SimpleNode);
+ assertEquals("45", ((SimpleNode<?>) childrenLst1.get(0)).getValue());
+ lf11Found = true;
+ } else if (localName.equals("cont11")) {
+ assertTrue(childrenLst1.get(0) instanceof CompositeNode);
+ cont11Found = true;
+ } else if (localName.equals("lst11")) {
+ lst11Found = true;
+ assertTrue(childrenLst1.get(0) instanceof CompositeNode);
+ assertEquals(0, ((CompositeNode) childrenLst1.get(0)).getChildren().size());
+ }
+
+ }
+ assertTrue(lf11Found);
+ assertTrue(cont11Found);
+ assertTrue(lst11Found);
+ }
+
+ private void verifyCompositeNode(CompositeNode compositeNode, String namespace) {
+ boolean cont1Found = false;
+ boolean lst1Found = false;
+ boolean lflst1_1Found = false;
+ boolean lflst1_2Found = false;
+ boolean lf1Found = false;
+
+ assertEquals(namespace, compositeNode.getNodeType().getNamespace().toString());
+
+ for (Node<?> node : compositeNode.getChildren()) {
+ if (node.getNodeType().getLocalName().equals("cont1")) {
+ if (node instanceof CompositeNode) {
+ cont1Found = true;
+ assertEquals(0, ((CompositeNode) node).getChildren().size());
+ }
+ } else if (node.getNodeType().getLocalName().equals("lst1")) {
+ if (node instanceof CompositeNode) {
+ lst1Found = true;
+ assertEquals(0, ((CompositeNode) node).getChildren().size());
+ }
+ } else if (node.getNodeType().getLocalName().equals("lflst1")) {
+ if (node instanceof SimpleNode) {
+ if (((SimpleNode<?>) node).getValue().equals("lflst1_1")) {
+ lflst1_1Found = true;
+ } else if (((SimpleNode<?>) node).getValue().equals("lflst1_2")) {
+ lflst1_2Found = true;
+ }
+ }
+
+ } else if (node.getNodeType().getLocalName().equals("lf1")) {
+ if (node instanceof SimpleNode) {
+ if (((SimpleNode<?>) node).getValue().equals("lf1")) {
+ lf1Found = true;
+ }
+ }
+ }
+ assertEquals(namespace, node.getNodeType().getNamespace().toString());
+ }
+ assertTrue(cont1Found);
+ assertTrue(lst1Found);
+ assertTrue(lflst1_1Found);
+ assertTrue(lflst1_2Found);
+ assertTrue(lf1Found);
+ }
+
+ private CompositeNode compositeContainerFromJson(String jsonPath) {
+ return compositeContainerFromJson(jsonPath, false);
+ }
+
+ private CompositeNode compositeContainerFromJson(String jsonPath, boolean dummyNamespaces)
+ throws WebApplicationException {
+
+ JsonToCompositeNodeProvider jsonToCompositeNodeProvider = JsonToCompositeNodeProvider.INSTANCE;
+ InputStream jsonStream = JsonToCnSnTest.class.getResourceAsStream(jsonPath);
+ try {
+ CompositeNode compositeNode = jsonToCompositeNodeProvider
+ .readFrom(null, null, null, null, null, jsonStream);
+ assertTrue(compositeNode instanceof CompositeNodeWrapper);
+ if (dummyNamespaces) {
+ try {
+ TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) compositeNode);
+ return ((CompositeNodeWrapper) compositeNode).unwrap();
+ } catch (URISyntaxException e) {
+ LOG.error(e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+ }
+ return compositeNode;
+ } catch (IOException e) {
+ LOG.error(e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+ return null;
+ }
+
+}
}
}
}
+
+ public static void prepareMockForRestconfBeforeNormalization(Set<Module> modules, DataSchemaNode dataSchemaNode,
+ RestconfImpl restconf) {
+ ControllerContext instance = ControllerContext.getInstance();
+ instance.setSchemas(TestUtils.loadSchemaContext(modules));
+ restconf.setControllerContext(ControllerContext.getInstance());
+
+ BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
+ when(mockedBrokerFacade.commitConfigurationDataPut(any(InstanceIdentifier.class), any(CompositeNode.class)))
+ .thenReturn(
+ new DummyFuture.Builder().rpcResult(
+ new DummyRpcResult.Builder<TransactionStatus>().result(TransactionStatus.COMMITED)
+ .build()).build());
+ restconf.setBroker(mockedBrokerFacade);
+ }
}
assertEquals("bit3", jReader.nextString());
bitsChecked = true;
} else if (keyName.equals("lfbinary")) {
- assertEquals("AAaacdabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%%-#^", jReader.nextString());
+ assertEquals("AAaacdabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", jReader.nextString());
lfbinaryChecked = true;
} else if (keyName.equals("lfempty")) {
jReader.beginArray();
import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.util.regex.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.ws.rs.WebApplicationException;
import org.junit.*;
+import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
+import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
import org.opendaylight.yangtools.yang.data.api.*;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
dataLoad("/yang-to-json-conversion/identityref", 2, "identityref-module", "cont");
}
+ @Ignore
@Test
public void identityrefToJsonTest() {
String json = null;
private CompositeNode prepareCompositeNode() {
MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
ModifyAction.CREATE, null);
- MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont,
+ MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont1"), cont, null,
+ ModifyAction.CREATE, null);
+ cont.getChildren().add(cont1);
+
+ MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont1,
TestUtils.buildQName("name_test", "identityref:module", "2013-12-2"), ModifyAction.CREATE, null);
- cont.getChildren().add(lf1);
+ cont1.getChildren().add(lf1);
+ cont1.init();
cont.init();
return cont;
--- /dev/null
+package org.opendaylight.controller.sal.restconf.impl.test;
+
+import static org.junit.Assert.*;
+
+import java.io.*;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
+import org.opendaylight.controller.sal.restconf.impl.*;
+import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class XmlToCnSnTest {
+ private static final Logger LOG = LoggerFactory.getLogger(XmlToCnSnTest.class);
+
+ /**
+ * top level element represents container. second level element is list with
+ * two elements.
+ */
+ @Test
+ public void testXmlDataContainer() {
+ CompositeNode compNode = compositeNodeFromXml("/xml-to-cnsn/data-container.xml", false);
+ assertNotNull(compNode);
+ DataSchemaNode dataSchemaNode = null;
+ try {
+ dataSchemaNode = TestUtils.obtainSchemaFromYang("/xml-to-cnsn/data-container-yang");
+ } catch (FileNotFoundException e) {
+ LOG.error(e.getMessage());
+ assertTrue(false);
+ }
+
+ assertNotNull(dataSchemaNode);
+ TestUtils.supplementNamespace(dataSchemaNode, compNode);
+
+ String nameSpace = "data:container:yang";
+ assertEquals(nameSpace, compNode.getNodeType().getNamespace().toString());
+
+ verifyNullAndEmptyStringSingleNode(compNode, nameSpace);
+ verifyCommonPartAOfXml(compNode, "", nameSpace);
+ }
+
+ private void verifyNullAndEmptyStringSingleNode(CompositeNode compNode, String nameSpace) {
+ assertEquals("cont", compNode.getNodeType().getLocalName());
+
+ SimpleNode<?> lf2 = null;
+ SimpleNode<?> lf3 = null;
+ int found = 0;
+ for (Node<?> child : compNode.getChildren()) {
+ if (found == 0x3)
+ break;
+ if (child instanceof SimpleNode<?>) {
+ SimpleNode<?> childSimple = (SimpleNode<?>) child;
+ if (childSimple.getNodeType().getLocalName().equals("lf3")) {
+ lf3 = childSimple;
+ found = found | (1 << 0);
+ } else if (childSimple.getNodeType().getLocalName().equals("lf2")) {
+ lf2 = childSimple;
+ found = found | (1 << 1);
+ }
+ }
+ assertEquals(nameSpace, child.getNodeType().getNamespace().toString());
+ }
+
+ assertEquals("", lf2.getValue());
+ assertEquals(null, lf3.getValue());
+ }
+
+ @Test
+ public void testXmlDataList() {
+ CompositeNode compNode = compositeNodeFromXml("/xml-to-cnsn/data-list.xml", false);
+ assertNotNull(compNode);
+
+ DataSchemaNode dataSchemaNode = null;
+ try {
+ dataSchemaNode = TestUtils.obtainSchemaFromYang("/xml-to-cnsn/data-list-yang", "data-container-yang");
+ } catch (FileNotFoundException e) {
+ LOG.error(e.getMessage());
+ }
+ assertNotNull(dataSchemaNode);
+ TestUtils.supplementNamespace(dataSchemaNode, compNode);
+
+ String nameSpaceList = "data:list:yang";
+ String nameSpaceCont = "data:container:yang";
+ assertEquals(nameSpaceCont, compNode.getNodeType().getNamespace().toString());
+ assertEquals("cont", compNode.getNodeType().getLocalName());
+ assertEquals(3, compNode.getChildren().size());
+ CompositeNode lst1_1 = null;
+ CompositeNode lst1_2 = null;
+ int loopCount = 0;
+ for (Node<?> node : compNode.getChildren()) {
+ if (node.getNodeType().getLocalName().equals("lf1")) {
+ assertEquals(nameSpaceList, node.getNodeType().getNamespace().toString());
+ assertTrue(node instanceof SimpleNode<?>);
+ assertEquals("lf1", node.getValue());
+ } else {
+ assertTrue(node instanceof CompositeNode);
+ switch (loopCount++) {
+ case 0:
+ lst1_1 = (CompositeNode) node;
+ break;
+ case 1:
+ lst1_2 = (CompositeNode) node;
+ break;
+ }
+ assertEquals(nameSpaceCont, node.getNodeType().getNamespace().toString());
+ }
+ }
+ // lst1_1
+ verifyCommonPartAOfXml(lst1_1, "1", nameSpaceCont);
+ // :lst1_1
+
+ // lst1_2
+ SimpleNode<?> lflst11 = null;
+ CompositeNode cont11 = null;
+ for (Node<?> node : lst1_2.getChildren()) {
+ String nodeName = node.getNodeType().getLocalName();
+ if (nodeName.equals("lflst11")) {
+ assertTrue(node instanceof SimpleNode<?>);
+ lflst11 = (SimpleNode<?>) node;
+
+ } else if (nodeName.equals("cont11")) {
+ assertTrue(node instanceof CompositeNode);
+ cont11 = (CompositeNode) node;
+ }
+ assertEquals(nameSpaceCont, compNode.getNodeType().getNamespace().toString());
+ }
+ assertEquals("221", lflst11.getValue());
+
+ assertEquals(1, cont11.getChildren().size());
+ assertTrue(cont11.getChildren().get(0) instanceof SimpleNode<?>);
+ SimpleNode<?> cont11_lf111 = (SimpleNode<?>) cont11.getChildren().get(0);
+ assertEquals(nameSpaceCont, cont11_lf111.getNodeType().getNamespace().toString());
+ assertEquals("lf111", cont11_lf111.getNodeType().getLocalName());
+ assertEquals((short) 100, cont11_lf111.getValue());
+ // :lst1_2
+
+ }
+
+ @Test
+ public void testXmlEmptyData() {
+ CompositeNode compNode = compositeNodeFromXml("/xml-to-cnsn/empty-data.xml", true);
+ assertEquals("cont", compNode.getNodeType().getLocalName());
+ SimpleNode<?> lf1 = null;
+ SimpleNode<?> lflst1_1 = null;
+ SimpleNode<?> lflst1_2 = null;
+ CompositeNode lst1 = null;
+ int lflst1Count = 0;
+ for (Node<?> node : compNode.getChildren()) {
+ if (node.getNodeType().getLocalName().equals("lf1")) {
+ assertTrue(node instanceof SimpleNode<?>);
+ lf1 = (SimpleNode<?>) node;
+ } else if (node.getNodeType().getLocalName().equals("lflst1")) {
+ assertTrue(node instanceof SimpleNode<?>);
+
+ switch (lflst1Count++) {
+ case 0:
+ lflst1_1 = (SimpleNode<?>) node;
+ break;
+ case 1:
+ lflst1_2 = (SimpleNode<?>) node;
+ break;
+ }
+ } else if (node.getNodeType().getLocalName().equals("lst1")) {
+ assertTrue(node instanceof CompositeNode);
+ lst1 = (CompositeNode) node;
+ }
+ }
+
+ assertNotNull(lf1);
+ assertNotNull(lflst1_1);
+ assertNotNull(lflst1_2);
+ assertNotNull(lst1);
+
+ assertEquals("", lf1.getValue());
+ assertEquals("", lflst1_1.getValue());
+ assertEquals("", lflst1_2.getValue());
+ assertEquals(1, lst1.getChildren().size());
+ assertEquals("lf11", lst1.getChildren().get(0).getNodeType().getLocalName());
+
+ assertTrue(lst1.getChildren().get(0) instanceof SimpleNode<?>);
+ assertEquals("", lst1.getChildren().get(0).getValue());
+
+ }
+
+ /**
+ * Test case like this <lf11 xmlns:x="namespace">x:identity</lf11>
+ */
+ @Test
+ public void testIdentityrefNmspcInElement() {
+ testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-nmspc-in-element.xml", "/xml-to-cnsn/identityref",
+ "identityref-module", "cont", 2, "iden", "identity:module");
+ }
+
+ /**
+ *
+ * Test case like <lf11 xmlns="namespace1"
+ * xmlns:x="namespace">identity</lf11>
+ */
+
+ @Test
+ public void testIdentityrefDefaultNmspcInElement() {
+ testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-default-nmspc-in-element.xml",
+ "/xml-to-cnsn/identityref/yang-augments", "general-module", "cont", 3, "iden", "identityref:module");
+ }
+
+ /**
+ *
+ * Test case like <cont1 xmlns="namespace1"> <lf11
+ * xmlns:x="namespace">identity</lf11> </cont1>
+ */
+ @Test
+ public void testIdentityrefDefaultNmspcInParrentElement() {
+ testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-default-nmspc-in-parrent-element.xml",
+ "/xml-to-cnsn/identityref", "identityref-module", "cont", 2, "iden", "identityref:module");
+ }
+
+ /**
+ *
+ * Test case like <cont1 xmlns="namespace1" xmlns:x="namespace">
+ * <lf11>x:identity</lf11> </cont1>
+ */
+ @Test
+ public void testIdentityrefNmspcInParrentElement() {
+ testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-nmspc-in-parrent-element.xml",
+ "/xml-to-cnsn/identityref", "identityref-module", "cont", 2, "iden", "z:namespace");
+
+ }
+
+ /**
+ *
+ * Test case like (without namespace in xml) <cont1> <lf11>x:identity</lf11>
+ * </cont1>
+ */
+ @Test
+ public void testIdentityrefNoNmspcValueWithPrefix() {
+ testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-no-nmspc-value-with-prefix.xml",
+ "/xml-to-cnsn/identityref", "identityref-module", "cont", 2, "x:iden", "identityref:module");
+ }
+
+ /**
+ *
+ * Test case like (without namespace in xml) <cont1> <lf11>identity</lf11>
+ * </cont1>
+ */
+ @Test
+ public void testIdentityrefNoNmspcValueWithoutPrefix() {
+ testIdentityrefToCnSn("/xml-to-cnsn/identityref/xml/data-no-nmspc-value-without-prefix.xml",
+ "/xml-to-cnsn/identityref", "identityref-module", "cont", 2, "iden", "identityref:module");
+ }
+
+ private void verifyCommonPartAOfXml(CompositeNode compNode, String suf, String nameSpace) {
+ SimpleNode<?> lf1suf = null;
+ SimpleNode<?> lflst1suf_1 = null;
+ SimpleNode<?> lflst1suf_2 = null;
+ SimpleNode<?> lflst1suf_3 = null;
+ CompositeNode cont1suf = null;
+ CompositeNode lst1suf = null;
+
+ int lflstCount = 0;
+
+ for (Node<?> node : compNode.getChildren()) {
+ String localName = node.getNodeType().getLocalName();
+ if (localName.equals("lf1" + suf)) {
+ assertTrue(node instanceof SimpleNode<?>);
+ lf1suf = (SimpleNode<?>) node;
+ } else if (localName.equals("lflst1" + suf)) {
+ assertTrue(node instanceof SimpleNode<?>);
+ switch (lflstCount++) {
+ case 0:
+ lflst1suf_1 = (SimpleNode<?>) node;
+ break;
+ case 1:
+ lflst1suf_2 = (SimpleNode<?>) node;
+ break;
+ case 2:
+ lflst1suf_3 = (SimpleNode<?>) node;
+ break;
+ }
+ } else if (localName.equals("lst1" + suf)) {
+ assertTrue(node instanceof CompositeNode);
+ lst1suf = (CompositeNode) node;
+ } else if (localName.equals("cont1" + suf)) {
+ assertTrue(node instanceof CompositeNode);
+ cont1suf = (CompositeNode) node;
+ }
+ assertEquals(nameSpace, node.getNodeType().getNamespace().toString());
+ }
+
+ assertNotNull(lf1suf);
+ assertNotNull(lflst1suf_1);
+ assertNotNull(lflst1suf_2);
+ assertNotNull(lflst1suf_3);
+ assertNotNull(lst1suf);
+ assertNotNull(cont1suf);
+
+ assertEquals("str0", lf1suf.getValue());
+ assertEquals("121", lflst1suf_1.getValue());
+ assertEquals("131", lflst1suf_2.getValue());
+ assertEquals("str1", lflst1suf_3.getValue());
+
+ assertEquals(1, lst1suf.getChildren().size());
+
+ assertTrue(lst1suf.getChildren().get(0) instanceof SimpleNode<?>);
+ SimpleNode<?> lst11_lf11 = (SimpleNode<?>) lst1suf.getChildren().get(0);
+ assertEquals(nameSpace, lst11_lf11.getNodeType().getNamespace().toString());
+ assertEquals("lf11" + suf, lst11_lf11.getNodeType().getLocalName());
+ assertEquals("str2", lst11_lf11.getValue());
+
+ assertTrue(cont1suf.getChildren().get(0) instanceof SimpleNode<?>);
+ SimpleNode<?> cont1_lf11 = (SimpleNode<?>) cont1suf.getChildren().get(0);
+ assertEquals(nameSpace, cont1_lf11.getNodeType().getNamespace().toString());
+ assertEquals("lf11" + suf, cont1_lf11.getNodeType().getLocalName());
+ assertEquals((short) 100, cont1_lf11.getValue());
+ }
+
+ private CompositeNode compositeNodeFromXml(String xmlPath, boolean dummyNamespaces) {
+ XmlToCompositeNodeProvider xmlToCompositeNodeProvider = XmlToCompositeNodeProvider.INSTANCE;
+ try {
+ InputStream xmlStream = XmlToCnSnTest.class.getResourceAsStream(xmlPath);
+ CompositeNode compositeNode = xmlToCompositeNodeProvider.readFrom(null, null, null, null, null, xmlStream);
+ if (dummyNamespaces) {
+ try {
+ TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) compositeNode);
+ return ((CompositeNodeWrapper) compositeNode).unwrap();
+ } catch (URISyntaxException e) {
+ LOG.error(e.getMessage());
+ assertTrue(e.getMessage(), false);
+ }
+ }
+ return compositeNode;
+
+ } catch (WebApplicationException | IOException e) {
+ LOG.error(e.getMessage());
+ assertTrue(false);
+ }
+ return null;
+ }
+
+ private void testIdentityrefToCnSn(String xmlPath, String yangPath, String moduleName, String schemaName,
+ int moduleCount, String resultLocalName, String resultNamespace) {
+ CompositeNode compositeNode = compositeNodeFromXml(xmlPath, false);
+ assertNotNull(compositeNode);
+
+ Set<Module> modules = TestUtils.resolveModules(yangPath);
+ assertEquals(moduleCount, modules.size());
+ Module module = TestUtils.resolveModule(moduleName, modules);
+ assertNotNull(module);
+ DataSchemaNode dataSchemaNode = TestUtils.resolveDataSchemaNode(module, null);
+ assertNotNull(dataSchemaNode);
+
+ RestconfImpl restconf = RestconfImpl.getInstance();
+ ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext(modules));
+
+ TestUtils.prepareMockForRestconfBeforeNormalization(modules, dataSchemaNode, restconf);
+
+ restconf.createConfigurationData(moduleName + ":" + schemaName, compositeNode);
+
+ SimpleNode<?> lf11 = getLf11(compositeNode);
+ assertTrue(lf11.getValue() instanceof QName);
+ QName qName = (QName) lf11.getValue();
+ assertEquals(resultLocalName, qName.getLocalName());
+ assertEquals(resultNamespace, qName.getNamespace().toString());
+
+ }
+
+ private SimpleNode<?> getLf11(CompositeNode compositeNode) {
+ assertEquals("cont", compositeNode.getNodeType().getLocalName());
+
+ List<Node<?>> childs = compositeNode.getChildren();
+ assertEquals(1, childs.size());
+ Node<?> nd = childs.iterator().next();
+ assertTrue(nd instanceof CompositeNode);
+ assertEquals("cont1", nd.getNodeType().getLocalName());
+
+ childs = ((CompositeNode) nd).getChildren();
+ SimpleNode<?> lf11 = null;
+ for (Node<?> child : childs) {
+ assertTrue(child instanceof SimpleNode);
+ if (child.getNodeType().getLocalName().equals("lf11")) {
+ lf11 = (SimpleNode<?>) child;
+ }
+ }
+ assertNotNull(lf11);
+ return lf11;
+ }
+
+}
--- /dev/null
+module identity-module {
+ namespace "identity:module";
+
+ prefix "idemod";
+ revision 2013-12-2 {
+ }
+
+ identity iden {
+ }
+}
\ No newline at end of file
--- /dev/null
+module identityref-module {
+ namespace "identityref:module";
+
+ prefix "iderefmod";
+
+ import identity-module {prefix idemo; revision-date 2013-12-2;}
+
+ revision 2013-12-2 {
+ }
+
+ container cont {
+ container cont1 {
+ leaf lf1 {
+ type identityref {
+ base "idemo:iden";
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module aug-referenced-elements-module {
+ namespace "aug:referenced:elements:module";
+
+ prefix "augrefelmo";
+
+ import referenced-elements-module {prefix refelmo; revision-date 2013-12-3;}
+
+ revision 2013-12-3 {
+ }
+
+ augment "/refelmo:cont" {
+ leaf lf2 {
+ type boolean;
+ }
+ }
+
+
+}
\ No newline at end of file
--- /dev/null
+module referenced-elements-module {
+ namespace "referenced:elements:module";
+
+ prefix "refelmo";
+
+ revision 2013-12-3 {
+ }
+
+ container cont {
+ leaf lf1 {
+ type string;
+ }
+ }
+ leaf-list lflst1 {
+ type uint32;
+ }
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module instance-identifier-module {
+ namespace "instance:identifier:module";
+
+ prefix "inidmod";
+
+ revision 2013-12-3 {
+ }
+
+ container cont {
+ leaf lf1 {
+ type instance-identifier {
+ }
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+{
+ "cont": {
+ "lf":[null]
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "cont": {
+ "lflst1":[],
+ "lflst2":[45]
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "cont": {
+ "lf":
+ }
+}
\ No newline at end of file
--- /dev/null
+module identity-module {
+ namespace "identity:module";
+
+ prefix "idemod";
+ revision 2013-12-2 {
+ }
+
+ identity iden {
+ }
+}
\ No newline at end of file
--- /dev/null
+module identityref-module {
+ namespace "identityref:module";
+
+ prefix "iderefmod";
+
+ import identity-module {prefix idemo; revision-date 2013-12-2;}
+
+ revision 2013-12-2 {
+ }
+
+ identity iden_local {
+ }
+
+ container cont {
+ container cont1 {
+ leaf lf11 {
+ type identityref {
+ base "idemo:iden";
+ }
+ }
+ leaf lf12 {
+ type identityref {
+ base "iden_local";
+ }
+ }
+ leaf lf13 {
+ type identityref {
+ base "iden_local";
+ }
+ }
+ leaf lf14 {
+ type identityref {
+ base "iden_local";
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+{
+ "cont":{
+ "cont1":{
+ "lf11":"identity-module:iden",
+ "lf12":"iden_local",
+ "identityref-module:lf13":"iden_local",
+ "identityref-module:lf14":"identity-module:iden_local"
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "lst":[
+ {
+ "lst1": [
+ {
+ "lf11":"lf11_1"
+ },
+ {
+ "lflst11":[
+ 45
+ ]
+ },
+ {
+ "cont11":{
+ }
+ },
+ {
+ "lst11":[
+ {
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+{
+ "cont": {
+ "lflst1":[45,55,66]
+ }
+}
\ No newline at end of file
--- /dev/null
+module simple-container-yang {
+ namespace "simple:container:yang";
+
+ prefix "smpdtp";
+ revision 2013-11-12 {
+ }
+
+ container cont {
+ container cont1 {
+ }
+ list lst1 {
+ }
+ leaf-list lflst1 {
+ type string;
+ }
+ leaf lf1 {
+ type string;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "cont":{
+ "cont1":{
+ },
+ "lst1": [
+ {
+ }
+ ],
+ "lflst1":[
+ "lflst1_1",
+ "lflst1_2"
+ ],
+ "lf1":"lf1"
+ }
+}
\ No newline at end of file
--- /dev/null
+module simple-list-yang1 {
+ namespace "simple:list:yang1";
+
+ prefix "smplstyg";
+ revision 2013-11-12 {
+ }
+
+ list lst {
+ container cont1 {
+ }
+ list lst1 {
+ }
+ leaf-list lflst1 {
+ type string;
+ }
+ leaf lf1 {
+ type string;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module simple-list-yang2 {
+ namespace "simple:list:yang2";
+
+ prefix "smplstyg";
+ revision 2013-11-12 {
+ }
+
+ list lst {
+ container cont1 {
+ }
+ list lst1 {
+ }
+ leaf-list lflst1 {
+ type string;
+ }
+ leaf lf1 {
+ type string;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "lst":[
+ {
+ "cont1":{
+ },
+ "lst1": [
+ {
+ }
+ ],
+ "lflst1":[
+ "lflst1_1",
+ "lflst1_2"
+ ],
+ "lf1":"lf1"
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+{
+
+ "lst":[
+ {
+ },
+ {
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+{
+
+ "cont": {
+ },
+ "lst":[
+ {
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+{
+ "lf":"hello"
+}
\ No newline at end of file
--- /dev/null
+module data-container-yang {
+ namespace "data:container:yang";
+
+ prefix "dtconyg";
+ revision 2013-11-19 {
+ }
+
+ container cont {
+ leaf lf1 {
+ type string;
+ }
+
+ leaf lf2 {
+ type string;
+ }
+
+ leaf lf3 {
+ type empty;
+ }
+
+ leaf-list lflst1 {
+ type string;
+ }
+ list lst1 {
+ leaf lf11 {
+ type string;
+ }
+ }
+ container cont1 {
+ leaf lf11 {
+ type uint8;
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<cont>
+ <lf1>str0</lf1>
+ <lf2></lf2>
+ <lf3/>
+ <lflst1>121</lflst1>
+ <lflst1>131</lflst1>
+ <lflst1>str1</lflst1>
+ <lst1>
+ <lf11>str2</lf11>
+ </lst1>
+ <cont1>
+ <lf11>100</lf11>
+ </cont1>
+</cont>
--- /dev/null
+module data-container-yang {
+ namespace "data:container:yang";
+
+ prefix "dtconyg";
+ revision 2013-11-19 {
+ }
+
+ container cont {
+ list lst1 {
+ leaf lf11 {
+ type string;
+ }
+ leaf-list lflst11 {
+ type string;
+ }
+ list lst11 {
+ leaf lf111 {
+ type string;
+ }
+ }
+ container cont11 {
+ leaf lf111 {
+ type uint8;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module data-list-yang {
+ namespace "data:list:yang";
+
+ prefix "dtlstyg";
+
+ import data-container-yang {
+ prefix "dtconyg";
+ revision-date 2013-11-19;
+ }
+
+
+ revision 2013-11-19 {
+ }
+
+
+
+ augment "/dtconyg:cont" {
+ leaf lf1 {
+ type string;
+ }
+ }
+}
--- /dev/null
+<cont>
+ <lst1>
+ <lf11>str0</lf11>
+ <lflst11>121</lflst11>
+ <lflst11>131</lflst11>
+ <lflst11>str1</lflst11>
+ <lst11>
+ <lf111>str2</lf111>
+ </lst11>
+ <cont11>
+ <lf111>100</lf111>
+ </cont11>
+ </lst1>
+ <lst1>
+ <lflst11>221</lflst11>
+ <cont11>
+ <lf111>100</lf111>
+ </cont11>
+ </lst1>
+ <lf1>lf1</lf1>
+</cont>
--- /dev/null
+<cont xmlns:x="x:namespace" xmlns:y="y:namespace">
+ <cont1 xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">
+ <lf11 xmlns:c="identity:module">c:iden</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+<cont>
+ <lf1></lf1>
+ <lflst1></lflst1>
+ <lflst1></lflst1>
+ <lst1>
+ <lf11></lf11>
+ </lst1>
+</cont>
--- /dev/null
+module identity-module {
+ namespace "identity:module";
+
+ prefix "idemod";
+ revision 2013-12-2 {
+ }
+
+ identity iden {
+ }
+}
\ No newline at end of file
--- /dev/null
+module identityref-module {
+ namespace "identityref:module";
+
+ prefix "iderefmod";
+
+ import identity-module {prefix idemo; revision-date 2013-12-2;}
+
+ revision 2013-12-2 {
+ }
+
+ container cont {
+ container cont1 {
+ leaf lf11 {
+ type identityref {
+ base "idemo:iden";
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<cont xmlns="general:module" xmlns:x="x:namespace" xmlns:y="y:namespace">
+ <cont1 xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">
+ <lf11 xmlns="identityref:module" xmlns:c="c:namespace">iden</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+<cont xmlns:x="x:namespace" xmlns:y="y:namespace">
+ <cont1 xmlns="identityref:module" xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">
+ <lf11 xmlns:c="c:namespace">iden</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+<cont xmlns="identityref:module" xmlns:x="x:namespace" xmlns:y="y:namespace">
+ <cont1 xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">
+ <lf11 xmlns:c="identity:module">c:iden</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+<cont xmlns="identityref:module" xmlns:x="x:namespace" xmlns:y="y:namespace">
+ <cont1 xmlns:c="identity:module" xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">
+ <lf11>z:iden</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+<cont>
+ <cont1>
+ <lf11>x:iden</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+<cont>
+ <cont1>
+ <lf11>iden</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+module general-module {
+ namespace "general:module";
+
+ prefix "genmod";
+ revision 2013-12-12 {
+ }
+
+ container cont {
+ container cont1 {
+ }
+ }
+
+
+}
\ No newline at end of file
--- /dev/null
+module identity-module {
+ namespace "identity:module";
+
+ prefix "idemod";
+ revision 2013-12-2 {
+ }
+
+ identity iden {
+ }
+}
\ No newline at end of file
--- /dev/null
+module identityref-module {
+ namespace "identityref:module";
+
+ prefix "iderefmod";
+
+ import identity-module {prefix idemo; revision-date 2013-12-2;}
+ import general-module {prefix gmo; revision-date 2013-12-12;}
+
+ revision 2013-12-2 {
+ }
+
+ augment "/gmo:cont/gmo:cont1" {
+ leaf lf11 {
+ type identityref {
+ base "idemo:iden";
+ }
+ }
+ }
+
+}
\ No newline at end of file
<lfdecimal6>33.12345</lfdecimal6>
<lfenum>enum3</lfenum>
<lfbits>bit3</lfbits>
- <lfbinary>AAaacdabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%%-#^</lfbinary>
+ <lfbinary>AAaacdabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</lfbinary>
<lfempty></lfempty>
<lfunion1>324</lfunion1>
<lfunion2>33.3</lfunion2>