X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fxml%2Fcodec%2FXmlUtilsTest.java;h=b82f534839dca342c5c1a49e19947d0fd05caeaa;hp=0688bfbc5cddbe256a3e67839606d6efd811442b;hb=f781598707f0810491cb571f835ee49772e00e83;hpb=63b36aa3537d77bd9be323e1113716ef2cd54098 diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/xml/codec/XmlUtilsTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/xml/codec/XmlUtilsTest.java index 0688bfbc5c..b82f534839 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/xml/codec/XmlUtilsTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/xml/codec/XmlUtilsTest.java @@ -8,34 +8,21 @@ package org.opendaylight.controller.xml.codec; - -import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.io.ByteSource; -import junit.framework.Assert; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import javax.xml.parsers.DocumentBuilderFactory; import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.ModifyAction; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.api.SimpleNode; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; - -import javax.xml.parsers.DocumentBuilderFactory; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; +// FIXME : CompositeNode is not avaliable anymore so fix the test to use NormalizedNodeContainer ASAP public class XmlUtilsTest { private static final DocumentBuilderFactory BUILDERFACTORY; @@ -49,7 +36,7 @@ public class XmlUtilsTest { BUILDERFACTORY = factory; } - private SchemaContext schema; + private SchemaContext schemaContext; private RpcDefinition testRpc; public static final String XML_CONTENT = "" + @@ -65,69 +52,19 @@ public class XmlUtilsTest { return XmlUtilsTest.this.getClass().getResourceAsStream("rpcTest.yang"); } }; - schema = new YangParserImpl().parseSources(Lists.newArrayList(byteSource)); - final Module rpcTestModule = schema.getModules().iterator().next(); - testRpc = rpcTestModule.getRpcs().iterator().next(); - } - - @Test - public void testNullInputXmlToComposite() { - CompositeNode node = XmlUtils.inputXmlToCompositeNode(testRpc.getQName(), null, schema); - Assert.assertNull(node); - } - @Test - public void testNullRpcXmlToComposite() { - CompositeNode node = XmlUtils.inputXmlToCompositeNode(null, XML_CONTENT, schema); - Assert.assertNull(node); - } + final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + final ArrayList sources = Lists.newArrayList(byteSource); - @Test - public void testInputXmlToCompositeNode() { - CompositeNode node = XmlUtils.inputXmlToCompositeNode(testRpc.getQName(), XML_CONTENT, schema); - ImmutableList input = (ImmutableList)node.getValue().get(0).getValue(); - SimpleNode firstNode = input.get(0); + try { - Assert.assertEquals("id", firstNode.getNodeType().getLocalName()); - Assert.assertEquals("flowid", firstNode.getValue()); - - SimpleNode secondNode = input.get(1); - Assert.assertEquals("flow", secondNode.getNodeType().getLocalName()); - - YangInstanceIdentifier instance = (YangInstanceIdentifier) secondNode.getValue(); - Iterable iterable = instance.getPathArguments(); - Iterator it = iterable.iterator(); - YangInstanceIdentifier.NodeIdentifier firstPath = (YangInstanceIdentifier.NodeIdentifier) it.next(); - Assert.assertEquals("node", firstPath.getNodeType().getLocalName()); - YangInstanceIdentifier.NodeIdentifierWithPredicates secondPath = (YangInstanceIdentifier.NodeIdentifierWithPredicates)it.next(); - Short value = (Short)secondPath.getKeyValues().values().iterator().next(); - Short expected = 3; - Assert.assertEquals(expected, value); - } + schemaContext = reactor.buildEffective(sources); + } catch (ReactorException e) { + throw new RuntimeException("Unable to build schema context from " + sources, e); + } - @Test - public void testInputCompositeNodeToXML() { - CompositeNode input = XmlUtils.inputXmlToCompositeNode(testRpc.getQName(), XML_CONTENT, schema); - List> childNodes = new ArrayList(); - childNodes.add(input); - QName rpcQName = schema.getOperations().iterator().next().getQName(); - CompositeNode node = new ImmutableCompositeNode(rpcQName, input.getValue(), ModifyAction.REPLACE); - String xml = XmlUtils.inputCompositeNodeToXml(node, schema); - Assert.assertNotNull(xml); - Assert.assertTrue(xml.contains("3@java.lang.Short")); - } - - @Test - public void testNullCompositeNodeToXml(){ - String xml = XmlUtils.inputCompositeNodeToXml(null, schema); - Assert.assertTrue(xml.isEmpty()); - } - - @Test - public void testNullSchemaCompositeNodeToXml(){ - String xml = XmlUtils.inputCompositeNodeToXml(new ImmutableCompositeNode(QName.create("ns", "2013-12-09", "child1"), new ArrayList>(), ModifyAction.REPLACE), null); - Assert.assertTrue(xml.isEmpty()); + final Module rpcTestModule = schemaContext.getModules().iterator().next(); + testRpc = rpcTestModule.getRpcs().iterator().next(); } - }