NormalizedNode serialization using protocol buffer
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / test / java / org / opendaylight / controller / cluster / datastore / util / NormalizedNodeXmlConverterTest.java
index 8d609823a71e11c69fe11a67d184cd4e276f1eb5..d53e91a262329e6f3e445a3d0186384cf1edf5e9 100644 (file)
@@ -7,31 +7,10 @@
  */
 package org.opendaylight.controller.cluster.datastore.util;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.URI;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.TransformerFactoryConfigurationError;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Test;
@@ -65,10 +44,30 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URI;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 
 /**
@@ -81,423 +80,403 @@ import com.google.common.collect.Sets;
 
 
 public class NormalizedNodeXmlConverterTest {
-  private static final Logger logger = LoggerFactory
-      .getLogger(NormalizedNodeXmlConverterTest.class);
-  public static final String NAMESPACE =
-      "urn:opendaylight:params:xml:ns:yang:controller:test";
-  private static Date revision;
-  private ContainerNode expectedNode;
-  private ContainerSchemaNode containerNode;
-  private String xmlPath;
-
-  static {
-    try {
-      revision = new SimpleDateFormat("yyyy-MM-dd").parse("2014-03-13");
-    } catch (ParseException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  public static DataSchemaNode getSchemaNode(final SchemaContext context,
-      final String moduleName, final String childNodeName) {
-    for (Module module : context.getModules()) {
-      if (module.getName().equals(moduleName)) {
-        DataSchemaNode found =
-            findChildNode(module.getChildNodes(), childNodeName);
-        Preconditions.checkState(found != null, "Unable to find %s",
-            childNodeName);
-        return found;
-      }
+    private static final Logger logger = LoggerFactory
+        .getLogger(NormalizedNodeXmlConverterTest.class);
+    public static final String NAMESPACE =
+        "urn:opendaylight:params:xml:ns:yang:controller:test";
+    private static Date revision;
+    private ContainerNode expectedNode;
+    private ContainerSchemaNode containerNode;
+    private String xmlPath;
+
+    static {
+        try {
+            revision = new SimpleDateFormat("yyyy-MM-dd").parse("2014-03-13");
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
     }
-    throw new IllegalStateException("Unable to find child node "
-        + childNodeName);
-  }
 
-  static DataSchemaNode findChildNode(final Iterable<DataSchemaNode> children, final String name) {
-    List<DataNodeContainer> containers = Lists.newArrayList();
+    public static DataSchemaNode getSchemaNode(final SchemaContext context,
+        final String moduleName, final String childNodeName) {
+        for (Module module : context.getModules()) {
+            if (module.getName().equals(moduleName)) {
+                DataSchemaNode found =
+                    findChildNode(module.getChildNodes(), childNodeName);
+                Preconditions.checkState(found != null, "Unable to find %s",
+                    childNodeName);
+                return found;
+            }
+        }
+        throw new IllegalStateException("Unable to find child node "
+            + childNodeName);
+    }
 
-    for (DataSchemaNode dataSchemaNode : children) {
-      if (dataSchemaNode.getQName().getLocalName().equals(name)) {
-        return dataSchemaNode;
+    static DataSchemaNode findChildNode(final Collection<DataSchemaNode> children, final String name) {
+        List<DataNodeContainer> containers = Lists.newArrayList();
+
+        for (DataSchemaNode dataSchemaNode : children) {
+            if (dataSchemaNode.getQName().getLocalName().equals(name)) {
+                return dataSchemaNode;
+            }
+            if (dataSchemaNode instanceof DataNodeContainer) {
+                containers.add((DataNodeContainer) dataSchemaNode);
+            } else if (dataSchemaNode instanceof ChoiceNode) {
+                containers.addAll(((ChoiceNode) dataSchemaNode).getCases());
+            }
+        }
+
+        for (DataNodeContainer container : containers) {
+            DataSchemaNode retVal = findChildNode(container.getChildNodes(), name);
+            if (retVal != null) {
+                return retVal;
+            }
+        }
+
+        return null;
     }
-      if (dataSchemaNode instanceof DataNodeContainer) {
-        containers.add((DataNodeContainer) dataSchemaNode);
-      } else if (dataSchemaNode instanceof ChoiceNode) {
-        containers.addAll(((ChoiceNode) dataSchemaNode).getCases());
-      }
+
+    public static InstanceIdentifier.NodeIdentifier getNodeIdentifier(
+        final String localName) {
+        return new InstanceIdentifier.NodeIdentifier(QName.create(
+            URI.create(NAMESPACE), revision, localName));
     }
 
-    for (DataNodeContainer container : containers) {
-      DataSchemaNode retVal = findChildNode(container.getChildNodes(), name);
-      if (retVal != null) {
-        return retVal;
-      }
+    public static InstanceIdentifier.AugmentationIdentifier getAugmentIdentifier(
+        final String... childNames) {
+        Set<QName> qn = Sets.newHashSet();
+
+        for (String childName : childNames) {
+            qn.add(getNodeIdentifier(childName).getNodeType());
+        }
+
+        return new InstanceIdentifier.AugmentationIdentifier(qn);
     }
 
-    return null;
-  }
 
-  private static InstanceIdentifier.NodeIdentifier getNodeIdentifier(
-      final String localName) {
-    return new InstanceIdentifier.NodeIdentifier(QName.create(
-        URI.create(NAMESPACE), revision, localName));
-  }
+    public static ContainerNode augmentChoiceExpectedNode() {
+
+        DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ContainerNode> b =
+            Builders.containerBuilder();
+        b.withNodeIdentifier(getNodeIdentifier("container"));
+
+        b.withChild(Builders
+            .choiceBuilder()
+            .withNodeIdentifier(getNodeIdentifier("ch2"))
+            .withChild(
+                Builders.leafBuilder()
+                    .withNodeIdentifier(getNodeIdentifier("c2Leaf")).withValue("2")
+                    .build())
+            .withChild(
+                Builders
+                    .choiceBuilder()
+                    .withNodeIdentifier(getNodeIdentifier("c2DeepChoice"))
+                    .withChild(
+                        Builders
+                            .leafBuilder()
+                            .withNodeIdentifier(
+                                getNodeIdentifier("c2DeepChoiceCase1Leaf2"))
+                            .withValue("2").build()).build()).build());
+
+        b.withChild(Builders
+            .choiceBuilder()
+            .withNodeIdentifier(getNodeIdentifier("ch3"))
+            .withChild(
+                Builders.leafBuilder()
+                    .withNodeIdentifier(getNodeIdentifier("c3Leaf")).withValue("3")
+                    .build()).build());
+
+        b.withChild(Builders
+            .augmentationBuilder()
+            .withNodeIdentifier(getAugmentIdentifier("augLeaf"))
+            .withChild(
+                Builders.leafBuilder()
+                    .withNodeIdentifier(getNodeIdentifier("augLeaf"))
+                    .withValue("augment").build()).build());
+
+        b.withChild(Builders
+            .augmentationBuilder()
+            .withNodeIdentifier(getAugmentIdentifier("ch"))
+            .withChild(
+                Builders
+                    .choiceBuilder()
+                    .withNodeIdentifier(getNodeIdentifier("ch"))
+                    .withChild(
+                        Builders.leafBuilder()
+                            .withNodeIdentifier(getNodeIdentifier("c1Leaf"))
+                            .withValue("1").build())
+                    .withChild(
+                        Builders
+                            .augmentationBuilder()
+                            .withNodeIdentifier(
+                                getAugmentIdentifier("c1Leaf_AnotherAugment",
+                                    "deepChoice"))
+                            .withChild(
+                                Builders
+                                    .leafBuilder()
+                                    .withNodeIdentifier(
+                                        getNodeIdentifier("c1Leaf_AnotherAugment"))
+                                    .withValue("1").build())
+                            .withChild(
+                                Builders
+                                    .choiceBuilder()
+                                    .withNodeIdentifier(
+                                        getNodeIdentifier("deepChoice"))
+                                    .withChild(
+                                        Builders
+                                            .leafBuilder()
+                                            .withNodeIdentifier(
+                                                getNodeIdentifier("deepLeafc1"))
+                                            .withValue("1").build()).build())
+                            .build()).build()).build());
+
+        return b.build();
+    }
 
-  public static InstanceIdentifier.AugmentationIdentifier getAugmentIdentifier(
-      final String... childNames) {
-    Set<QName> qn = Sets.newHashSet();
 
-    for (String childName : childNames) {
-      qn.add(getNodeIdentifier(childName).getNodeType());
+
+    public void init(final String yangPath, final String xmlPath, final ContainerNode expectedNode)
+        throws Exception {
+        SchemaContext schema = parseTestSchema(yangPath);
+        this.xmlPath = xmlPath;
+        this.containerNode =
+            (ContainerSchemaNode) getSchemaNode(schema, "test", "container");
+        this.expectedNode = expectedNode;
     }
 
-    return new InstanceIdentifier.AugmentationIdentifier(qn);
-  }
-
-
-  private static ContainerNode augmentChoiceExpectedNode() {
-
-    DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ContainerNode> b =
-        Builders.containerBuilder();
-    b.withNodeIdentifier(getNodeIdentifier("container"));
-
-    b.withChild(Builders
-        .choiceBuilder()
-        .withNodeIdentifier(getNodeIdentifier("ch2"))
-        .withChild(
-            Builders.leafBuilder()
-                .withNodeIdentifier(getNodeIdentifier("c2Leaf")).withValue("2")
-                .build())
-        .withChild(
-            Builders
-                .choiceBuilder()
-                .withNodeIdentifier(getNodeIdentifier("c2DeepChoice"))
-                .withChild(
-                    Builders
-                        .leafBuilder()
-                        .withNodeIdentifier(
-                            getNodeIdentifier("c2DeepChoiceCase1Leaf2"))
-                        .withValue("2").build()).build()).build());
-
-    b.withChild(Builders
-        .choiceBuilder()
-        .withNodeIdentifier(getNodeIdentifier("ch3"))
-        .withChild(
-            Builders.leafBuilder()
-                .withNodeIdentifier(getNodeIdentifier("c3Leaf")).withValue("3")
-                .build()).build());
-
-    b.withChild(Builders
-        .augmentationBuilder()
-        .withNodeIdentifier(getAugmentIdentifier("augLeaf"))
-        .withChild(
-            Builders.leafBuilder()
-                .withNodeIdentifier(getNodeIdentifier("augLeaf"))
-                .withValue("augment").build()).build());
-
-    b.withChild(Builders
-        .augmentationBuilder()
-        .withNodeIdentifier(getAugmentIdentifier("ch"))
-        .withChild(
-            Builders
-                .choiceBuilder()
-                .withNodeIdentifier(getNodeIdentifier("ch"))
-                .withChild(
-                    Builders.leafBuilder()
-                        .withNodeIdentifier(getNodeIdentifier("c1Leaf"))
-                        .withValue("1").build())
-                .withChild(
-                    Builders
-                        .augmentationBuilder()
-                        .withNodeIdentifier(
-                            getAugmentIdentifier("c1Leaf_AnotherAugment",
-                                "deepChoice"))
-                        .withChild(
-                            Builders
-                                .leafBuilder()
-                                .withNodeIdentifier(
-                                    getNodeIdentifier("c1Leaf_AnotherAugment"))
-                                .withValue("1").build())
-                        .withChild(
-                            Builders
-                                .choiceBuilder()
-                                .withNodeIdentifier(
-                                    getNodeIdentifier("deepChoice"))
-                                .withChild(
-                                    Builders
-                                        .leafBuilder()
-                                        .withNodeIdentifier(
-                                            getNodeIdentifier("deepLeafc1"))
-                                        .withValue("1").build()).build())
-                        .build()).build()).build());
-
-    return b.build();
-  }
-
-
-
-  public void init(final String yangPath, final String xmlPath, final ContainerNode expectedNode)
-      throws Exception {
-    SchemaContext schema = parseTestSchema(yangPath);
-    this.xmlPath = xmlPath;
-    this.containerNode =
-        (ContainerSchemaNode) getSchemaNode(schema, "test", "container");
-    this.expectedNode = expectedNode;
-  }
-
-  SchemaContext parseTestSchema(final String yangPath) throws Exception {
-
-    YangParserImpl yangParserImpl = new YangParserImpl();
-    InputStream stream =
-        NormalizedNodeXmlConverterTest.class.getResourceAsStream(yangPath);
-    ArrayList<InputStream> al = new ArrayList<InputStream>();
-    al.add(stream);
-    Set<Module> modules = yangParserImpl.parseYangModelsFromStreams(al);
-    return yangParserImpl.resolveSchemaContext(modules);
-
-  }
-
-
-  @Test
-  public void testConversionWithAugmentChoice() throws Exception {
-    init("/augment_choice.yang", "/augment_choice.xml",
-        augmentChoiceExpectedNode());
-    Document doc = loadDocument(xmlPath);
-
-    ContainerNode built =
-        DomToNormalizedNodeParserFactory
-            .getInstance(DomUtils.defaultValueCodecProvider())
-            .getContainerNodeParser()
-            .parse(Collections.singletonList(doc.getDocumentElement()),
-                containerNode);
-
-    if (expectedNode != null) {
-        junit.framework.Assert.assertEquals(expectedNode, built);
+    SchemaContext parseTestSchema(final String yangPath) throws Exception {
+
+        YangParserImpl yangParserImpl = new YangParserImpl();
+        InputStream stream =
+            NormalizedNodeXmlConverterTest.class.getResourceAsStream(yangPath);
+        ArrayList<InputStream> al = new ArrayList<InputStream>();
+        al.add(stream);
+        Set<Module> modules = yangParserImpl.parseYangModelsFromStreams(al);
+        return yangParserImpl.resolveSchemaContext(modules);
+
     }
 
-    logger.info("{}", built);
 
-    Iterable<Element> els =
-        DomFromNormalizedNodeSerializerFactory
-            .getInstance(XmlDocumentUtils.getDocument(),
-                DomUtils.defaultValueCodecProvider())
-            .getContainerNodeSerializer().serialize(containerNode, built);
+    @Test
+    public void testConversionWithAugmentChoice() throws Exception {
+        init("/augment_choice.yang", "/augment_choice.xml",
+            augmentChoiceExpectedNode());
+        Document doc = loadDocument(xmlPath);
 
-    Element el = els.iterator().next();
+        ContainerNode built =
+            DomToNormalizedNodeParserFactory
+                .getInstance(DomUtils.defaultValueCodecProvider())
+                .getContainerNodeParser()
+                .parse(Collections.singletonList(doc.getDocumentElement()),
+                    containerNode);
 
-    XMLUnit.setIgnoreWhitespace(true);
-    XMLUnit.setIgnoreComments(true);
+        if (expectedNode != null) {
+            junit.framework.Assert.assertEquals(expectedNode, built);
+        }
 
-    System.out.println(toString(doc.getDocumentElement()));
-    System.out.println(toString(el));
+        logger.info("{}", built);
 
-    new Diff(
-        XMLUnit.buildControlDocument(toString(doc.getDocumentElement())),
-        XMLUnit.buildTestDocument(toString(el))).similar();
-  }
+        Iterable<Element> els =
+            DomFromNormalizedNodeSerializerFactory
+                .getInstance(XmlDocumentUtils.getDocument(),
+                    DomUtils.defaultValueCodecProvider())
+                .getContainerNodeSerializer().serialize(containerNode, built);
 
-  private static ContainerNode listLeafListWithAttributes() {
-    DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ContainerNode> b =
-        Builders.containerBuilder();
-    b.withNodeIdentifier(getNodeIdentifier("container"));
+        Element el = els.iterator().next();
 
-    CollectionNodeBuilder<MapEntryNode, MapNode> listBuilder =
-        Builders.mapBuilder().withNodeIdentifier(getNodeIdentifier("list"));
+        XMLUnit.setIgnoreWhitespace(true);
+        XMLUnit.setIgnoreComments(true);
 
-    Map<QName, Object> predicates = Maps.newHashMap();
-    predicates.put(getNodeIdentifier("uint32InList").getNodeType(), 3L);
+        System.out.println(toString(doc.getDocumentElement()));
+        System.out.println(toString(el));
 
-    DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> list1Builder =
-        Builders.mapEntryBuilder().withNodeIdentifier(
-            new InstanceIdentifier.NodeIdentifierWithPredicates(
-                getNodeIdentifier("list").getNodeType(), predicates));
-    NormalizedNodeBuilder<InstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> uint32InListBuilder =
-        Builders.leafBuilder().withNodeIdentifier(
-            getNodeIdentifier("uint32InList"));
+        new Diff(
+            XMLUnit.buildControlDocument(toString(doc.getDocumentElement())),
+            XMLUnit.buildTestDocument(toString(el))).similar();
+    }
 
-    list1Builder.withChild(uint32InListBuilder.withValue(3L).build());
+    private static ContainerNode listLeafListWithAttributes() {
+        DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifier, ContainerNode> b =
+            Builders.containerBuilder();
+        b.withNodeIdentifier(getNodeIdentifier("container"));
 
-    listBuilder.withChild(list1Builder.build());
-    b.withChild(listBuilder.build());
+        CollectionNodeBuilder<MapEntryNode, MapNode> listBuilder =
+            Builders.mapBuilder().withNodeIdentifier(getNodeIdentifier("list"));
 
-    NormalizedNodeBuilder<InstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> booleanBuilder =
-        Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean"));
-    booleanBuilder.withValue(false);
-    b.withChild(booleanBuilder.build());
+        Map<QName, Object> predicates = Maps.newHashMap();
+        predicates.put(getNodeIdentifier("uint32InList").getNodeType(), 3L);
 
-    ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafListBuilder =
-        Builders.leafSetBuilder().withNodeIdentifier(
-            getNodeIdentifier("leafList"));
+        DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> list1Builder =
+            Builders.mapEntryBuilder().withNodeIdentifier(
+                new InstanceIdentifier.NodeIdentifierWithPredicates(
+                    getNodeIdentifier("list").getNodeType(), predicates));
+        NormalizedNodeBuilder<InstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> uint32InListBuilder =
+            Builders.leafBuilder().withNodeIdentifier(
+                getNodeIdentifier("uint32InList"));
 
-    NormalizedNodeBuilder<InstanceIdentifier.NodeWithValue, Object, LeafSetEntryNode<Object>> leafList1Builder =
-        Builders.leafSetEntryBuilder().withNodeIdentifier(
-            new InstanceIdentifier.NodeWithValue(getNodeIdentifier("leafList")
-                .getNodeType(), "a"));
+        list1Builder.withChild(uint32InListBuilder.withValue(3L).build());
 
-    leafList1Builder.withValue("a");
+        listBuilder.withChild(list1Builder.build());
+        b.withChild(listBuilder.build());
 
-    leafListBuilder.withChild(leafList1Builder.build());
-    b.withChild(leafListBuilder.build());
+        NormalizedNodeBuilder<InstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> booleanBuilder =
+            Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean"));
+        booleanBuilder.withValue(false);
+        b.withChild(booleanBuilder.build());
 
-    return b.build();
-  }
+        ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafListBuilder =
+            Builders.leafSetBuilder().withNodeIdentifier(
+                getNodeIdentifier("leafList"));
 
+        NormalizedNodeBuilder<InstanceIdentifier.NodeWithValue, Object, LeafSetEntryNode<Object>> leafList1Builder =
+            Builders.leafSetEntryBuilder().withNodeIdentifier(
+                new InstanceIdentifier.NodeWithValue(getNodeIdentifier("leafList")
+                    .getNodeType(), "a"));
 
-  @Test
-  public void testConversionWithAttributes() throws Exception {
-    init("/test.yang", "/simple_xml_with_attributes.xml",
-        listLeafListWithAttributes());
-    Document doc = loadDocument(xmlPath);
+        leafList1Builder.withValue("a");
 
-    ContainerNode built =
-        DomToNormalizedNodeParserFactory
-            .getInstance(DomUtils.defaultValueCodecProvider())
-            .getContainerNodeParser()
-            .parse(Collections.singletonList(doc.getDocumentElement()),
-                containerNode);
+        leafListBuilder.withChild(leafList1Builder.build());
+        b.withChild(leafListBuilder.build());
 
-    if (expectedNode != null) {
-        junit.framework.Assert.assertEquals(expectedNode, built);
+        return b.build();
     }
 
-    logger.info("{}", built);
 
-    Iterable<Element> els =
-        DomFromNormalizedNodeSerializerFactory
-            .getInstance(XmlDocumentUtils.getDocument(),
-                DomUtils.defaultValueCodecProvider())
-            .getContainerNodeSerializer().serialize(containerNode, built);
+    @Test
+    public void testConversionWithAttributes() throws Exception {
+        init("/test.yang", "/simple_xml_with_attributes.xml",
+            listLeafListWithAttributes());
+        Document doc = loadDocument(xmlPath);
+
+        ContainerNode built =
+            DomToNormalizedNodeParserFactory
+                .getInstance(DomUtils.defaultValueCodecProvider())
+                .getContainerNodeParser()
+                .parse(Collections.singletonList(doc.getDocumentElement()),
+                    containerNode);
 
-    Element el = els.iterator().next();
+        if (expectedNode != null) {
+            junit.framework.Assert.assertEquals(expectedNode, built);
+        }
 
-    XMLUnit.setIgnoreWhitespace(true);
-    XMLUnit.setIgnoreComments(true);
+        logger.info("{}", built);
 
-    System.out.println(toString(doc.getDocumentElement()));
-    System.out.println(toString(el));
+        Iterable<Element> els =
+            DomFromNormalizedNodeSerializerFactory
+                .getInstance(XmlDocumentUtils.getDocument(),
+                    DomUtils.defaultValueCodecProvider())
+                .getContainerNodeSerializer().serialize(containerNode, built);
 
-    new Diff(
-        XMLUnit.buildControlDocument(toString(doc.getDocumentElement())),
-        XMLUnit.buildTestDocument(toString(el))).similar();
-  }
+        Element el = els.iterator().next();
 
+        XMLUnit.setIgnoreWhitespace(true);
+        XMLUnit.setIgnoreComments(true);
 
-  private Document loadDocument(final String xmlPath) throws Exception {
-    InputStream resourceAsStream =
-        NormalizedNodeXmlConverterTest.class.getResourceAsStream(xmlPath);
+        System.out.println(toString(doc.getDocumentElement()));
+        System.out.println(toString(el));
 
-    Document currentConfigElement = readXmlToDocument(resourceAsStream);
-    Preconditions.checkNotNull(currentConfigElement);
-    return currentConfigElement;
-  }
+        new Diff(
+            XMLUnit.buildControlDocument(toString(doc.getDocumentElement())),
+            XMLUnit.buildTestDocument(toString(el))).similar();
+    }
 
-  private static final DocumentBuilderFactory BUILDERFACTORY;
 
-  static {
-    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-    factory.setNamespaceAware(true);
-    factory.setCoalescing(true);
-    factory.setIgnoringElementContentWhitespace(true);
-    factory.setIgnoringComments(true);
-    BUILDERFACTORY = factory;
-  }
+    private Document loadDocument(final String xmlPath) throws Exception {
+        InputStream resourceAsStream =
+            NormalizedNodeXmlConverterTest.class.getResourceAsStream(xmlPath);
 
-  private Document readXmlToDocument(final InputStream xmlContent)
-      throws IOException, SAXException {
-    DocumentBuilder dBuilder;
-    try {
-      dBuilder = BUILDERFACTORY.newDocumentBuilder();
-    } catch (ParserConfigurationException e) {
-      throw new RuntimeException("Failed to parse XML document", e);
+        Document currentConfigElement = readXmlToDocument(resourceAsStream);
+        Preconditions.checkNotNull(currentConfigElement);
+        return currentConfigElement;
     }
-    Document doc = dBuilder.parse(xmlContent);
-
-    doc.getDocumentElement().normalize();
-    return doc;
-  }
-
-  public static String toString(final Element xml) {
-    try {
-      Transformer transformer =
-          TransformerFactory.newInstance().newTransformer();
-      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-
-      StreamResult result = new StreamResult(new StringWriter());
-      DOMSource source = new DOMSource(xml);
-      transformer.transform(source, result);
-
-      return result.getWriter().toString();
-    } catch (IllegalArgumentException | TransformerFactoryConfigurationError
-        | TransformerException e) {
-      throw new RuntimeException("Unable to serialize xml element " + xml, e);
+
+    private static final DocumentBuilderFactory BUILDERFACTORY;
+
+    static {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setCoalescing(true);
+        factory.setIgnoringElementContentWhitespace(true);
+        factory.setIgnoringComments(true);
+        BUILDERFACTORY = factory;
+    }
+
+    private Document readXmlToDocument(final InputStream xmlContent)
+        throws IOException, SAXException {
+        DocumentBuilder dBuilder;
+        try {
+            dBuilder = BUILDERFACTORY.newDocumentBuilder();
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException("Failed to parse XML document", e);
+        }
+        Document doc = dBuilder.parse(xmlContent);
+
+        doc.getDocumentElement().normalize();
+        return doc;
+    }
+
+    public static String toString(final Element xml) {
+        try {
+            Transformer transformer =
+                TransformerFactory.newInstance().newTransformer();
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+            StreamResult result = new StreamResult(new StringWriter());
+            DOMSource source = new DOMSource(xml);
+            transformer.transform(source, result);
+
+            return result.getWriter().toString();
+        } catch (IllegalArgumentException | TransformerFactoryConfigurationError
+            | TransformerException e) {
+            throw new RuntimeException("Unable to serialize xml element " + xml, e);
+        }
+    }
+
+    @Test
+    public void testConversionToNormalizedXml() throws Exception {
+        SimpleNormalizedNodeMessage.NormalizedNodeXml nnXml =
+            EncoderDecoderUtil.encode(parseTestSchema("/augment_choice.yang"),
+                augmentChoiceExpectedNode());
+        Document expectedDoc = loadDocument("/augment_choice.xml");
+        Document convertedDoc =
+            EncoderDecoderUtil.factory.newDocumentBuilder().parse(
+                new ByteArrayInputStream(nnXml.getXmlString().getBytes("utf-8")));
+        System.out.println(toString(convertedDoc.getDocumentElement()));
+        XMLUnit.setIgnoreWhitespace(true);
+        XMLUnit.setIgnoreComments(true);
+        new Diff(XMLUnit.buildControlDocument(toString(expectedDoc
+            .getDocumentElement())),
+            XMLUnit.buildTestDocument(toString(convertedDoc
+                .getDocumentElement()))).similar();
+        System.out.println(toString(expectedDoc.getDocumentElement()));
+
+    }
+
+
+    @Test
+    public void testConversionFromXmlToNormalizedNode() throws Exception {
+        SimpleNormalizedNodeMessage.NormalizedNodeXml nnXml =
+            EncoderDecoderUtil.encode(parseTestSchema("/test.yang"),
+                listLeafListWithAttributes());
+        Document expectedDoc = loadDocument("/simple_xml_with_attributes.xml");
+        Document convertedDoc =
+            EncoderDecoderUtil.factory.newDocumentBuilder().parse(
+                new ByteArrayInputStream(nnXml.getXmlString().getBytes("utf-8")));
+        System.out.println(toString(convertedDoc.getDocumentElement()));
+        XMLUnit.setIgnoreWhitespace(true);
+        XMLUnit.setIgnoreComments(true);
+        new Diff(XMLUnit.buildControlDocument(toString(expectedDoc
+            .getDocumentElement())),
+            XMLUnit.buildTestDocument(toString(convertedDoc
+                .getDocumentElement()))).similar();
+        System.out.println(toString(expectedDoc.getDocumentElement()));
+
+        // now we will try to convert xml back to normalize node.
+        ContainerNode cn =
+            (ContainerNode) EncoderDecoderUtil.decode(
+                parseTestSchema("/test.yang"), nnXml);
+        junit.framework.Assert.assertEquals(listLeafListWithAttributes(), cn);
+
     }
-  }
 
-  @Test
-  public void testConversionToNormalizedXml() throws Exception {
-    SimpleNormalizedNodeMessage.NormalizedNodeXml nnXml =
-        EncoderDecoderUtil.encode(parseTestSchema("/augment_choice.yang"),
-            augmentChoiceExpectedNode());
-    Document expectedDoc = loadDocument("/augment_choice.xml");
-    Document convertedDoc =
-        EncoderDecoderUtil.factory.newDocumentBuilder().parse(
-            new ByteArrayInputStream(nnXml.getXmlString().getBytes("utf-8")));
-    System.out.println(toString(convertedDoc.getDocumentElement()));
-    XMLUnit.setIgnoreWhitespace(true);
-    XMLUnit.setIgnoreComments(true);
-    new Diff(XMLUnit.buildControlDocument(toString(expectedDoc
-        .getDocumentElement())),
-        XMLUnit.buildTestDocument(toString(convertedDoc
-            .getDocumentElement()))).similar();
-    System.out.println(toString(expectedDoc.getDocumentElement()));
-
-  }
-
-
-  @Test
-  public void testConversionFromXmlToNormalizedNode() throws Exception {
-    SimpleNormalizedNodeMessage.NormalizedNodeXml nnXml =
-        EncoderDecoderUtil.encode(parseTestSchema("/test.yang"),
-            listLeafListWithAttributes());
-    Document expectedDoc = loadDocument("/simple_xml_with_attributes.xml");
-    Document convertedDoc =
-        EncoderDecoderUtil.factory.newDocumentBuilder().parse(
-            new ByteArrayInputStream(nnXml.getXmlString().getBytes("utf-8")));
-    System.out.println(toString(convertedDoc.getDocumentElement()));
-    XMLUnit.setIgnoreWhitespace(true);
-    XMLUnit.setIgnoreComments(true);
-    new Diff(XMLUnit.buildControlDocument(toString(expectedDoc
-        .getDocumentElement())),
-        XMLUnit.buildTestDocument(toString(convertedDoc
-            .getDocumentElement()))).similar();
-    System.out.println(toString(expectedDoc.getDocumentElement()));
-
-    // now we will try to convert xml back to normalize node.
-    ContainerNode cn =
-        (ContainerNode) EncoderDecoderUtil.decode(
-            parseTestSchema("/test.yang"), nnXml);
-    junit.framework.Assert.assertEquals(listLeafListWithAttributes(), cn);
-
-  }
-
-  @Test
-  public void testInMemoryTestModelProtoBuffEncoding() throws Exception {
-
-    SimpleNormalizedNodeMessage.NormalizedNodeXml nnXml =
-        EncoderDecoderUtil.encode(parseTestSchema("/odl-datastore-test.yang"),
-            TestModel.createFamily());
-
-    Document convertedDoc =
-        EncoderDecoderUtil.factory.newDocumentBuilder().parse(
-            new ByteArrayInputStream(nnXml.getXmlString().getBytes("utf-8")));
-    System.out.println(toString(convertedDoc.getDocumentElement()));
-
-    // now we will try to convert xml back to normalize node.
-    ContainerNode cn =
-        (ContainerNode) EncoderDecoderUtil.decode(
-            parseTestSchema("/odl-datastore-test.yang"), nnXml);
-    junit.framework.Assert.assertEquals(TestModel.createFamily(), cn);
-
-
-  }
 }