* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.yang.data.codec.xml;
import static java.util.Objects.requireNonNull;
-import com.google.common.io.BaseEncoding;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URI;
+import java.util.Base64;
import java.util.Optional;
-import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.OutputKeys;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.xml.sax.SAXException;
public class Bug5446Test extends XMLTestCase {
- private static final XMLOutputFactory XML_FACTORY;
-
- static {
- XML_FACTORY = XMLOutputFactory.newFactory();
- XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
- }
-
- private final QNameModule fooModuleQName;
- private final QName rootQName;
- private final QName ipAddressQName;
- private final SchemaContext schemaContext;
-
- public Bug5446Test() throws Exception {
- fooModuleQName = QNameModule.create(new URI("foo"), QName.parseRevision("2015-11-05"));
- rootQName = QName.create(fooModuleQName, "root");
- ipAddressQName = QName.create(fooModuleQName, "ip-address");
-
- schemaContext = YangParserTestUtils.parseYangResource("/bug5446/yang/foo.yang");
- }
+ private static final QNameModule FOO_MODULE = QNameModule.create(URI.create("foo"), Revision.of("2015-11-05"));
+ private static final QName ROOT_QNAME = QName.create(FOO_MODULE, "root");
+ private static final QName IP_ADDRESS_QNAME = QName.create(FOO_MODULE, "ip-address");
@Test
public void test() throws Exception {
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug5446/yang/foo.yang");
final Document doc = loadDocument("/bug5446/xml/foo.xml");
final ContainerNode docNode = createDocNode();
- Optional<DataContainerChild<? extends PathArgument, ?>> root = docNode.getChild(new NodeIdentifier(rootQName));
+ Optional<DataContainerChild<? extends PathArgument, ?>> root = docNode.getChild(new NodeIdentifier(ROOT_QNAME));
assertTrue(root.orElse(null) instanceof ContainerNode);
Optional<DataContainerChild<? extends PathArgument, ?>> child = ((ContainerNode) root.orElse(null))
- .getChild(new NodeIdentifier(ipAddressQName));
+ .getChild(new NodeIdentifier(IP_ADDRESS_QNAME));
assertTrue(child.orElse(null) instanceof LeafNode);
LeafNode<?> ipAdress = (LeafNode<?>) child.get();
Object value = ipAdress.getValue();
assertTrue(value instanceof byte[]);
- assertEquals("fwAAAQ==", BaseEncoding.base64().encode((byte[]) value));
+ assertEquals("fwAAAQ==", Base64.getEncoder().encodeToString((byte[]) value));
DOMResult serializationResult = writeNormalizedNode(docNode, schemaContext);
assertNotNull(serializationResult);
assertXMLEqual(expectedXMLString, serializationResultXMLString);
}
- private ContainerNode createDocNode() {
- LeafNode<byte[]> ipAddress = ImmutableNodes.leafNode(ipAddressQName, BaseEncoding.base64().decode("fwAAAQ=="));
- ContainerNode root = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(rootQName))
+ private static ContainerNode createDocNode() {
+ LeafNode<byte[]> ipAddress = ImmutableNodes.leafNode(IP_ADDRESS_QNAME, Base64.getDecoder().decode("fwAAAQ=="));
+ ContainerNode root = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
.withChild(ipAddress).build();
- return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(rootQName)).withChild(root)
+ return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ROOT_QNAME)).withChild(root)
.build();
}
NormalizedNodeStreamWriter normalizedNodeStreamWriter = null;
XMLStreamWriter writer = null;
try {
- writer = XML_FACTORY.createXMLStreamWriter(result);
+ writer = TestFactories.DEFAULT_OUTPUT_FACTORY.createXMLStreamWriter(result);
normalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(writer, context);
normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(normalizedNodeStreamWriter);