X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Futils%2FXmlUtilsTest.java;h=a408e1d55a1e9cd2602458a9b051835ec9334be6;hb=6ab0aae9f5fcc5a464670c85e8249c575c4d9b9e;hp=92340b63eb5193892be714401ced33b5fe9b16b2;hpb=5c5f9d085a0876b875ce8889dfdac2a83d5e5e97;p=controller.git
diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/utils/XmlUtilsTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/utils/XmlUtilsTest.java
index 92340b63eb..a408e1d55a 100644
--- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/utils/XmlUtilsTest.java
+++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/utils/XmlUtilsTest.java
@@ -15,9 +15,13 @@ import com.google.common.io.ByteSource;
import junit.framework.Assert;
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;
@@ -27,7 +31,9 @@ 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;
public class XmlUtilsTest {
@@ -46,10 +52,10 @@ public class XmlUtilsTest {
private SchemaContext schema;
private RpcDefinition testRpc;
- public static final String XML_CONTENT = "" +
+ public static final String XML_CONTENT = "" +
"flowid" +
"/ltha:node/ltha:node1[ltha:id='3@java.lang.Short']" +
- "";
+ "";
@Before
public void setUp() throws Exception {
@@ -64,6 +70,18 @@ public class XmlUtilsTest {
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);
+ }
+
@Test
public void testInputXmlToCompositeNode() {
CompositeNode node = XmlUtils.inputXmlToCompositeNode(testRpc.getQName(), XML_CONTENT, schema);
@@ -87,5 +105,29 @@ public class XmlUtilsTest {
Assert.assertEquals(expected, value);
}
+ @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());
+ }
+
}