import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import java.io.ByteArrayOutputStream;
import java.net.URISyntaxException;
import java.util.AbstractMap;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Map;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
return targetBaseType;
}
- @Test
- public void testEmptyNodeWithAttribute() throws Exception {
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
-
- final Map<QName, String> attrs = Maps.newHashMap();
- attrs.put(QName.create("namespaceAttr", "2012-12-12", "attr1"), "value");
- final QName qName = QName.create("urn:opendaylight:controller:rpc:test", "2014-07-28", "cont");
- final ImmutableCompositeNode dataAttributes = ImmutableCompositeNode.create(qName, attrs, Collections.<Node<?>>emptyList());
- XmlStreamUtils.create(XmlUtils.DEFAULT_XML_CODEC_PROVIDER).writeDocument(writer, dataAttributes);
-
- writer.close();
- out.close();
-
- final String xmlAsString = new String(out.toByteArray());
-
- // TODO why resulting xml does not have namespace definition ? If sending xml by e.g. netconf the namespace is there but not here in test
- final String expectedXmlAsString = "<cont xmlns:a=\"namespaceAttr\" a:attr1=\"value\"></cont>";
-
- XMLUnit.setIgnoreAttributeOrder(true);
- final Document control = XMLUnit.buildControlDocument(expectedXmlAsString);
- final Document test = XMLUnit.buildTestDocument(xmlAsString);
- final Diff diff = XMLUnit.compareXML(control, test);
-
- final boolean identical = diff.identical();
- assertTrue("Xml differs: " + diff.toString(), identical);
- }
-
- private Map<String, String> mapPrefixed(final Iterable<Map.Entry<URI, String>> prefixes) {
+ private static Map<String, String> mapPrefixed(final Iterable<Map.Entry<URI, String>> prefixes) {
final Map<String, String> mappedPrefixes = Maps.newHashMap();
for (final Map.Entry<URI, String> prefix : prefixes) {
mappedPrefixes.put(prefix.getKey().toString(), prefix.getValue());
return mappedPrefixes;
}
- private QName getAttrQName(final String namespace, final String revision, final String localName, final Optional<String> prefix) {
-
- if(prefix.isPresent()) {
+ private static QName getAttrQName(final String namespace, final String revision, final String localName, final Optional<String> prefix) {
+ if (prefix.isPresent()) {
final QName moduleQName = QName.create(namespace, revision, "module");
final QNameModule module = QNameModule.create(moduleQName.getNamespace(), moduleQName.getRevision());
- return QName.create(module, prefix.get(), localName);
+ return QName.create(module, localName);
} else {
return QName.create(namespace, revision, localName);
}
return null;
}
- private LeafrefTypeDefinition findLeafrefType(final LeafSchemaNode schemaNode) {
+ private static LeafrefTypeDefinition findLeafrefType(final LeafSchemaNode schemaNode) {
final TypeDefinition<?> type = schemaNode.getType();
if (type instanceof LeafrefTypeDefinition) {
return (LeafrefTypeDefinition)type;
}
return null;
}
-}
\ No newline at end of file
+}