/*
- * 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;
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;
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;
/**
- * 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
*
}
}
- 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 =
+ childNodeName);
}
- static DataSchemaNode findChildNode(Set<DataSchemaNode> children, String name) {
+ 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))
+ if (dataSchemaNode.getQName().getLocalName().equals(name)) {
return dataSchemaNode;
+ }
if (dataSchemaNode instanceof DataNodeContainer) {
containers.add((DataNodeContainer) dataSchemaNode);
} else if (dataSchemaNode instanceof ChoiceNode) {
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<QName> 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<InstanceIdentifier.NodeIdentifier, ContainerNode> b =
+ DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> b =
Builders.containerBuilder();
b.withNodeIdentifier(getNodeIdentifier("container"));
- 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 =
this.expectedNode = expectedNode;
}
- SchemaContext parseTestSchema(String yangPath) throws Exception {
+ SchemaContext parseTestSchema(final String yangPath) throws Exception {
YangParserImpl yangParserImpl = new YangParserImpl();
InputStream stream =
.parse(Collections.singletonList(doc.getDocumentElement()),
containerNode);
- if (expectedNode != null)
+ if (expectedNode != null) {
junit.framework.Assert.assertEquals(expectedNode, built);
+ }
logger.info("{}", built);
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<InstanceIdentifier.NodeIdentifier, ContainerNode> b =
+ DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> b =
Builders.containerBuilder();
b.withNodeIdentifier(getNodeIdentifier("container"));
Map<QName, Object> predicates = Maps.newHashMap();
predicates.put(getNodeIdentifier("uint32InList").getNodeType(), 3L);
- DataContainerNodeBuilder<InstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> list1Builder =
+ DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> list1Builder =
Builders.mapEntryBuilder().withNodeIdentifier(
- new InstanceIdentifier.NodeIdentifierWithPredicates(
+ new YangInstanceIdentifier.NodeIdentifierWithPredicates(
getNodeIdentifier("list").getNodeType(), predicates));
- NormalizedNodeBuilder<InstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> uint32InListBuilder =
+ NormalizedNodeBuilder<YangInstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> uint32InListBuilder =
Builders.leafBuilder().withNodeIdentifier(
getNodeIdentifier("uint32InList"));
listBuilder.withChild(list1Builder.build());
b.withChild(listBuilder.build());
- NormalizedNodeBuilder<InstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> booleanBuilder =
+ NormalizedNodeBuilder<YangInstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> booleanBuilder =
Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean"));
booleanBuilder.withValue(false);
b.withChild(booleanBuilder.build());
Builders.leafSetBuilder().withNodeIdentifier(
getNodeIdentifier("leafList"));
- NormalizedNodeBuilder<InstanceIdentifier.NodeWithValue, Object, LeafSetEntryNode<Object>> leafList1Builder =
+ NormalizedNodeBuilder<YangInstanceIdentifier.NodeWithValue, Object, LeafSetEntryNode<Object>> leafList1Builder =
Builders.leafSetEntryBuilder().withNodeIdentifier(
- new InstanceIdentifier.NodeWithValue(getNodeIdentifier("leafList")
- .getNodeType(), "a"));
+ new YangInstanceIdentifier.NodeWithValue(getNodeIdentifier(
+ "leafList").getNodeType(), "a"));
leafList1Builder.withValue("a");
.parse(Collections.singletonList(doc.getDocumentElement()),
containerNode);
- if (expectedNode != null)
+ if (expectedNode != null) {
junit.framework.Assert.assertEquals(expectedNode, built);
+ }
logger.info("{}", built);
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);
BUILDERFACTORY = factory;
}
- private Document readXmlToDocument(InputStream xmlContent)
+ private Document readXmlToDocument(final InputStream xmlContent)
throws IOException, SAXException {
DocumentBuilder dBuilder;
try {
return doc;
}
- public static String toString(Element xml) {
+ public static String toString(final Element xml) {
try {
Transformer transformer =
TransformerFactory.newInstance().newTransformer();
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()));
}
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.
}
- @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);
-
-
- }
}