X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-protocolbuffer-encoding%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futil%2FNormalizedNodeXmlConverterTest.java;h=853b3e264bdc9b4b58eed7e1ca95363eaa64e6be;hb=eb887b1c2c8cd2768f8b4c2ed2b5054f97798466;hp=45e3ea5be32f6a62f8a394cd2afb0fc5680ff06a;hpb=4a3ab064cc93fb545b7c1352f444e50b5c7227fa;p=controller.git diff --git a/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/util/NormalizedNodeXmlConverterTest.java b/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/util/NormalizedNodeXmlConverterTest.java index 45e3ea5be3..853b3e264b 100644 --- a/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/util/NormalizedNodeXmlConverterTest.java +++ b/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/util/NormalizedNodeXmlConverterTest.java @@ -1,9 +1,11 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * - * This program and the accompanying materials are made available under the terms of the Eclipse - * Public License v1.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.controller.cluster.datastore.util; @@ -14,9 +16,9 @@ import com.google.common.collect.Sets; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import org.junit.Test; -import org.opendaylight.controller.cluster.datastore.common.SimpleNormalizedNodeMessage; +import org.opendaylight.controller.protobuff.messages.common.SimpleNormalizedNodeMessage; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; @@ -62,6 +64,7 @@ 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; @@ -70,8 +73,8 @@ import java.util.Set; /** - * Two of the testcases in the yangtools/yang-data-impl are leveraged (with modification) to - * create the serialization of NormalizedNode using the ProtocolBuffer + * Two of the testcases in the yangtools/yang-data-impl are leveraged (with modification) to create + * the serialization of NormalizedNode using the ProtocolBuffer * * @syedbahm * @@ -96,8 +99,8 @@ public class NormalizedNodeXmlConverterTest { } } - public static DataSchemaNode getSchemaNode(SchemaContext context, - String moduleName, String childNodeName) { + 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 = @@ -111,12 +114,14 @@ public class NormalizedNodeXmlConverterTest { + childNodeName); } - static DataSchemaNode findChildNode(Set children, String name) { + static DataSchemaNode findChildNode( + final Collection children, final String name) { List containers = Lists.newArrayList(); for (DataSchemaNode dataSchemaNode : children) { - if (dataSchemaNode.getQName().getLocalName().equals(name)) + if (dataSchemaNode.getQName().getLocalName().equals(name)) { return dataSchemaNode; + } if (dataSchemaNode instanceof DataNodeContainer) { containers.add((DataNodeContainer) dataSchemaNode); } else if (dataSchemaNode instanceof ChoiceNode) { @@ -134,27 +139,27 @@ public class NormalizedNodeXmlConverterTest { return null; } - private static InstanceIdentifier.NodeIdentifier getNodeIdentifier( - String localName) { - return new InstanceIdentifier.NodeIdentifier(new QName( + public static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier( + final String localName) { + return new YangInstanceIdentifier.NodeIdentifier(QName.create( URI.create(NAMESPACE), revision, localName)); } - public static InstanceIdentifier.AugmentationIdentifier getAugmentIdentifier( - String... childNames) { + public static YangInstanceIdentifier.AugmentationIdentifier getAugmentIdentifier( + final String... childNames) { Set qn = Sets.newHashSet(); for (String childName : childNames) { qn.add(getNodeIdentifier(childName).getNodeType()); } - return new InstanceIdentifier.AugmentationIdentifier(qn); + return new YangInstanceIdentifier.AugmentationIdentifier(qn); } - private static ContainerNode augmentChoiceExpectedNode() { + public static ContainerNode augmentChoiceExpectedNode() { - DataContainerNodeBuilder b = + DataContainerNodeBuilder b = Builders.containerBuilder(); b.withNodeIdentifier(getNodeIdentifier("container")); @@ -233,8 +238,8 @@ public class NormalizedNodeXmlConverterTest { - public void init(String yangPath, String xmlPath, ContainerNode expectedNode) - throws Exception { + public void init(final String yangPath, final String xmlPath, + final ContainerNode expectedNode) throws Exception { SchemaContext schema = parseTestSchema(yangPath); this.xmlPath = xmlPath; this.containerNode = @@ -242,7 +247,7 @@ public class NormalizedNodeXmlConverterTest { this.expectedNode = expectedNode; } - SchemaContext parseTestSchema(String yangPath) throws Exception { + SchemaContext parseTestSchema(final String yangPath) throws Exception { YangParserImpl yangParserImpl = new YangParserImpl(); InputStream stream = @@ -268,8 +273,9 @@ public class NormalizedNodeXmlConverterTest { .parse(Collections.singletonList(doc.getDocumentElement()), containerNode); - if (expectedNode != null) + if (expectedNode != null) { junit.framework.Assert.assertEquals(expectedNode, built); + } logger.info("{}", built); @@ -287,14 +293,12 @@ public class NormalizedNodeXmlConverterTest { System.out.println(toString(doc.getDocumentElement())); System.out.println(toString(el)); - boolean diff = - new Diff( - XMLUnit.buildControlDocument(toString(doc.getDocumentElement())), - XMLUnit.buildTestDocument(toString(el))).similar(); + new Diff(XMLUnit.buildControlDocument(toString(doc.getDocumentElement())), + XMLUnit.buildTestDocument(toString(el))).similar(); } private static ContainerNode listLeafListWithAttributes() { - DataContainerNodeBuilder b = + DataContainerNodeBuilder b = Builders.containerBuilder(); b.withNodeIdentifier(getNodeIdentifier("container")); @@ -304,11 +308,11 @@ public class NormalizedNodeXmlConverterTest { Map predicates = Maps.newHashMap(); predicates.put(getNodeIdentifier("uint32InList").getNodeType(), 3L); - DataContainerNodeBuilder list1Builder = + DataContainerNodeBuilder list1Builder = Builders.mapEntryBuilder().withNodeIdentifier( - new InstanceIdentifier.NodeIdentifierWithPredicates( + new YangInstanceIdentifier.NodeIdentifierWithPredicates( getNodeIdentifier("list").getNodeType(), predicates)); - NormalizedNodeBuilder> uint32InListBuilder = + NormalizedNodeBuilder> uint32InListBuilder = Builders.leafBuilder().withNodeIdentifier( getNodeIdentifier("uint32InList")); @@ -317,7 +321,7 @@ public class NormalizedNodeXmlConverterTest { listBuilder.withChild(list1Builder.build()); b.withChild(listBuilder.build()); - NormalizedNodeBuilder> booleanBuilder = + NormalizedNodeBuilder> booleanBuilder = Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean")); booleanBuilder.withValue(false); b.withChild(booleanBuilder.build()); @@ -326,10 +330,10 @@ public class NormalizedNodeXmlConverterTest { Builders.leafSetBuilder().withNodeIdentifier( getNodeIdentifier("leafList")); - NormalizedNodeBuilder> leafList1Builder = + NormalizedNodeBuilder> leafList1Builder = Builders.leafSetEntryBuilder().withNodeIdentifier( - new InstanceIdentifier.NodeWithValue(getNodeIdentifier("leafList") - .getNodeType(), "a")); + new YangInstanceIdentifier.NodeWithValue(getNodeIdentifier( + "leafList").getNodeType(), "a")); leafList1Builder.withValue("a"); @@ -353,8 +357,9 @@ public class NormalizedNodeXmlConverterTest { .parse(Collections.singletonList(doc.getDocumentElement()), containerNode); - if (expectedNode != null) + if (expectedNode != null) { junit.framework.Assert.assertEquals(expectedNode, built); + } logger.info("{}", built); @@ -372,14 +377,12 @@ public class NormalizedNodeXmlConverterTest { System.out.println(toString(doc.getDocumentElement())); System.out.println(toString(el)); - boolean diff = - new Diff( - XMLUnit.buildControlDocument(toString(doc.getDocumentElement())), - XMLUnit.buildTestDocument(toString(el))).similar(); + new Diff(XMLUnit.buildControlDocument(toString(doc.getDocumentElement())), + XMLUnit.buildTestDocument(toString(el))).similar(); } - private Document loadDocument(String xmlPath) throws Exception { + private Document loadDocument(final String xmlPath) throws Exception { InputStream resourceAsStream = NormalizedNodeXmlConverterTest.class.getResourceAsStream(xmlPath); @@ -399,7 +402,7 @@ public class NormalizedNodeXmlConverterTest { BUILDERFACTORY = factory; } - private Document readXmlToDocument(InputStream xmlContent) + private Document readXmlToDocument(final InputStream xmlContent) throws IOException, SAXException { DocumentBuilder dBuilder; try { @@ -413,7 +416,7 @@ public class NormalizedNodeXmlConverterTest { return doc; } - public static String toString(Element xml) { + public static String toString(final Element xml) { try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); @@ -442,11 +445,10 @@ public class NormalizedNodeXmlConverterTest { System.out.println(toString(convertedDoc.getDocumentElement())); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); - boolean diff = - new Diff(XMLUnit.buildControlDocument(toString(expectedDoc - .getDocumentElement())), - XMLUnit.buildTestDocument(toString(convertedDoc - .getDocumentElement()))).similar(); + new Diff(XMLUnit.buildControlDocument(toString(expectedDoc + .getDocumentElement())), + XMLUnit.buildTestDocument(toString(convertedDoc.getDocumentElement()))) + .similar(); System.out.println(toString(expectedDoc.getDocumentElement())); } @@ -464,11 +466,10 @@ public class NormalizedNodeXmlConverterTest { System.out.println(toString(convertedDoc.getDocumentElement())); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); - boolean diff = - new Diff(XMLUnit.buildControlDocument(toString(expectedDoc - .getDocumentElement())), - XMLUnit.buildTestDocument(toString(convertedDoc - .getDocumentElement()))).similar(); + 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. @@ -479,24 +480,4 @@ public class NormalizedNodeXmlConverterTest { } - @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); - - - } }