Mainly deleting unnecessary methods.
Change-Id: I994c19ee0a9ccc95491e85667fe7ae352f62864f
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
import java.io.IOException;
import java.net.URI;
-import java.util.*;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import javax.activation.UnsupportedDataTypeException;
-import org.opendaylight.controller.sal.restconf.impl.*;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO;
import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.IdentityValue;
+import org.opendaylight.controller.sal.restconf.impl.RestCodec;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.*;
-import org.opendaylight.yangtools.yang.model.api.*;
-import org.opendaylight.yangtools.yang.model.api.type.*;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(type);
+ if (node.getValue() == null && !(baseType instanceof EmptyTypeDefinition)) {
+ logger.debug("While generationg JSON output null value was found for type "
+ + baseType.getClass().getSimpleName() + ".");
+ }
+
// TODO check InstanceIdentifierTypeDefinition
if (baseType instanceof IdentityrefTypeDefinition) {
if (node.getValue() instanceof QName) {
package org.opendaylight.controller.sal.rest.impl;
import javax.activation.UnsupportedDataTypeException;
+
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.codec.LeafrefCodec;
+import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
+import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlCodecProvider;
import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.Leafref;
import org.w3c.dom.Document;
+import com.google.common.base.Optional;
public class XmlMapper {
+ private static final LeafrefCodecImpl LEAFREF_DEFAULT_CODEC = new LeafrefCodecImpl(
+ Optional.<LeafrefTypeDefinition> absent());
+
+ private static class LeafrefCodecImpl extends TypeDefinitionAwareCodec<Object, LeafrefTypeDefinition> implements
+ LeafrefCodec<String> {
+
+ protected LeafrefCodecImpl(Optional<LeafrefTypeDefinition> typeDef) {
+ super(typeDef, Object.class);
+ }
+
+ @Override
+ public String serialize(Object data) {
+ return String.valueOf(data);
+ }
+
+ @Override
+ public Object deserialize(String data) {
+ return data;
+ }
+ }
+
+ private static class XmlCodecProviderImpl implements XmlCodecProvider {
+ @Override
+ public TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> codecFor(TypeDefinition<?> baseType) {
+ TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> codec = TypeDefinitionAwareCodec
+ .from(baseType);
+
+ if (codec == null) {
+ if (baseType instanceof Leafref) {
+ return LEAFREF_DEFAULT_CODEC;
+ }
+ }
+ return codec;
+ }
+ }
+
+ private static final XmlCodecProvider XML_CODEC_PROVIDER_IMPL = new XmlCodecProviderImpl();
+
public Document write(CompositeNode data, DataNodeContainer schema) throws UnsupportedDataTypeException {
- return XmlDocumentUtils.toDocument(data, schema, XmlDocumentUtils.defaultValueCodecProvider());
+ return XmlDocumentUtils.toDocument(data, schema, XML_CODEC_PROVIDER_IMPL);
}
}
package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.StringReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
-import org.opendaylight.controller.sal.restconf.impl.test.structures.*;
-import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.controller.sal.restconf.impl.test.structures.Cont;
+import org.opendaylight.controller.sal.restconf.impl.test.structures.Lf;
+import org.opendaylight.controller.sal.restconf.impl.test.structures.LfLst;
+import org.opendaylight.controller.sal.restconf.impl.test.structures.Lst;
+import org.opendaylight.controller.sal.restconf.impl.test.structures.LstItem;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
import com.google.gson.stream.JsonReader;
*/
@Test
public void xmlAndYangTypesWithJsonReaderTest() {
- CompositeNode compositeNode = TestUtils.loadCompositeNode("/cnsn-to-json/simple-yang-types/xml/data.xml");
+ CompositeNode compositeNode = TestUtils.readInputToCnSn("/cnsn-to-json/simple-yang-types/xml/data.xml",
+ XmlToCompositeNodeProvider.INSTANCE);
TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
String jsonOutput = null;
try {
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
}
private void testWrapper(String xmlPath, String pathToSchemaNode) {
- CompositeNode compNode = TestUtils.loadCompositeNode(xmlPath);
+ CompositeNode compNode = TestUtils.readInputToCnSn(xmlPath, XmlToCompositeNodeProvider.INSTANCE);
TestUtils.normalizeCompositeNode(compNode, modules, pathToSchemaNode);
try {
TestUtils.writeCompNodeWithSchemaContextToOutput(compNode, modules, dataSchemaNode,
package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.StringReader;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import javax.ws.rs.WebApplicationException;
-import javax.xml.bind.DatatypeConverter;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.*;
-import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
@Test
public void simpleYangDataTest() {
- CompositeNode compositeNode = TestUtils.loadCompositeNode("/cnsn-to-json/simple-data-types/xml/data.xml");
+ CompositeNode compositeNode = TestUtils.readInputToCnSn("/cnsn-to-json/simple-data-types/xml/data.xml",
+ XmlToCompositeNodeProvider.INSTANCE);
String jsonOutput = null;
verifyJsonOutput(jsonOutput);
}
- private CompositeNode prepareData() {
- MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
- ModifyAction.CREATE, null);
-
- List<Node<?>> childNodes = new ArrayList<>();
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint8Min"), cont, (byte) -128,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint8Max"), cont, (byte) 127,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint16Min"), cont, (short) -32768,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint16Max"), cont, (short) 32767,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint32Min"), cont,
- (int) -2147483648, ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint32Max"), cont, (int) 2147483647,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint64Min"), cont, new Long(
- "-9223372036854775807"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint64Max"), cont, new Long(
- "9223372036854775807"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint8Max"), cont, (short) 255,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint16Max"), cont, (int) 65535,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint32Max"), cont, new Long(
- "4294967295"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfstr"), cont, "lfstr",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfstr1"), cont, "",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbool1"), cont, Boolean.TRUE,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbool2"), cont, Boolean.FALSE,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal1"), cont, new BigDecimal(
- "43.32"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal2"), cont, new BigDecimal(
- "-0.43"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal3"), cont, new BigDecimal(
- "43"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal4"), cont, new BigDecimal(
- "43E3"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal6"), cont, new BigDecimal(
- "33.12345"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfenum"), cont, "enum3",
- ModifyAction.CREATE, null));
-
- HashSet<String> bits = new HashSet<String>();
- bits.add("bit3");
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbits"), cont, bits,
- ModifyAction.CREATE, null));
-
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbinary"), cont, DatatypeConverter
- .parseBase64Binary("AAaacdabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"),
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfempty"), cont, null,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion1"), cont, (int) 324,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion2"), cont, new BigDecimal(
- "33.3"), ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion3"), cont, "55",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion4"), cont, Boolean.TRUE,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion5"), cont, "true",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion6"), cont, "false",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion7"), cont, null,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion8"), cont, "",
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion9"), cont, "",
- ModifyAction.CREATE, null));
-
- HashSet<String> bits2 = new HashSet<String>();
- bits2.add("bt1");
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion10"), cont, bits2,
- ModifyAction.CREATE, null));
-
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion11"), cont, (short) 33,
- ModifyAction.CREATE, null));
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion12"), cont, Boolean.FALSE,
- ModifyAction.CREATE, null));
- try {
- childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("identityref1"), cont, new QName(
- new URI("simple:data:types"), "iden"), ModifyAction.CREATE, null));
- } catch (URISyntaxException e) {
- }
-
- cont.getChildren().addAll(childNodes);
-
- cont.init();
-
- return cont;
- }
-
private void verifyJsonOutput(String jsonOutput) {
StringReader strReader = new StringReader(jsonOutput);
JsonReader jReader = new JsonReader(strReader);
private void jsonReadContElements(JsonReader jReader) throws IOException {
jReader.beginObject();
List<String> loadedLfs = new ArrayList<>();
- boolean exceptForDecimal5Raised = false;
boolean enumChecked = false;
boolean bitsChecked = false;
boolean lfdecimal6Checked = false;
boolean lfbool2Checked = false;
boolean lfstrChecked = false;
boolean lfbinaryChecked = false;
- // boolean lfref1Checked = false;
boolean lfemptyChecked = false;
boolean lfstr1Checked = false;
boolean lfidentityrefChecked = false;
try {
peek = jReader.peek();
} catch (IOException e) {
- if (keyName.equals("lfdecimal5")) {
- exceptForDecimal5Raised = true;
- } else {
- assertTrue("Key " + keyName + " has incorrect value for specifed type", false);
- }
+ assertTrue("Key " + keyName + " has incorrect value for specifed type", false);
}
if (keyName.startsWith("lfnint") || keyName.startsWith("lfnuint")) {
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.model.api.YangNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Test
public void incorrectTopLevelElementTest() {
- CompositeNode compositeNode = TestUtils.loadCompositeNode("/cnsn-to-json/simple-data-types/xml/data.xml");
+ CompositeNode compositeNode = TestUtils.readInputToCnSn("/cnsn-to-json/simple-data-types/xml/data.xml", XmlToCompositeNodeProvider.INSTANCE);
DataSchemaNode incorrectDataSchema = null;
incorrectDataSchema = new IncorrectDataSchema();
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
private String toJson(String xmlDataPath) {
try {
- CompositeNode compositeNode = TestUtils.loadCompositeNode(xmlDataPath);
+ CompositeNode compositeNode = TestUtils.readInputToCnSn(xmlDataPath, XmlToCompositeNodeProvider.INSTANCE);
TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
return TestUtils.writeCompNodeWithSchemaContextToOutput(compositeNode, modules, dataSchemaNode,
StructuredDataToJsonProvider.INSTANCE);
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
*/
@Test
public void augmentedElementsToJson() {
- CompositeNode compositeNode = TestUtils.loadCompositeNode("/cnsn-to-json/augmentation/xml/data.xml");
+ CompositeNode compositeNode = TestUtils.readInputToCnSn("/cnsn-to-json/augmentation/xml/data.xml",
+ XmlToCompositeNodeProvider.INSTANCE);
TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
String jsonOutput = null;
@Test
public void incorrectTopLevelElementTest() {
- String xmlOutput = null;
+ boolean nullPointerExceptionRaised = false;
try {
- xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
+ TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
(Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(), StructuredDataToXmlProvider.INSTANCE);
} catch (WebApplicationException | IOException e) {
LOG.error("WebApplicationException or IOException was raised");
+ } catch (NullPointerException e) {
+ nullPointerExceptionRaised = true;
}
- assertNotNull(xmlOutput);
- assertTrue(xmlOutput.contains("<lf1>any value</lf1>"));
+ assertTrue(nullPointerExceptionRaised);
}
import javax.ws.rs.WebApplicationException;
import javax.xml.transform.TransformerFactoryConfigurationError;
-import org.junit.*;
+import org.junit.BeforeClass;
+import org.junit.Test;
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;
"<lf11 xmlns:prefix=\"referenced:module\">prefix:iden</lf11>");
}
- @Ignore
@Test
public void snAsYangIdentityrefWithPrefixToXMLTest() {
serializeToXml(prepareIdentityrefData("prefix", false), "<lf11>no qname value</lf11>");
}
- @Ignore
@Test
public void snAsYangLeafrefWithPrefixToXMLTest() {
serializeToXml(prepareLeafrefData(), "<lfBoolean>true</lfBoolean>", "<lfLfref>true</lfLfref>");
package org.opendaylight.controller.sal.restconf.impl.json.to.cnsn.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-import java.io.FileNotFoundException;
-import java.util.*;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import javax.ws.rs.WebApplicationException;
import org.opendaylight.controller.sal.restconf.impl.ResponseException;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.*;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// "simple:data:types1"
Set<Module> modules1 = new HashSet<>();
Set<Module> modules2 = new HashSet<>();
- try {
- modules1 = TestUtils.loadModules(TestUtils.class.getResource("/json-to-cnsn/simple-list-yang/1").getPath());
- modules2 = TestUtils.loadModules(TestUtils.class.getResource("/json-to-cnsn/simple-list-yang/2").getPath());
- } catch (FileNotFoundException e) {
- }
+ modules1 = TestUtils.loadModulesFrom("/json-to-cnsn/simple-list-yang/1");
+ modules2 = TestUtils.loadModulesFrom("/json-to-cnsn/simple-list-yang/2");
assertNotNull(modules1);
assertNotNull(modules2);
JsonToCompositeNodeProvider.INSTANCE);
assertNotNull(compositeNode);
- Set<Module> modules = TestUtils.resolveModulesFrom("/json-to-cnsn/identityref");
+ Set<Module> modules = TestUtils.loadModulesFrom("/json-to-cnsn/identityref");
assertEquals(2, modules.size());
- Module module = TestUtils.resolveModule("identityref-module", modules);
- assertNotNull(module);
- DataSchemaNode dataSchemaNode = TestUtils.resolveDataSchemaNode(null, module);
- assertNotNull(dataSchemaNode);
TestUtils.normalizeCompositeNode(compositeNode, modules, "identityref-module:cont");
assertNotNull(compositeNode);
Set<Module> modules = null;
- try {
- modules = TestUtils.loadModules(TestUtils.class.getResource(yangPath).getPath());
- } catch (FileNotFoundException e) {
- LOG.error(e.getMessage());
- assertTrue(false);
- }
+ modules = TestUtils.loadModulesFrom(yangPath);
assertNotNull(modules);
TestUtils.normalizeCompositeNode(compositeNode, modules, moduleName + ":" + topLevelElementName);
- // TestUtils.supplementNamespace(dataSchemaNode, compositeNode);
assertTrue(compositeNode instanceof CompositeNodeWrapper);
CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap();
package org.opendaylight.controller.sal.restconf.impl.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.FileNotFoundException;
import java.util.Set;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.Mock;
-
-import static org.mockito.Mockito.*;
-
import org.opendaylight.controller.sal.core.api.mount.MountInstance;
import org.opendaylight.controller.sal.core.api.mount.MountService;
import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@BeforeClass
public static void init() throws FileNotFoundException {
- Set<Module> allModules = TestUtils.loadModules(ControllerContextTest.class.getResource("/full-versions/yangs")
- .getPath());
+ Set<Module> allModules = TestUtils.loadModulesFrom("/full-versions/yangs");
+ assertNotNull(allModules);
SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
controllerContext.setSchemas(schemaContext);
}
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.net.*;
-import java.util.*;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Set;
-import org.junit.*;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.sal.restconf.impl.*;
-import org.opendaylight.yangtools.yang.common.*;
-import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
+import org.opendaylight.controller.sal.restconf.impl.StructuredData;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
import org.opendaylight.yangtools.yang.model.api.Module;
@BeforeClass
public static void initialization() {
- modules = TestUtils.resolveModulesFrom("/invoke-rpc");
+ modules = TestUtils.loadModulesFrom("/invoke-rpc");
assertEquals(1, modules.size());
Module module = TestUtils.resolveModule("invoke-rpc-module", modules);
assertNotNull(module);
package org.opendaylight.controller.sal.restconf.impl.test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.logging.Level;
import java.util.logging.LogRecord;
-import javax.ws.rs.core.*;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
-import org.junit.*;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
-import org.opendaylight.controller.sal.restconf.impl.*;
+import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.Module;
@BeforeClass
public static void init() throws FileNotFoundException {
- Set<Module> allModules = TestUtils.loadModules(RestconfImplTest.class.getResource("/full-versions/yangs")
- .getPath());
+ Set<Module> allModules = TestUtils.loadModulesFrom("/full-versions/yangs");
+ assertNotNull(allModules);
SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
controllerContext = ControllerContext.getInstance();
controllerContext.setSchemas(schemaContext);
String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0");
- CompositeNode loadedCompositeNode = TestUtils.loadCompositeNode("/parts/ietf-interfaces_interfaces.xml", true);
+ CompositeNode loadedCompositeNode = TestUtils.readInputToCnSn("/parts/ietf-interfaces_interfaces.xml", true,
+ XmlToCompositeNodeProvider.INSTANCE);
when(brokerFacade.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode);
Response response = target(uri).request(MEDIA_TYPE_DRAFT02).get();
assertEquals(404, response.getStatus());
}
- @Ignore
@Test
public void testReadOperationalData() throws UnsupportedEncodingException, FileNotFoundException {
String uri = createUri("/operational/", "ietf-interfaces:interfaces/interface/eth0");
- CompositeNode loadedCompositeNode = TestUtils.loadCompositeNode("/parts/ietf-interfaces_interfaces.xml");
+ CompositeNode loadedCompositeNode = TestUtils.readInputToCnSn("/parts/ietf-interfaces_interfaces.xml", true,
+ XmlToCompositeNodeProvider.INSTANCE);
+
when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode);
Response response = target(uri).request(MEDIA_TYPE_DRAFT02).get();
package org.opendaylight.controller.sal.restconf.impl.test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.sal.restconf.impl.*;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
+import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.Module;
@BeforeClass
public static void init() throws FileNotFoundException {
- Set<Module> allModules = TestUtils.loadModules(RestconfImplTest.class.getResource("/full-versions/yangs")
- .getPath());
+ Set<Module> allModules = TestUtils.loadModulesFrom("/full-versions/yangs");
+ assertNotNull(allModules);
SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
ControllerContext controllerContext = ControllerContext.getInstance();
controllerContext.setSchemas(schemaContext);
@Test
public void testExample() throws FileNotFoundException {
- CompositeNode loadedCompositeNode = TestUtils.loadCompositeNode("/parts/ietf-interfaces_interfaces.xml");
+ CompositeNode loadedCompositeNode = TestUtils.readInputToCnSn("/parts/ietf-interfaces_interfaces.xml", XmlToCompositeNodeProvider.INSTANCE);
BrokerFacade brokerFacade = mock(BrokerFacade.class);
when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode);
assertEquals(loadedCompositeNode, brokerFacade.readOperationalData(null));
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.io.*;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Date;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;
-import javax.xml.parsers.*;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.transform.*;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.controller.sal.rest.impl.UnsupportedFormatException;
-import org.opendaylight.controller.sal.rest.impl.XmlReader;
-import org.opendaylight.controller.sal.restconf.impl.*;
-import org.opendaylight.controller.sal.restconf.impl.json.to.cnsn.test.JsonToCnSnTest;
+import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
+import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.NodeWrapper;
+import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
+import org.opendaylight.controller.sal.restconf.impl.StructuredData;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
import org.slf4j.Logger;
private final static YangModelParser parser = new YangParserImpl();
- public static Set<Module> loadModules(String resourceDirectory) throws FileNotFoundException {
+ private static Set<Module> loadModules(String resourceDirectory) throws FileNotFoundException {
final File testDir = new File(resourceDirectory);
final String[] fileList = testDir.list();
final List<File> testFiles = new ArrayList<File>();
return parser.parseYangModels(testFiles);
}
+ public static Set<Module> loadModulesFrom(String yangPath) {
+ try {
+ return TestUtils.loadModules(TestUtils.class.getResource(yangPath).getPath());
+ } catch (FileNotFoundException e) {
+ LOG.error("Yang files at path: " + yangPath + " weren't loaded.");
+ }
+
+ return null;
+ }
+
public static SchemaContext loadSchemaContext(Set<Module> modules) {
return parser.resolveSchemaContext(modules);
}
public static SchemaContext loadSchemaContext(String resourceDirectory) throws FileNotFoundException {
- return parser.resolveSchemaContext(loadModules(resourceDirectory));
+ return parser.resolveSchemaContext(loadModulesFrom(resourceDirectory));
}
public static Module findModule(Set<Module> modules, String moduleName) {
- Module result = null;
for (Module module : modules) {
if (module.getName().equals(moduleName)) {
- result = module;
- break;
+ return module;
}
}
- return result;
+ return null;
}
public static Document loadDocumentFrom(InputStream inputStream) {
RestconfImpl restconf = RestconfImpl.getInstance();
ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext(modules));
- prepareMockForRestconfBeforeNormalization(modules, restconf);
+ prepareMocksForRestconf(modules, restconf);
restconf.createConfigurationData(schemaNodePath, compositeNode);
}
+ /**
+ * Searches module with name {@code searchedModuleName} in {@code modules}.
+ * If module name isn't specified and module set has only one element then
+ * this element is returned.
+ *
+ */
public static Module resolveModule(String searchedModuleName, Set<Module> modules) {
- assertNotNull("modules can't be null.", modules);
+ assertNotNull("Modules can't be null.", modules);
if (searchedModuleName != null) {
for (Module m : modules) {
if (m.getName().equals(searchedModuleName)) {
return null;
}
- public static Set<Module> resolveModulesFrom(String yangPath) {
- try {
- return TestUtils.loadModules(TestUtils.class.getResource(yangPath).getPath());
- } catch (FileNotFoundException e) {
- LOG.error("Yang files at path: " + yangPath + " weren't loaded.");
- }
-
- return null;
- }
-
public static DataSchemaNode resolveDataSchemaNode(String searchedDataSchemaName, Module module) {
assertNotNull("Module can't be null", module);
return null;
}
- public static CompositeNode loadCompositeNode(String xmlDataPath) {
- return loadCompositeNode(xmlDataPath, false);
- }
-
- public static CompositeNode loadCompositeNode(String xmlDataPath, boolean addDumyNamespace) {
- InputStream xmlStream = TestUtils.class.getResourceAsStream(xmlDataPath);
- CompositeNode compositeNode = null;
- try {
- XmlReader xmlReader = new XmlReader();
- compositeNode = xmlReader.read(xmlStream);
- } catch (UnsupportedFormatException | XMLStreamException e) {
- LOG.error(e.getMessage());
- }
- if (addDumyNamespace) {
- try {
- addDummyNamespaceToAllNodes((CompositeNodeWrapper) compositeNode);
- } catch (URISyntaxException e) {
- LOG.error(e.getMessage());
- }
- }
- return compositeNode;
- }
-
public static QName buildQName(String name, String uri, String date, String prefix) {
try {
URI u = new URI(uri);
return buildQName(name, "", null);
}
- public static DataSchemaNode obtainSchemaFromYang(String yangFolder) throws FileNotFoundException {
- return obtainSchemaFromYang(yangFolder, null);
- }
-
- public static DataSchemaNode obtainSchemaFromYang(String yangFolder, String moduleName)
- throws FileNotFoundException {
- Set<Module> modules = null;
- modules = TestUtils.loadModules(TestUtils.class.getResource(yangFolder).getPath());
-
- if (modules == null) {
- return null;
- }
- if (modules.size() < 1) {
- return null;
- }
-
- Module moduleRes = null;
- if (modules.size() > 1) {
- if (moduleName == null) {
- return null;
- } else {
- for (Module module : modules) {
- if (module.getName().equals(moduleName)) {
- moduleRes = module;
- }
- }
- if (moduleRes == null) {
- return null;
- }
- }
- } else {
- moduleRes = modules.iterator().next();
- }
-
- if (moduleRes.getChildNodes() == null) {
- return null;
- }
-
- if (moduleRes.getChildNodes().size() != 1) {
- return null;
- }
- DataSchemaNode dataSchemaNode = moduleRes.getChildNodes().iterator().next();
- return dataSchemaNode;
- }
-
- public static void addDummyNamespaceToAllNodes(NodeWrapper<?> wrappedNode) throws URISyntaxException {
+ private static void addDummyNamespaceToAllNodes(NodeWrapper<?> wrappedNode) throws URISyntaxException {
wrappedNode.setNamespace(new URI(""));
if (wrappedNode instanceof CompositeNodeWrapper) {
for (NodeWrapper<?> childNodeWrapper : ((CompositeNodeWrapper) wrappedNode).getValues()) {
}
}
- private static void prepareMockForRestconfBeforeNormalization(Set<Module> modules, RestconfImpl restconf) {
-
+ private static void prepareMocksForRestconf(Set<Module> modules, RestconfImpl restconf) {
ControllerContext controllerContext = ControllerContext.getInstance();
BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
new DummyRpcResult.Builder<TransactionStatus>().result(TransactionStatus.COMMITED)
.build()).build());
- restconf.setControllerContext(ControllerContext.getInstance());
+ restconf.setControllerContext(controllerContext);
restconf.setBroker(mockedBrokerFacade);
}
- public static CompositeNode readInputToCnSn(String jsonPath, boolean dummyNamespaces,
+ public static CompositeNode readInputToCnSn(String path, boolean dummyNamespaces,
MessageBodyReader<CompositeNode> reader) throws WebApplicationException {
- InputStream jsonStream = JsonToCnSnTest.class.getResourceAsStream(jsonPath);
+ InputStream inputStream = TestUtils.class.getResourceAsStream(path);
try {
- CompositeNode compositeNode = reader.readFrom(null, null, null, null, null, jsonStream);
+ CompositeNode compositeNode = reader.readFrom(null, null, null, null, null, inputStream);
assertTrue(compositeNode instanceof CompositeNodeWrapper);
if (dummyNamespaces) {
try {
return null;
}
+ public static CompositeNode readInputToCnSn(String path, MessageBodyReader<CompositeNode> reader) {
+ return readInputToCnSn(path, false, reader);
+ }
+
public static String writeCompNodeWithSchemaContextToOutput(CompositeNode compositeNode, Set<Module> modules,
DataSchemaNode dataSchemaNode, MessageBodyWriter<StructuredData> messageBodyWriter) throws IOException,
WebApplicationException {
byteArrayOS);
return byteArrayOS.toString();
-
}
-
}
package org.opendaylight.controller.sal.restconf.impl.test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.opendaylight.controller.sal.restconf.impl.*;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.*;
-import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@BeforeClass
public static void init() throws FileNotFoundException {
- Set<Module> allModules = TestUtils.loadModules(RestconfImplTest.class.getResource("/full-versions/yangs")
- .getPath());
+ Set<Module> allModules = TestUtils.loadModulesFrom("/full-versions/yangs");
+ assertNotNull(allModules);
SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
controllerContext = ControllerContext.getInstance();
controllerContext.setSchemas(schemaContext);
}
protected static void dataLoad(String yangPath, int modulesNumber, String moduleName, String dataSchemaName) {
- modules = TestUtils.resolveModulesFrom(yangPath);
+ modules = TestUtils.loadModulesFrom(yangPath);
assertEquals(modulesNumber, modules.size());
Module module = TestUtils.resolveModule(moduleName, modules);
searchedModuleName = module == null ? "" : module.getName();
import static org.junit.Assert.*;
-import java.io.*;
-import java.net.URISyntaxException;
import java.util.List;
import java.util.Set;
-import javax.ws.rs.WebApplicationException;
-
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
-import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.*;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
@Test
public void testXmlDataContainer() {
- CompositeNode compNode = compositeNodeFromXml("/xml-to-cnsn/data-container.xml", false);
+ CompositeNode compNode = TestUtils.readInputToCnSn("/xml-to-cnsn/data-container.xml", false,
+ XmlToCompositeNodeProvider.INSTANCE);
assertNotNull(compNode);
- Set<Module> modules = null;
- try {
- modules = TestUtils.loadModules(TestUtils.class.getResource("/xml-to-cnsn/data-container-yang").getPath());
- } catch (FileNotFoundException e) {
- LOG.error(e.getMessage());
- assertTrue(false);
- }
+ Set<Module> modules = TestUtils.loadModulesFrom("/xml-to-cnsn/data-container-yang");
assertNotNull(modules);
TestUtils.normalizeCompositeNode(compNode, modules, "data-container-yang:cont");
@Test
public void testXmlDataList() {
- CompositeNode compNode = compositeNodeFromXml("/xml-to-cnsn/data-list.xml", false);
+ CompositeNode compNode = TestUtils.readInputToCnSn("/xml-to-cnsn/data-list.xml", false,
+ XmlToCompositeNodeProvider.INSTANCE);
assertNotNull(compNode);
- Set<Module> modules = null;
- try {
- modules = TestUtils.loadModules(TestUtils.class.getResource("/xml-to-cnsn/data-list-yang").getPath());
- } catch (FileNotFoundException e) {
- }
+ Set<Module> modules = TestUtils.loadModulesFrom("/xml-to-cnsn/data-list-yang");
assertNotNull(modules);
TestUtils.normalizeCompositeNode(compNode, modules, "data-container-yang:cont");
@Test
public void testXmlEmptyData() {
- CompositeNode compNode = compositeNodeFromXml("/xml-to-cnsn/empty-data.xml", true);
+ CompositeNode compNode = TestUtils.readInputToCnSn("/xml-to-cnsn/empty-data.xml", true,
+ XmlToCompositeNodeProvider.INSTANCE);
assertEquals("cont", compNode.getNodeType().getLocalName());
SimpleNode<?> lf1 = null;
SimpleNode<?> lflst1_1 = null;
assertEquals((short) 100, cont1_lf11.getValue());
}
- private CompositeNode compositeNodeFromXml(String xmlPath, boolean dummyNamespaces) {
- XmlToCompositeNodeProvider xmlToCompositeNodeProvider = XmlToCompositeNodeProvider.INSTANCE;
- try {
- InputStream xmlStream = XmlLeafrefToCnSnTest.class.getResourceAsStream(xmlPath);
- CompositeNode compositeNode = xmlToCompositeNodeProvider.readFrom(null, null, null, null, null, xmlStream);
- if (dummyNamespaces) {
- try {
- TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) compositeNode);
- return ((CompositeNodeWrapper) compositeNode).unwrap();
- } catch (URISyntaxException e) {
- LOG.error(e.getMessage());
- assertTrue(e.getMessage(), false);
- }
- }
- return compositeNode;
-
- } catch (WebApplicationException | IOException e) {
- LOG.error(e.getMessage());
- assertTrue(false);
- }
- return null;
- }
-
private void testIdentityrefToCnSn(String xmlPath, String yangPath, String moduleName, String schemaName,
int moduleCount, String resultLocalName, String resultNamespace) {
- CompositeNode compositeNode = compositeNodeFromXml(xmlPath, false);
+ CompositeNode compositeNode = TestUtils.readInputToCnSn(xmlPath, false, XmlToCompositeNodeProvider.INSTANCE);
assertNotNull(compositeNode);
- Set<Module> modules = TestUtils.resolveModulesFrom(yangPath);
+ Set<Module> modules = TestUtils.loadModulesFrom(yangPath);
assertEquals(moduleCount, modules.size());
- Module module = TestUtils.resolveModule(moduleName, modules);
- assertNotNull(module);
- DataSchemaNode dataSchemaNode = TestUtils.resolveDataSchemaNode(null, module);
- assertNotNull(dataSchemaNode);
TestUtils.normalizeCompositeNode(compositeNode, modules, moduleName + ":" + schemaName);
QName qName = (QName) lf11.getValue();
assertEquals(resultLocalName, qName.getLocalName());
assertEquals(resultNamespace, qName.getNamespace().toString());
-
}
private SimpleNode<?> getLf11(CompositeNode compositeNode) {