From: Robert Varga Date: Sun, 8 Jun 2014 18:56:59 +0000 (+0200) Subject: BUG-981: Fix XML serialization test X-Git-Tag: release/helium~683 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=43d946846554d7dce760f73997748906be42bd66 BUG-981: Fix XML serialization test Since commit 7624eedc495e85d12c2c2c56efb09dfd9406f977 changed XML resolution rules such that XML namespace is required to properly identify a node. This broke serialization tests, which did not provide module/revision identification -- which meant serialized data was being handled by String encoder. The string encoder does not do the right thing for arrays -- which broke the bits and binary encoding tests. Fix the tests to specify module/revision, thus matching conforming to schema. Change-Id: I5cbee0e19b85ebe3a5cf181a0e2d2ca044bfe07e Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlTest.java index 155ee9d590..9318af529b 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlTest.java @@ -9,6 +9,8 @@ package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.test; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.IOException; import java.util.List; @@ -18,9 +20,6 @@ import javax.xml.transform.TransformerFactoryConfigurationError; import org.junit.BeforeClass; import org.junit.Test; - -import static org.mockito.Mockito.*; - import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; import org.opendaylight.controller.sal.restconf.impl.test.TestUtils; import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader; @@ -166,9 +165,9 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader { serializeToXml( prepareCnStructForYangData( TypeDefinitionAwareCodec.from(BinaryType.getInstance()) - .deserialize("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567"), + .deserialize("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567"), elName), "<" + elName + ">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567"); + + elName + ">"); } @Test @@ -182,9 +181,9 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader { String elName = "lfBits"; serializeToXml( prepareCnStructForYangData(TypeDefinitionAwareCodec.from( - BitsType.create( mock( SchemaPath.class ), bitList ) ) - .deserialize("one two"), elName), - "<" + elName + ">one two", "<" + elName + ">two one"); + BitsType.create( mock( SchemaPath.class ), bitList ) ) + .deserialize("one two"), elName), + "<" + elName + ">one two", "<" + elName + ">two one"); } @Test @@ -196,10 +195,10 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader { String elName = "lfEnumeration"; serializeToXml( prepareCnStructForYangData(TypeDefinitionAwareCodec.from( - EnumerationType.create( mock( SchemaPath.class ), enumList, - Optional.absent() ) ) - .deserialize("enum2"), - elName), "<" + elName + ">enum2"); + EnumerationType.create( mock( SchemaPath.class ), enumList, + Optional.absent() ) ) + .deserialize("enum2"), + elName), "<" + elName + ">enum2"); } @Test @@ -231,9 +230,9 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader { List bitList = Lists.newArrayList( mockBit1, mockBit2 ); List> types = Lists.>newArrayList( - Int8.getInstance(), - BitsType.create( mock( SchemaPath.class ) , bitList ), - BooleanType.getInstance() ); + Int8.getInstance(), + BitsType.create( mock( SchemaPath.class ) , bitList ), + BooleanType.getInstance() ); UnionType unionType = UnionType.create( types ); String elName = "lfUnion"; @@ -253,7 +252,7 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader { + elName + ">str"); } - private void serializeToXml(CompositeNode compositeNode, String... xmlRepresentation) + private void serializeToXml(final CompositeNode compositeNode, final String... xmlRepresentation) throws TransformerFactoryConfigurationError { String xmlString = ""; try { @@ -275,7 +274,7 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader { } - private CompositeNode prepareIdentityrefData(String prefix, boolean valueAsQName) { + private CompositeNode prepareIdentityrefData(final String prefix, final boolean valueAsQName) { MutableCompositeNode cont = NodeFactory.createMutableCompositeNode( TestUtils.buildQName("cont", "basic:module", "2013-12-2"), null, null, ModifyAction.CREATE, null); MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode( @@ -298,11 +297,11 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader { } private CompositeNode prepareCnStructForYangData(final Object data, final String leafName) { - MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null, - ModifyAction.CREATE, null); + MutableCompositeNode cont = NodeFactory.createMutableCompositeNode( + TestUtils.buildQName("cont", "basic:module", "2013-12-2"), null, null, ModifyAction.CREATE, null); - MutableSimpleNode lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName(leafName), cont, data, - ModifyAction.CREATE, null); + MutableSimpleNode lf1 = NodeFactory.createMutableSimpleNode( + TestUtils.buildQName(leafName, "basic:module", "2013-12-2"), cont, data, ModifyAction.CREATE, null); cont.getValue().add(lf1); cont.init();