From: Jakub Toth Date: Mon, 9 Jan 2017 10:35:00 +0000 (+0100) Subject: Bug 7433 - Remove use of YangSchemaSourceImpl from restconf tests X-Git-Tag: release/carbon~93 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=0e68dd223c2e1c949bc4ebb204ea3a2730a62fc4;p=netconf.git Bug 7433 - Remove use of YangSchemaSourceImpl from restconf tests Change-Id: I3a5901618cbe162eed07cf0301626e6228df4360 Signed-off-by: Jakub Toth --- diff --git a/restconf/sal-rest-connector/pom.xml b/restconf/sal-rest-connector/pom.xml index 098c1b3f0d..14d4cf3ac1 100644 --- a/restconf/sal-rest-connector/pom.xml +++ b/restconf/sal-rest-connector/pom.xml @@ -90,6 +90,10 @@ org.opendaylight.yangtools yang-parser-impl + + org.opendaylight.yangtools + yang-test-util + org.opendaylight.mdsal.model ietf-restconf diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/md/sal/rest/common/TestRestconfUtils.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/md/sal/rest/common/TestRestconfUtils.java index 029c3c9bf7..1ba0f3f893 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/md/sal/rest/common/TestRestconfUtils.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/md/sal/rest/common/TestRestconfUtils.java @@ -8,19 +8,17 @@ package org.opendaylight.controller.md.sal.rest.common; +import com.google.common.base.Preconditions; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; - import org.opendaylight.controller.sal.rest.impl.test.providers.TestJsonBodyWriter; import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext; @@ -35,28 +33,20 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -import com.google.common.base.Preconditions; - /** - * sal-rest-connector - * org.opendaylight.controller.md.sal.rest.common + * sal-rest-connector org.opendaylight.controller.md.sal.rest.common * * * * @author Vaclav Demcak * - * Created: Mar 7, 2015 + * Created: Mar 7, 2015 */ public class TestRestconfUtils { @@ -82,21 +72,20 @@ public class TestRestconfUtils { BUILDERFACTORY = factory; } - private TestRestconfUtils () { + private TestRestconfUtils() { throw new UnsupportedOperationException("Test utility class"); } public static SchemaContext loadSchemaContext(final String yangPath, final SchemaContext schemaContext) { try { Preconditions.checkArgument(yangPath != null, "Path can not be null."); - Preconditions.checkArgument(( ! yangPath.isEmpty()), "Path can not be empty."); + Preconditions.checkArgument((!yangPath.isEmpty()), "Path can not be empty."); if (schemaContext == null) { - return loadSchemaContext(yangPath); + return YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(yangPath)); } else { throw new UnsupportedOperationException("Unable to add new yang sources to existing schema context."); } - } - catch (final Exception e) { + } catch (final Exception e) { LOG.error("Yang files at path: " + yangPath + " weren't loaded."); } return schemaContext; @@ -106,7 +95,8 @@ public class TestRestconfUtils { throw new AbstractMethodError("Not implemented yet"); } - public static NormalizedNodeContext loadNormalizedContextFromXmlFile(final String pathToInputFile, final String uri) { + public static NormalizedNodeContext loadNormalizedContextFromXmlFile(final String pathToInputFile, + final String uri) { final InstanceIdentifierContext iiContext = ControllerContext.getInstance().toInstanceIdentifier(uri); final InputStream inputStream = TestJsonBodyWriter.class.getResourceAsStream(pathToInputFile); try { @@ -114,8 +104,7 @@ public class TestRestconfUtils { final Document doc = dBuilder.parse(inputStream); final NormalizedNode nn = parse(iiContext, doc); return new NormalizedNodeContext(iiContext, nn); - } - catch (final Exception e) { + } catch (final Exception e) { LOG.error("Load xml file " + pathToInputFile + " fail.", e); } return null; @@ -152,12 +141,13 @@ public class TestRestconfUtils { } } } - final DomToNormalizedNodeParserFactory parserFactory = - DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, iiContext.getSchemaContext()); + final DomToNormalizedNodeParserFactory parserFactory = DomToNormalizedNodeParserFactory + .getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, iiContext.getSchemaContext()); - if(schemaNode instanceof ContainerSchemaNode) { - return parserFactory.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()), (ContainerSchemaNode) schemaNode); - } else if(schemaNode instanceof ListSchemaNode) { + if (schemaNode instanceof ContainerSchemaNode) { + return parserFactory.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()), + (ContainerSchemaNode) schemaNode); + } else if (schemaNode instanceof ListSchemaNode) { final ListSchemaNode casted = (ListSchemaNode) schemaNode; return parserFactory.getMapEntryNodeParser().parse(elements, casted); } // FIXME : add another DataSchemaNode extensions e.g. LeafSchemaNode @@ -180,22 +170,4 @@ public class TestRestconfUtils { } return testFiles; } - - public static SchemaContext loadSchemaContext(String resourceDirectory) - throws SourceException, ReactorException, FileNotFoundException, - URISyntaxException { - return parseYangSources(loadFiles(resourceDirectory)); - } - - public static SchemaContext parseYangSources(Collection testFiles) - throws SourceException, ReactorException, FileNotFoundException { - CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR - .newBuild(); - for (File testFile : testFiles) { - reactor.addSource(new YangStatementSourceImpl( - new NamedFileInputStream(testFile, testFile.getPath()))); - } - - return reactor.buildEffective(); - } } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/InstanceIdentifierTypeLeafTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/InstanceIdentifierTypeLeafTest.java index 8439d0cbc4..23eab0435c 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/InstanceIdentifierTypeLeafTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/InstanceIdentifierTypeLeafTest.java @@ -17,12 +17,14 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class InstanceIdentifierTypeLeafTest { @Test public void stringToInstanceIdentifierTest() throws Exception { - final SchemaContext schemaContext = TestRestconfUtils.loadSchemaContext("/instanceidentifier"); + final SchemaContext schemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/instanceidentifier")); ControllerContext.getInstance().setGlobalSchema(schemaContext); final InstanceIdentifierContext instanceIdentifier = ControllerContext.getInstance().toInstanceIdentifier( diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReader.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReader.java index a12dcf014f..b3cc32dcaf 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReader.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReader.java @@ -40,6 +40,7 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * sal-rest-connector @@ -70,7 +71,7 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest { public TestJsonBodyReader () throws NoSuchFieldException, SecurityException { super(); - jsonBodyReader = new JsonNormalizedNodeBodyReader(); + this.jsonBodyReader = new JsonNormalizedNodeBodyReader(); } @Override @@ -83,7 +84,7 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest { final Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc")); - schemaContext = TestRestconfUtils.parseYangSources(testFiles); + schemaContext = YangParserTestUtils.parseYangSources(testFiles); controllerContext.setSchemas(schemaContext); } @@ -93,11 +94,11 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest { schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont")); final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()); final String uri = "instance-identifier-module:cont"; - mockBodyReader(uri, jsonBodyReader, false); + mockBodyReader(uri, this.jsonBodyReader, false); final InputStream inputStream = TestJsonBodyReader.class .getResourceAsStream("/instanceidentifier/json/jsondata.json"); - final NormalizedNodeContext returnValue = jsonBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII); } @@ -110,11 +111,11 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest { final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName); final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName); final String uri = "instance-identifier-module:cont/cont1"; - mockBodyReader(uri, jsonBodyReader, false); + mockBodyReader(uri, this.jsonBodyReader, false); final InputStream inputStream = TestJsonBodyReader.class .getResourceAsStream("/instanceidentifier/json/json_sub_container.json"); - final NormalizedNodeContext returnValue = jsonBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII); } @@ -126,11 +127,11 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest { final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1"); final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName); final String uri = "instance-identifier-module:cont"; - mockBodyReader(uri, jsonBodyReader, true); + mockBodyReader(uri, this.jsonBodyReader, true); final InputStream inputStream = TestJsonBodyReader.class .getResourceAsStream("/instanceidentifier/json/json_sub_container.json"); - final NormalizedNodeContext returnValue = jsonBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII); } @@ -146,11 +147,11 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest { final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()) .node(augII).node(contAugmentQName); final String uri = "instance-identifier-module:cont"; - mockBodyReader(uri, jsonBodyReader, true); + mockBodyReader(uri, this.jsonBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/json/json_augment_container.json"); - final NormalizedNodeContext returnValue = jsonBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII); } @@ -172,11 +173,11 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest { .node(augChoice1II).node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName) .node(containerQName); final String uri = "instance-identifier-module:cont"; - mockBodyReader(uri, jsonBodyReader, true); + mockBodyReader(uri, this.jsonBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/json/json_augment_choice_container.json"); - final NormalizedNodeContext returnValue = jsonBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII); } @@ -184,11 +185,11 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest { @Test public void rpcModuleInputTest() throws Exception { final String uri = "invoke-rpc-module:rpc-test"; - mockBodyReader(uri, jsonBodyReader, true); + mockBodyReader(uri, this.jsonBodyReader, true); final InputStream inputStream = TestJsonBodyReader.class .getResourceAsStream("/invoke-rpc/json/rpc-input.json"); - final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); final ContainerNode inputNode = (ContainerNode) returnValue.getData(); final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReaderMountPoint.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReaderMountPoint.java index 604df056f7..f4f063964d 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReaderMountPoint.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReaderMountPoint.java @@ -40,6 +40,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers @@ -69,7 +70,7 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest { public TestJsonBodyReaderMountPoint() throws NoSuchFieldException, SecurityException { super(); - jsonBodyReader = new JsonNormalizedNodeBodyReader(); + this.jsonBodyReader = new JsonNormalizedNodeBodyReader(); } @Override @@ -82,7 +83,7 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest { final Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc")); - schemaContext = TestRestconfUtils.parseYangSources(testFiles); + schemaContext = YangParserTestUtils.parseYangSources(testFiles); final DOMMountPoint mountInstance = mock(DOMMountPoint.class); when(mountInstance.getSchemaContext()).thenReturn(schemaContext); @@ -99,11 +100,11 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest { final DataSchemaNode dataSchemaNode = schemaContext .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont")); final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont"; - mockBodyReader(uri, jsonBodyReader, false); + mockBodyReader(uri, this.jsonBodyReader, false); final InputStream inputStream = TestJsonBodyReaderMountPoint.class .getResourceAsStream("/instanceidentifier/json/jsondata.json"); - final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkMountPointNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue); } @@ -113,11 +114,11 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest { final DataSchemaNode dataSchemaNode = schemaContext .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont")); final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1"; - mockBodyReader(uri, jsonBodyReader, false); + mockBodyReader(uri, this.jsonBodyReader, false); final InputStream inputStream = TestJsonBodyReaderMountPoint.class .getResourceAsStream("/instanceidentifier/json/json_sub_container.json"); - final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkMountPointNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, QName.create(dataSchemaNode.getQName(), "cont1")); @@ -128,11 +129,11 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest { final DataSchemaNode dataSchemaNode = schemaContext .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont")); final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont"; - mockBodyReader(uri, jsonBodyReader, true); + mockBodyReader(uri, this.jsonBodyReader, true); final InputStream inputStream = TestJsonBodyReaderMountPoint.class .getResourceAsStream("/instanceidentifier/json/json_sub_container.json"); - final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkMountPointNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue); } @@ -140,11 +141,11 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest { @Test public void rpcModuleInputTest() throws Exception { final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-test"; - mockBodyReader(uri, jsonBodyReader, true); + mockBodyReader(uri, this.jsonBodyReader, true); final InputStream inputStream = TestJsonBodyReaderMountPoint.class .getResourceAsStream("/invoke-rpc/json/rpc-input.json"); - final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); final ContainerNode inputNode = (ContainerNode) returnValue.getData(); final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName @@ -179,7 +180,7 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest { .getSchemaContext().getDataChildByName( dataSchemaNode.getQName()); assertNotNull(mountDataSchemaNode); - if (qName != null && dataSchemaNode instanceof DataNodeContainer) { + if ((qName != null) && (dataSchemaNode instanceof DataNodeContainer)) { final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode) .getDataChildByName(qName); dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent) diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyWriter.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyWriter.java index 37d56bfbf1..d708ef822c 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyWriter.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyWriter.java @@ -15,9 +15,7 @@ import java.io.File; import java.io.InputStream; import java.io.OutputStream; import java.util.Collection; - import javax.ws.rs.core.MediaType; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; @@ -25,6 +23,7 @@ import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader; import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter; import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers @@ -43,8 +42,8 @@ public class TestJsonBodyWriter extends AbstractBodyReaderTest { public TestJsonBodyWriter() throws NoSuchFieldException, SecurityException { super(); - jsonBodyWriter = new NormalizedNodeJsonBodyWriter(); - jsonBodyReader = new JsonNormalizedNodeBodyReader(); + this.jsonBodyWriter = new NormalizedNodeJsonBodyWriter(); + this.jsonBodyReader = new JsonNormalizedNodeBodyReader(); } @Override @@ -54,23 +53,23 @@ public class TestJsonBodyWriter extends AbstractBodyReaderTest { @BeforeClass public static void initialization() throws Exception { - Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); + final Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc")); - schemaContext = TestRestconfUtils.parseYangSources(testFiles); + schemaContext = YangParserTestUtils.parseYangSources(testFiles); controllerContext.setSchemas(schemaContext); } @Test public void rpcModuleInputTest() throws Exception { final String uri = "invoke-rpc-module:rpc-test"; - mockBodyReader(uri, jsonBodyReader, true); + mockBodyReader(uri, this.jsonBodyReader, true); final InputStream inputStream = TestJsonBodyWriter.class .getResourceAsStream("/invoke-rpc/json/rpc-output.json"); - final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); final OutputStream output = new ByteArrayOutputStream(); - jsonBodyWriter.writeTo(returnValue, null, null, null, mediaType, null, + this.jsonBodyWriter.writeTo(returnValue, null, null, null, this.mediaType, null, output); assertTrue(output.toString().contains("lf-test")); } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java index e14246434c..5817257b36 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java @@ -37,6 +37,7 @@ import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; 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.test.util.YangParserTestUtils; /** * sal-rest-connector @@ -65,7 +66,7 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { public TestXmlBodyReader () throws NoSuchFieldException, SecurityException { super(); - xmlBodyReader = new XmlNormalizedNodeBodyReader(); + this.xmlBodyReader = new XmlNormalizedNodeBodyReader(); } @Override @@ -78,7 +79,7 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { final Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc")); - schemaContext = TestRestconfUtils.parseYangSources(testFiles); + schemaContext = YangParserTestUtils.parseYangSources(testFiles); controllerContext.setSchemas(schemaContext); } @@ -88,11 +89,11 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont")); final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()); final String uri = "instance-identifier-module:cont"; - mockBodyReader(uri, xmlBodyReader, false); + mockBodyReader(uri, this.xmlBodyReader, false); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xmldata.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII); } @@ -105,11 +106,11 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName); final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName); final String uri = "instance-identifier-module:cont/cont1"; - mockBodyReader(uri, xmlBodyReader, false); + mockBodyReader(uri, this.xmlBodyReader, false); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII); } @@ -121,11 +122,11 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1"); final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName); final String uri = "instance-identifier-module:cont"; - mockBodyReader(uri, xmlBodyReader, true); + mockBodyReader(uri, this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII); } @@ -141,11 +142,11 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()) .node(augII).node(contAugmentQName); final String uri = "instance-identifier-module:cont"; - mockBodyReader(uri, xmlBodyReader, true); + mockBodyReader(uri, this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xml_augment_container.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII); } @@ -166,11 +167,11 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { .node(augChoice1II).node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName) .node(containerQName); final String uri = "instance-identifier-module:cont"; - mockBodyReader(uri, xmlBodyReader, true); + mockBodyReader(uri, this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xml_augment_choice_container.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII); } @@ -178,11 +179,11 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { @Test public void rpcModuleInputTest() throws Exception { final String uri = "invoke-rpc-module:rpc-test"; - mockBodyReader(uri, xmlBodyReader, true); + mockBodyReader(uri, this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/invoke-rpc/xml/rpc-input.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); final ContainerNode contNode = (ContainerNode) returnValue.getData(); final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "cont")); @@ -217,11 +218,11 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { */ @Test public void findFooContainerUsingNamespaceTest() throws Exception { - mockBodyReader("", xmlBodyReader, true); + mockBodyReader("", this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); // check return value checkNormalizedNodeContext(returnValue); @@ -239,11 +240,11 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest { */ @Test public void findBarContainerUsingNamespaceTest() throws Exception { - mockBodyReader("", xmlBodyReader, true); + mockBodyReader("", this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); // check return value checkNormalizedNodeContext(returnValue); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java index 2bb8ece0e1..bc35c07d96 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java @@ -41,6 +41,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers @@ -70,7 +71,7 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { public TestXmlBodyReaderMountPoint() throws NoSuchFieldException, SecurityException { super(); - xmlBodyReader = new XmlNormalizedNodeBodyReader(); + this.xmlBodyReader = new XmlNormalizedNodeBodyReader(); } @Override @@ -83,7 +84,7 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { final Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc")); - schemaContext = TestRestconfUtils.parseYangSources(testFiles); + schemaContext = YangParserTestUtils.parseYangSources(testFiles); final DOMMountPoint mountInstance = mock(DOMMountPoint.class); when(mountInstance.getSchemaContext()).thenReturn(schemaContext); @@ -100,11 +101,11 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { final DataSchemaNode dataSchemaNode = schemaContext .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont")); final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont"; - mockBodyReader(uri, xmlBodyReader, false); + mockBodyReader(uri, this.xmlBodyReader, false); final InputStream inputStream = TestXmlBodyReaderMountPoint.class .getResourceAsStream("/instanceidentifier/xml/xmldata.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkMountPointNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue); } @@ -114,11 +115,11 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { final DataSchemaNode dataSchemaNode = schemaContext .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont")); final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1"; - mockBodyReader(uri, xmlBodyReader, false); + mockBodyReader(uri, this.xmlBodyReader, false); final InputStream inputStream = TestXmlBodyReaderMountPoint.class .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkMountPointNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, QName.create(dataSchemaNode.getQName(), "cont1")); @@ -129,11 +130,11 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { final DataSchemaNode dataSchemaNode = schemaContext .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont")); final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont"; - mockBodyReader(uri, xmlBodyReader, true); + mockBodyReader(uri, this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReaderMountPoint.class .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkMountPointNormalizedNodeContext(returnValue); checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue); } @@ -141,11 +142,11 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { @Test public void rpcModuleInputTest() throws Exception { final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-test"; - mockBodyReader(uri, xmlBodyReader, true); + mockBodyReader(uri, this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReaderMountPoint.class .getResourceAsStream("/invoke-rpc/xml/rpc-input.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null, - null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, + null, null, this.mediaType, null, inputStream); checkNormalizedNodeContext(returnValue); final ContainerNode contNode = (ContainerNode) returnValue.getData(); final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "cont")); @@ -177,7 +178,7 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { .getSchemaContext().getDataChildByName( dataSchemaNode.getQName()); assertNotNull(mountDataSchemaNode); - if (qName != null && dataSchemaNode instanceof DataNodeContainer) { + if ((qName != null) && (dataSchemaNode instanceof DataNodeContainer)) { final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode) .getDataChildByName(qName); dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent) @@ -198,11 +199,11 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { */ @Test public void findFooContainerUsingNamespaceTest() throws Exception { - mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true); + mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); // check return value checkMountPointNormalizedNodeContext(returnValue); @@ -220,11 +221,11 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest { */ @Test public void findBarContainerUsingNamespaceTest() throws Exception { - mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true); + mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, true); final InputStream inputStream = TestXmlBodyReader.class .getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml"); - final NormalizedNodeContext returnValue = xmlBodyReader - .readFrom(null, null, null, mediaType, null, inputStream); + final NormalizedNodeContext returnValue = this.xmlBodyReader + .readFrom(null, null, null, this.mediaType, null, inputStream); // check return value checkMountPointNormalizedNodeContext(returnValue); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyWriter.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyWriter.java index 67e6b6ddf2..3ea5f837b7 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyWriter.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyWriter.java @@ -14,15 +14,14 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.OutputStream; import java.util.Collection; - import javax.ws.rs.core.MediaType; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter; import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers @@ -40,7 +39,7 @@ public class TestXmlBodyWriter extends AbstractBodyReaderTest { public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException { super(); - xmlBodyWriter = new NormalizedNodeXmlBodyWriter(); + this.xmlBodyWriter = new NormalizedNodeXmlBodyWriter(); } @Override @@ -50,10 +49,10 @@ public class TestXmlBodyWriter extends AbstractBodyReaderTest { @BeforeClass public static void initialization() throws Exception { - Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); + final Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc")); - schemaContext = TestRestconfUtils.parseYangSources(testFiles); + schemaContext = YangParserTestUtils.parseYangSources(testFiles); controllerContext.setSchemas(schemaContext); } @@ -64,7 +63,7 @@ public class TestXmlBodyWriter extends AbstractBodyReaderTest { final NormalizedNodeContext nnContext = TestRestconfUtils .loadNormalizedContextFromXmlFile(pathToInputFile, uri); final OutputStream output = new ByteArrayOutputStream(); - xmlBodyWriter.writeTo(nnContext, null, null, null, mediaType, null, + this.xmlBodyWriter.writeTo(nnContext, null, null, null, this.mediaType, null, output); assertTrue(output.toString().contains("lf-test")); } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java index c2e69f7988..fae6281d4a 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java @@ -5,9 +5,6 @@ * 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.sal.restconf.impl.test; import java.lang.reflect.Field; @@ -41,6 +38,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class RestconfImplNotificationSubscribingTest { @@ -61,7 +59,8 @@ public class RestconfImplNotificationSubscribingTest { this.broker.setDomDataBroker(this.domDataBroker); RestconfImpl.getInstance().setBroker(this.broker); - ControllerContext.getInstance().setGlobalSchema(TestRestconfUtils.loadSchemaContext("/notifications")); + ControllerContext.getInstance() + .setGlobalSchema(YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/notifications"))); final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class); final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-14-12", "localName")); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java index 38fc0bba13..e25f253190 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertNotNull; + import com.google.common.base.Preconditions; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; @@ -22,7 +23,9 @@ import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.sql.Date; import java.text.ParseException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; @@ -47,10 +50,8 @@ 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.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -62,8 +63,7 @@ public final class TestUtils { public static SchemaContext loadSchemaContext(final String... yangPath) throws FileNotFoundException, ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - + final List files = new ArrayList<>(); for (int i = 0; i < yangPath.length; i++) { final String path = yangPath[i]; final String pathToFile = TestUtils.class.getResource(path).getPath(); @@ -72,15 +72,16 @@ public final class TestUtils { if (fileList == null) { throw new FileNotFoundException(pathToFile); } + for (int j = 0; j < fileList.length; j++) { final String fileName = fileList[j]; final File file = new File(testDir, fileName); if (file.isDirectory() == false) { - reactor.addSource(new YangStatementSourceImpl(new NamedFileInputStream(file, file.getPath()))); + files.add(new NamedFileInputStream(file, file.getPath())); } } } - return reactor.buildEffective(); + return YangParserTestUtils.parseYangStreams(files); } public static Module findModule(final Set modules, final String moduleName) { @@ -119,7 +120,7 @@ public final class TestUtils { StandardCharsets.UTF_8))); final byte[] charData = out.toByteArray(); return new String(charData, StandardCharsets.UTF_8); - } catch (TransformerException e) { + } catch (final TransformerException e) { final String msg = "Error during transformation of Document into String"; LOG.error(msg, e); return msg; diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/netconf/sal/restconf/impl/InstanceIdentifierCodecImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/netconf/sal/restconf/impl/InstanceIdentifierCodecImplTest.java index de9e1f5458..207dac862a 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/netconf/sal/restconf/impl/InstanceIdentifierCodecImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/netconf/sal/restconf/impl/InstanceIdentifierCodecImplTest.java @@ -10,15 +10,16 @@ package org.opendaylight.netconf.sal.restconf.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.opendaylight.netconf.sal.restconf.impl.RestCodec.InstanceIdentifierCodecImpl; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; +import org.opendaylight.netconf.sal.restconf.impl.RestCodec.InstanceIdentifierCodecImpl; import org.opendaylight.yangtools.concepts.Codec; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class InstanceIdentifierCodecImplTest { @@ -30,26 +31,27 @@ public class InstanceIdentifierCodecImplTest { @Before public void setUp() throws Exception { - schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/parser/deserializer"); - instanceIdentifierDTO = new InstanceIdentifierCodecImpl(null); - ControllerContext.getInstance().setGlobalSchema(schemaContext); + this.schemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser/deserializer")); + this.instanceIdentifierDTO = new InstanceIdentifierCodecImpl(null); + ControllerContext.getInstance().setGlobalSchema(this.schemaContext); final QName baseQName = QName.create("deserializer:test", "2016-06-06", "deserializer-test"); final QName contA = QName.create(baseQName, "contA"); final QName leafList = QName.create(baseQName, "leaf-list-A"); - instanceIdentifierOKLeafList = YangInstanceIdentifier.builder() + this.instanceIdentifierOKLeafList = YangInstanceIdentifier.builder() .node(contA) .node(new YangInstanceIdentifier.NodeWithValue<>(leafList, "instance")) .build(); - instanceIdentifierOKList = YangInstanceIdentifier.builder() + this.instanceIdentifierOKList = YangInstanceIdentifier.builder() .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates( QName.create(baseQName, "list-one-key"), QName.create(QName.create(baseQName, "list-one-key"), "name"), "value")) .build(); - instanceIdentifierBadNamespace = YangInstanceIdentifier.builder() + this.instanceIdentifierBadNamespace = YangInstanceIdentifier.builder() .nodeWithKey(QName.create("nonexistent:module", "2016-10-17", "nonexistent-1"), QName.create("nonexistent:module", "2016-10-17", "nonexistent"), "value") @@ -59,32 +61,32 @@ public class InstanceIdentifierCodecImplTest { @Test public void testSerializeDeserializeList() throws Exception { final IdentityValuesDTO valuesDTO = - instanceIdentifierDTO.serialize(instanceIdentifierOKList); + this.instanceIdentifierDTO.serialize(this.instanceIdentifierOKList); final YangInstanceIdentifier deserializedIdentifier = - instanceIdentifierDTO.deserialize(valuesDTO); - assertEquals(instanceIdentifierOKList, deserializedIdentifier); + this.instanceIdentifierDTO.deserialize(valuesDTO); + assertEquals(this.instanceIdentifierOKList, deserializedIdentifier); } @Test public void testSerializeDeserializeLeafList() throws Exception { final IdentityValuesDTO valuesDTO = - instanceIdentifierDTO.serialize(instanceIdentifierOKLeafList); + this.instanceIdentifierDTO.serialize(this.instanceIdentifierOKLeafList); final YangInstanceIdentifier deserializedIdentifier = - instanceIdentifierDTO.deserialize(valuesDTO); - assertEquals(instanceIdentifierOKLeafList, deserializedIdentifier); + this.instanceIdentifierDTO.deserialize(valuesDTO); + assertEquals(this.instanceIdentifierOKLeafList, deserializedIdentifier); } @Test public void testSerializeDeserializeBadModuleNamespace() throws Exception { final IdentityValuesDTO valuesDTO = - instanceIdentifierDTO.serialize(instanceIdentifierBadNamespace); + this.instanceIdentifierDTO.serialize(this.instanceIdentifierBadNamespace); assertEquals("nonexistent-1", valuesDTO.getValuesWithNamespaces().get(0).getValue()); assertEquals("nonexistent:module", valuesDTO.getValuesWithNamespaces().get(0).getNamespace()); final YangInstanceIdentifier deserializedIdentifier = - instanceIdentifierDTO.deserialize(valuesDTO); + this.instanceIdentifierDTO.deserialize(valuesDTO); assertNull(deserializedIdentifier); } } \ No newline at end of file diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfImplTest.java index 2d1e64517d..a9d4fdec67 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfImplTest.java @@ -20,12 +20,14 @@ import org.opendaylight.restconf.handlers.SchemaContextHandler; import org.opendaylight.restconf.handlers.TransactionChainHandler; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class RestconfImplTest { @Test public void RestImplTest() throws Exception { - final SchemaContext schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/impl"); + final SchemaContext schemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/impl")); final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class); final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceTest.java index 7037bf8429..ded94ef834 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceTest.java @@ -10,6 +10,7 @@ package org.opendaylight.restconf.base.services.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; + import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.CheckedFuture; import java.net.URI; @@ -25,7 +26,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; -import org.opendaylight.restconf.base.services.impl.RestconfOperationsServiceImpl; import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler; import org.opendaylight.restconf.handlers.SchemaContextHandler; import org.opendaylight.restconf.handlers.TransactionChainHandler; @@ -35,6 +35,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class RestconfOperationsServiceTest { @@ -53,7 +54,7 @@ public class RestconfOperationsServiceTest { @Before public void init() throws Exception { MockitoAnnotations.initMocks(this); - this.schemaContext = TestRestconfUtils.loadSchemaContext("/modules"); + this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules")); final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class); final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfSchemaServiceTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfSchemaServiceTest.java index e3f65e7a67..681d25b3e1 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfSchemaServiceTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfSchemaServiceTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.mockito.Mockito.when; + import com.google.common.collect.ImmutableClassToInstanceMap; import java.util.HashMap; import org.junit.Before; @@ -30,7 +31,6 @@ import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext; import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.netconf.sal.restconf.impl.RestconfError; import org.opendaylight.restconf.base.services.api.RestconfSchemaService; -import org.opendaylight.restconf.base.services.impl.RestconfSchemaServiceImpl; import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler; import org.opendaylight.restconf.handlers.SchemaContextHandler; import org.opendaylight.restconf.utils.RestconfConstants; @@ -39,6 +39,7 @@ import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Unit tests for {@code RestconfSchemaService} @@ -81,9 +82,11 @@ public class RestconfSchemaServiceTest { public void setup() throws Exception { MockitoAnnotations.initMocks(this); - this.schemaContext = TestRestconfUtils.loadSchemaContext("/modules"); - this.schemaContextBehindMountPoint = TestRestconfUtils.loadSchemaContext("/modules/modules-behind-mount-point"); - this.schemaContextWithMountPoints = TestRestconfUtils.loadSchemaContext("/modules/mount-points"); + this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules")); + this.schemaContextBehindMountPoint = YangParserTestUtils + .parseYangSources(TestRestconfUtils.loadFiles("/modules/modules-behind-mount-point")); + this.schemaContextWithMountPoints = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules/mount-points")); // create and register mount points this.mountPoint = SimpleDOMMountPoint.create( diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/handlers/SchemaContextHandlerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/handlers/SchemaContextHandlerTest.java index 55d247a353..89aa8fbe13 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/handlers/SchemaContextHandlerTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/handlers/SchemaContextHandlerTest.java @@ -11,6 +11,7 @@ package org.opendaylight.restconf.handlers; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; + import com.google.common.util.concurrent.CheckedFuture; import org.junit.Before; import org.junit.Test; @@ -19,6 +20,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Tests for handling {@link SchemaContext} @@ -44,7 +46,8 @@ public class SchemaContextHandlerTest { Mockito.when(checked.checkedGet()).thenReturn(value); this.schemaContextHandler = new SchemaContextHandler(txHandler); - this.schemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_ACTUAL_SCHEMA_CONTEXT); + this.schemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_ACTUAL_SCHEMA_CONTEXT)); this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext); } @@ -77,7 +80,8 @@ public class SchemaContextHandlerTest { @Test public void onGlobalContextUpdateTest() throws Exception { // create new SchemaContext and update SchemaContextHandler - final SchemaContext newSchemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT); + final SchemaContext newSchemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)); this.schemaContextHandler.onGlobalContextUpdated(newSchemaContext); assertNotEquals("SchemaContextHandler should not has reference to old SchemaContext", diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonBodyReaderTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonBodyReaderTest.java index 80b147be60..4fffdb6d8e 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonBodyReaderTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/JsonBodyReaderTest.java @@ -38,6 +38,7 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class JsonBodyReaderTest extends AbstractBodyReaderTest { @@ -71,7 +72,7 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest { final Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc")); - schemaContext = TestRestconfUtils.parseYangSources(testFiles); + schemaContext = YangParserTestUtils.parseYangSources(testFiles); controllerContext.setSchemas(schemaContext); when(mountPointServiceHandler.get()).thenReturn(mock(DOMMountPointService.class)); } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/XmlBodyReaderTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/XmlBodyReaderTest.java index e1cbb96e5a..3cb0e30f02 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/XmlBodyReaderTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/jersey/providers/XmlBodyReaderTest.java @@ -34,6 +34,7 @@ import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; 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.test.util.YangParserTestUtils; public class XmlBodyReaderTest extends AbstractBodyReaderTest { @@ -65,7 +66,7 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest { final Collection testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang"); testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc")); - schemaContext = TestRestconfUtils.parseYangSources(testFiles); + schemaContext = YangParserTestUtils.parseYangSources(testFiles); controllerContext.setSchemas(schemaContext); when(mountPointServiceHandler.get()).thenReturn(mock(DOMMountPointService.class)); } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/IdentifierCodecTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/IdentifierCodecTest.java index e1cdd8ba6b..9a60be5adc 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/IdentifierCodecTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/IdentifierCodecTest.java @@ -10,11 +10,13 @@ package org.opendaylight.restconf.parser; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; + import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Unit tests for {@link IdentifierCodec} mostly according to examples from draft-ietf-netconf-restconf-13 @@ -23,14 +25,13 @@ public class IdentifierCodecTest { private static final String URI_WITH_LIST_AND_LEAF = "list-test:top/list1=%2C%27" + '"' + "%3A" + '"' + "%20%2F,,foo/list2=a,b/result"; - private static final String URI_WITH_LEAF_LIST = "list-test:top/Y=x%3Ay"; private static final String URI_WITH_INT_VAL_LEAF_LIST = "list-test:top/Y=4"; private SchemaContext schemaContext; @Before public void init() throws Exception { - this.schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/parser"); + this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser")); } /** @@ -41,11 +42,11 @@ public class IdentifierCodecTest { @Test public void codecListAndLeafTest() { final YangInstanceIdentifier dataYangII = IdentifierCodec.deserialize( - this.URI_WITH_LIST_AND_LEAF, this.schemaContext); + IdentifierCodecTest.URI_WITH_LIST_AND_LEAF, this.schemaContext); final String serializedDataYangII = IdentifierCodec.serialize(dataYangII, this.schemaContext); assertEquals("Failed codec deserialization and serialization test", - this.URI_WITH_LIST_AND_LEAF, serializedDataYangII); + IdentifierCodecTest.URI_WITH_LIST_AND_LEAF, serializedDataYangII); } /** @@ -56,11 +57,11 @@ public class IdentifierCodecTest { @Test public void codecLeafListTest() { final YangInstanceIdentifier dataYangII = IdentifierCodec.deserialize( - this.URI_WITH_INT_VAL_LEAF_LIST, this.schemaContext); + IdentifierCodecTest.URI_WITH_INT_VAL_LEAF_LIST, this.schemaContext); final String serializedDataYangII = IdentifierCodec.serialize(dataYangII, this.schemaContext); assertEquals("Failed codec deserialization and serialization test", - this.URI_WITH_INT_VAL_LEAF_LIST, serializedDataYangII); + IdentifierCodecTest.URI_WITH_INT_VAL_LEAF_LIST, serializedDataYangII); } /** diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierDeserializerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierDeserializerTest.java index e6d24ec251..47cd097ecd 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierDeserializerTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierDeserializerTest.java @@ -11,6 +11,7 @@ package org.opendaylight.restconf.parser.builder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; + import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import java.util.Iterator; @@ -27,6 +28,7 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Unit tests for {@link YangInstanceIdentifierDeserializer} @@ -41,7 +43,8 @@ public class YangInstanceIdentifierDeserializerTest { @Before public void init() throws Exception { - this.schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/parser/deserializer"); + this.schemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser/deserializer")); } /** diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializerTest.java index b05f43f4f6..582ecdc6c0 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializerTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializerTest.java @@ -25,6 +25,7 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Unit tests for {@link YangInstanceIdentifierSerializer} @@ -39,7 +40,8 @@ public class YangInstanceIdentifierSerializerTest { @Before public void init() throws Exception { - schemaContext = TestRestconfUtils.loadSchemaContext("/restconf/parser/serializer"); + this.schemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/restconf/parser/serializer")); } /** @@ -52,7 +54,7 @@ public class YangInstanceIdentifierSerializerTest { .node(QName.create("serializer:test", "2016-06-06", "contA")) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:contA", result); } @@ -68,7 +70,7 @@ public class YangInstanceIdentifierSerializerTest { .node(QName.create("serializer:test", "2016-06-06", "leaf-A")) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:contA/leaf-A", result); } @@ -90,7 +92,7 @@ public class YangInstanceIdentifierSerializerTest { .node(new NodeWithValue(leafList, "instance")) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:contA/list-A=100/leaf-list-AA=instance", result); @@ -108,7 +110,7 @@ public class YangInstanceIdentifierSerializerTest { .nodeWithKey(QName.create("serializer:test", "2016-06-06", "list-no-key"), Maps.newHashMap()) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:list-no-key", result); } @@ -125,7 +127,7 @@ public class YangInstanceIdentifierSerializerTest { QName.create("serializer:test", "2016-06-06", "list-one-key"), "value") .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:list-one-key=value", result); } @@ -145,7 +147,7 @@ public class YangInstanceIdentifierSerializerTest { final YangInstanceIdentifier data = YangInstanceIdentifier.builder() .node(list).nodeWithKey(list, values).build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:list-multiple-keys=value-1,2,true", result); } @@ -160,7 +162,7 @@ public class YangInstanceIdentifierSerializerTest { .node(QName.create("serializer:test", "2016-06-06", "leaf-0")) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:leaf-0", result); } @@ -176,7 +178,7 @@ public class YangInstanceIdentifierSerializerTest { .node(new NodeWithValue(QName.create("serializer:test", "2016-06-06", "leaf-list-0"), "instance")) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:leaf-list-0=instance", result); } @@ -187,7 +189,7 @@ public class YangInstanceIdentifierSerializerTest { */ @Test public void serializeNullSchemaContextNegativeTest() { - thrown.expect(NullPointerException.class); + this.thrown.expect(NullPointerException.class); YangInstanceIdentifierSerializer.create(null, YangInstanceIdentifier.EMPTY); } @@ -198,8 +200,8 @@ public class YangInstanceIdentifierSerializerTest { */ @Test public void serializeNullDataNegativeTest() { - thrown.expect(NullPointerException.class); - YangInstanceIdentifierSerializer.create(schemaContext, null); + this.thrown.expect(NullPointerException.class); + YangInstanceIdentifierSerializer.create(this.schemaContext, null); } /** @@ -209,7 +211,7 @@ public class YangInstanceIdentifierSerializerTest { */ @Test public void serializeEmptyDataTest() { - final String result = YangInstanceIdentifierSerializer.create(schemaContext, YangInstanceIdentifier.EMPTY); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, YangInstanceIdentifier.EMPTY); assertTrue("Empty identifier is expected", result.isEmpty()); } @@ -224,8 +226,8 @@ public class YangInstanceIdentifierSerializerTest { .node(QName.create("serializer:test", "2016-06-06", "not-existing-leaf")) .build(); - thrown.expect(IllegalArgumentException.class); - YangInstanceIdentifierSerializer.create(schemaContext, data); + this.thrown.expect(IllegalArgumentException.class); + YangInstanceIdentifierSerializer.create(this.schemaContext, data); } /** @@ -262,7 +264,7 @@ public class YangInstanceIdentifierSerializerTest { QName.create("serializer:test", "2016-06-06", "list-one-key"), value) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:list-one-key=" + encoded, result); } @@ -279,7 +281,7 @@ public class YangInstanceIdentifierSerializerTest { QName.create("serializer:test", "2016-06-06", "list-one-key"), value) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test:list-one-key=" + value, result); } @@ -300,7 +302,7 @@ public class YangInstanceIdentifierSerializerTest { .node(child) .build(); - final String result = YangInstanceIdentifierSerializer.create(schemaContext, data); + final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); assertEquals("Serialization not successful", "serializer-test-included:augmented-list=100/serializer-test:augmented-leaf", result); @@ -326,7 +328,7 @@ public class YangInstanceIdentifierSerializerTest { .node(child) .build(); - thrown.expect(IllegalArgumentException.class); - YangInstanceIdentifierSerializer.create(schemaContext, data); + this.thrown.expect(IllegalArgumentException.class); + YangInstanceIdentifierSerializer.create(this.schemaContext, data); } } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImplTest.java index d838d4be29..99e598315d 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImplTest.java @@ -17,6 +17,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; + import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; @@ -67,6 +68,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaNode; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class RestconfDataServiceImplTest { @@ -165,7 +167,8 @@ public class RestconfDataServiceImplTest { .node(this.baseQName) .build(); - this.contextRef = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT)); + this.contextRef = new SchemaContextRef( + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT))); this.schemaNode = DataSchemaContextTree.from(this.contextRef.get()).getChild(this.iidBase).getDataSchemaNode(); final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImplTest.java index df5b1c63a5..378e53ae84 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImplTest.java @@ -33,6 +33,7 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class RestconfInvokeOperationsServiceImplTest { @@ -49,7 +50,8 @@ public class RestconfInvokeOperationsServiceImplTest { @Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); - final SchemaContextRef contextRef = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT)); + final SchemaContextRef contextRef = new SchemaContextRef( + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT))); final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class); final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class); Mockito.when(txHandler.get()).thenReturn(domTx); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java index 7a8fcd327f..b441109ec5 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; + import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import java.lang.reflect.Field; @@ -49,6 +50,7 @@ import org.opendaylight.restconf.handlers.TransactionChainHandler; import org.opendaylight.restconf.parser.IdentifierCodec; import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType; import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class RestconfStreamsSubscriptionServiceImplTest { @@ -97,7 +99,8 @@ public class RestconfStreamsSubscriptionServiceImplTest { final Set>> set = new HashSet<>(); Mockito.when(map.entrySet()).thenReturn(set); Mockito.when(this.uriInfo.getQueryParameters()).thenReturn(map); - this.schemaHandler.onGlobalContextUpdated(TestRestconfUtils.loadSchemaContext("/notifications")); + this.schemaHandler.onGlobalContextUpdated( + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/notifications"))); } @BeforeClass diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/CreateStreamUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/CreateStreamUtilTest.java index 0ab186c305..4565d6a61c 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/CreateStreamUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/CreateStreamUtilTest.java @@ -11,6 +11,7 @@ package org.opendaylight.restconf.restful.utils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; + import java.util.Collections; import java.util.Set; import org.junit.Before; @@ -36,6 +37,7 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class CreateStreamUtilTest { @@ -47,7 +49,8 @@ public class CreateStreamUtilTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - this.refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT)); + this.refSchemaCtx = new SchemaContextRef( + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT))); } @Test diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PatchDataTransactionUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PatchDataTransactionUtilTest.java index 283db9b201..08c11be9e2 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PatchDataTransactionUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PatchDataTransactionUtilTest.java @@ -45,6 +45,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.model.api.SchemaNode; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class PatchDataTransactionUtilTest { @@ -81,7 +82,8 @@ public class PatchDataTransactionUtilTest { PatchDataTransactionUtilTest.broker.setAccessible(true); PatchDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class)); - refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT)); + this.refSchemaCtx = new SchemaContextRef( + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT))); final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox"); final QName containerPlayerQName = QName.create(baseQName, "player"); final QName leafGapQName = QName.create(baseQName, "gap"); @@ -92,7 +94,7 @@ public class PatchDataTransactionUtilTest { new YangInstanceIdentifier.NodeIdentifierWithPredicates(listArtistQName, leafNameQName, "name of artist"); /** instance identifier for accessing leaf node "gap" */ - iIDCreateAndDelete = YangInstanceIdentifier.builder() + this.iIDCreateAndDelete = YangInstanceIdentifier.builder() .node(baseQName) .node(containerPlayerQName) .node(leafGapQName) @@ -109,18 +111,18 @@ public class PatchDataTransactionUtilTest { .withChild(buildGapLeaf) .build(); - buildBaseContainerForTests = Builders.containerBuilder() + this.buildBaseContainerForTests = Builders.containerBuilder() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(baseQName)) .withChild(buildPlayerContainer) .build(); - targetNodeForCreateAndDelete = YangInstanceIdentifier.builder(iIDCreateAndDelete) + this.targetNodeForCreateAndDelete = YangInstanceIdentifier.builder(this.iIDCreateAndDelete) .node(containerPlayerQName) .node(leafGapQName) .build(); /** instance identifier for accessing leaf node "name" in list "artist" */ - iIDMerge = YangInstanceIdentifier.builder() + this.iIDMerge = YangInstanceIdentifier.builder() .node(baseQName) .node(containerLibraryQName) .node(listArtistQName) @@ -145,12 +147,12 @@ public class PatchDataTransactionUtilTest { .withChild(contentDescription) .build(); - buildArtistList = Builders.mapBuilder() + this.buildArtistList = Builders.mapBuilder() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listArtistQName)) .withChild(mapEntryNode) .build(); - targetNodeMerge = YangInstanceIdentifier.builder() + this.targetNodeMerge = YangInstanceIdentifier.builder() .node(baseQName) .node(containerLibraryQName) .node(listArtistQName) @@ -158,18 +160,18 @@ public class PatchDataTransactionUtilTest { .build(); /** Mocks */ - doReturn(rWTransaction).when(transactionChain).newReadWriteTransaction(); - doReturn(Futures.immediateCheckedFuture(null)).when(rWTransaction).submit(); + doReturn(this.rWTransaction).when(this.transactionChain).newReadWriteTransaction(); + doReturn(Futures.immediateCheckedFuture(null)).when(this.rWTransaction).submit(); } @Test public void testPatchDataReplaceMergeAndRemove() { doReturn(Futures.immediateCheckedFuture(false)).doReturn(Futures.immediateCheckedFuture(true)) - .when(rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, targetNodeMerge); + .when(this.rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeMerge); - final PATCHEntity entityReplace = new PATCHEntity("edit1", "REPLACE", targetNodeMerge, buildArtistList); - final PATCHEntity entityMerge = new PATCHEntity("edit2", "MERGE", targetNodeMerge, buildArtistList); - final PATCHEntity entityRemove = new PATCHEntity("edit3", "REMOVE", targetNodeMerge); + final PATCHEntity entityReplace = new PATCHEntity("edit1", "REPLACE", this.targetNodeMerge, this.buildArtistList); + final PATCHEntity entityMerge = new PATCHEntity("edit2", "MERGE", this.targetNodeMerge, this.buildArtistList); + final PATCHEntity entityRemove = new PATCHEntity("edit3", "REMOVE", this.targetNodeMerge); final List entities = new ArrayList<>(); entities.add(entityReplace); @@ -177,13 +179,13 @@ public class PatchDataTransactionUtilTest { entities.add(entityRemove); final InstanceIdentifierContext iidContext = - new InstanceIdentifierContext<>(iIDMerge, null, null, refSchemaCtx.get()); + new InstanceIdentifierContext<>(this.iIDMerge, null, null, this.refSchemaCtx.get()); final PATCHContext patchContext = new PATCHContext(iidContext, entities, "patchRMRm"); - final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChain); + final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain); final PATCHStatusContext patchStatusContext = - PatchDataTransactionUtil.patchData(patchContext, wrapper, refSchemaCtx); + PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx); - for (PATCHStatusEntity entity : patchStatusContext.getEditCollection()) { + for (final PATCHStatusEntity entity : patchStatusContext.getEditCollection()) { assertTrue(entity.isOk()); } assertTrue(patchStatusContext.isOk()); @@ -192,24 +194,24 @@ public class PatchDataTransactionUtilTest { @Test public void testPatchDataCreateAndDelete() throws Exception { doReturn(Futures.immediateCheckedFuture(false)).doReturn(Futures.immediateCheckedFuture(true)) - .when(rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, targetNodeForCreateAndDelete); + .when(this.rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeForCreateAndDelete); final PATCHEntity entityCreate = - new PATCHEntity("edit1", "CREATE", targetNodeForCreateAndDelete, buildBaseContainerForTests); + new PATCHEntity("edit1", "CREATE", this.targetNodeForCreateAndDelete, this.buildBaseContainerForTests); final PATCHEntity entityDelete = - new PATCHEntity("edit2", "DELETE", targetNodeForCreateAndDelete); + new PATCHEntity("edit2", "DELETE", this.targetNodeForCreateAndDelete); final List entities = new ArrayList<>(); entities.add(entityCreate); entities.add(entityDelete); final InstanceIdentifierContext iidContext = - new InstanceIdentifierContext<>(iIDCreateAndDelete, null, null, refSchemaCtx.get()); + new InstanceIdentifierContext<>(this.iIDCreateAndDelete, null, null, this.refSchemaCtx.get()); final PATCHContext patchContext = new PATCHContext(iidContext, entities, "patchCD"); - final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChain); - final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, refSchemaCtx); + final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain); + final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx); - for (PATCHStatusEntity entity : patchStatusContext.getEditCollection()) { + for (final PATCHStatusEntity entity : patchStatusContext.getEditCollection()) { assertTrue(entity.isOk()); } assertTrue(patchStatusContext.isOk()); @@ -218,19 +220,19 @@ public class PatchDataTransactionUtilTest { @Test public void deleteNonexistentDataTest() { doReturn(Futures.immediateCheckedFuture(false)) - .when(rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, targetNodeForCreateAndDelete); + .when(this.rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeForCreateAndDelete); final PATCHEntity entityDelete = - new PATCHEntity("edit", "DELETE", targetNodeForCreateAndDelete); + new PATCHEntity("edit", "DELETE", this.targetNodeForCreateAndDelete); final List entities = new ArrayList<>(); entities.add(entityDelete); final InstanceIdentifierContext iidContext = - new InstanceIdentifierContext<>(iIDCreateAndDelete, null, null, refSchemaCtx.get()); + new InstanceIdentifierContext<>(this.iIDCreateAndDelete, null, null, this.refSchemaCtx.get()); final PATCHContext patchContext = new PATCHContext(iidContext, entities, "patchD"); - final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChain); - final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, refSchemaCtx); + final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain); + final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx); assertFalse(patchStatusContext.isOk()); assertEquals(RestconfError.ErrorType.PROTOCOL, @@ -242,21 +244,21 @@ public class PatchDataTransactionUtilTest { @Test public void testPatchMergePutContainer() throws Exception { doReturn(Futures.immediateCheckedFuture(false)).doReturn(Futures.immediateCheckedFuture(true)) - .when(rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, targetNodeForCreateAndDelete); + .when(this.rWTransaction).exists(LogicalDatastoreType.CONFIGURATION, this.targetNodeForCreateAndDelete); final PATCHEntity entityMerge = - new PATCHEntity("edit1", "MERGE", targetNodeForCreateAndDelete, buildBaseContainerForTests); + new PATCHEntity("edit1", "MERGE", this.targetNodeForCreateAndDelete, this.buildBaseContainerForTests); final List entities = new ArrayList<>(); entities.add(entityMerge); final InstanceIdentifierContext iidContext = - new InstanceIdentifierContext<>(iIDCreateAndDelete, null, null, refSchemaCtx.get()); + new InstanceIdentifierContext<>(this.iIDCreateAndDelete, null, null, this.refSchemaCtx.get()); final PATCHContext patchContext = new PATCHContext(iidContext, entities, "patchM"); - final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChain); - final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, refSchemaCtx); + final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain); + final PATCHStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx); - for (PATCHStatusEntity entity : patchStatusContext.getEditCollection()) { + for (final PATCHStatusEntity entity : patchStatusContext.getEditCollection()) { assertTrue(entity.isOk()); } assertTrue(patchStatusContext.isOk()); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PostDataTransactionUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PostDataTransactionUtilTest.java index 337c4cbc04..f055b3b701 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PostDataTransactionUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PostDataTransactionUtilTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; + import com.google.common.util.concurrent.Futures; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; @@ -40,6 +41,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.DOMException; public class PostDataTransactionUtilTest { @@ -68,7 +70,8 @@ public class PostDataTransactionUtilTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - this.refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT)); + this.refSchemaCtx = new SchemaContextRef( + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT))); this.schema = this.refSchemaCtx.get(); final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox"); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PutDataTransactionUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PutDataTransactionUtilTest.java index 672dca2896..5083583b11 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PutDataTransactionUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PutDataTransactionUtilTest.java @@ -11,6 +11,7 @@ package org.opendaylight.restconf.restful.utils; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; + import com.google.common.base.Optional; import com.google.common.util.concurrent.Futures; import org.junit.Before; @@ -38,6 +39,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class PutDataTransactionUtilTest { @@ -69,7 +71,8 @@ public class PutDataTransactionUtilTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - this.refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT)); + this.refSchemaCtx = new SchemaContextRef( + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT))); this.schema = this.refSchemaCtx.get(); final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox"); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/mapping/RestconfMappingNodeUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/mapping/RestconfMappingNodeUtilTest.java index f650f85a56..758bca72a0 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/mapping/RestconfMappingNodeUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/mapping/RestconfMappingNodeUtilTest.java @@ -10,6 +10,7 @@ package org.opendaylight.restconf.utils.mapping; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.when; + import java.net.URI; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -50,6 +51,7 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Unit tests for {@link RestconfMappingNodeUtil} @@ -73,11 +75,12 @@ public class RestconfMappingNodeUtilTest { @BeforeClass public static void loadTestSchemaContextAndModules() throws Exception { - schemaContext = TestRestconfUtils.loadSchemaContext( - "/modules/restconf-module-testing"); - schemaContextMonitoring = TestRestconfUtils.loadSchemaContext("/modules"); + schemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules/restconf-module-testing")); + schemaContextMonitoring = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules")); modules = schemaContextMonitoring.getModules(); - modulesRest = TestRestconfUtils.loadSchemaContext("/modules/restconf-module-testing").getModules(); + modulesRest = YangParserTestUtils + .parseYangSources(TestRestconfUtils.loadFiles("/modules/restconf-module-testing")).getModules(); } @Before diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserFieldsParameterTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserFieldsParameterTest.java index 4ba30236b5..7b6f144851 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserFieldsParameterTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserFieldsParameterTest.java @@ -33,6 +33,7 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Unit test for {@link ParserFieldsParameter} @@ -75,40 +76,41 @@ public class ParserFieldsParameterTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - final SchemaContext schemaContext = TestRestconfUtils.loadSchemaContext("/jukebox"); + final SchemaContext schemaContext = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/jukebox")); final QNameModule qNameModule = QNameModule.create(URI.create("http://example.com/ns/example-jukebox"), new SimpleDateFormat("yyyy-MM-dd").parse("2015-04-04")); - jukeboxQName = QName.create(qNameModule, "jukebox"); - playerQName = QName.create(qNameModule, "player"); - libraryQName = QName.create(qNameModule, "library"); - augmentedLibraryQName = QName.create( + this.jukeboxQName = QName.create(qNameModule, "jukebox"); + this.playerQName = QName.create(qNameModule, "player"); + this.libraryQName = QName.create(qNameModule, "library"); + this.augmentedLibraryQName = QName.create( QNameModule.create( URI.create("http://example.com/ns/augmented-jukebox"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-05-05")), "augmented-library"); - albumQName = QName.create(qNameModule, "album"); - nameQName = QName.create(qNameModule, "name"); + this.albumQName = QName.create(qNameModule, "album"); + this.nameQName = QName.create(qNameModule, "name"); - Mockito.when(identifierContext.getSchemaContext()).thenReturn(schemaContext); - Mockito.when(containerJukebox.getQName()).thenReturn(jukeboxQName); - Mockito.when(identifierContext.getSchemaNode()).thenReturn(containerJukebox); + Mockito.when(this.identifierContext.getSchemaContext()).thenReturn(schemaContext); + Mockito.when(this.containerJukebox.getQName()).thenReturn(this.jukeboxQName); + Mockito.when(this.identifierContext.getSchemaNode()).thenReturn(this.containerJukebox); - Mockito.when(containerLibrary.getQName()).thenReturn(libraryQName); - Mockito.when(containerJukebox.getDataChildByName(libraryQName)).thenReturn(containerLibrary); + Mockito.when(this.containerLibrary.getQName()).thenReturn(this.libraryQName); + Mockito.when(this.containerJukebox.getDataChildByName(this.libraryQName)).thenReturn(this.containerLibrary); - Mockito.when(augmentedContainerLibrary.getQName()).thenReturn(augmentedLibraryQName); - Mockito.when(containerJukebox.getDataChildByName(augmentedLibraryQName)).thenReturn(augmentedContainerLibrary); + Mockito.when(this.augmentedContainerLibrary.getQName()).thenReturn(this.augmentedLibraryQName); + Mockito.when(this.containerJukebox.getDataChildByName(this.augmentedLibraryQName)).thenReturn(this.augmentedContainerLibrary); - Mockito.when(containerPlayer.getQName()).thenReturn(playerQName); - Mockito.when(containerJukebox.getDataChildByName(playerQName)).thenReturn(containerPlayer); + Mockito.when(this.containerPlayer.getQName()).thenReturn(this.playerQName); + Mockito.when(this.containerJukebox.getDataChildByName(this.playerQName)).thenReturn(this.containerPlayer); - Mockito.when(listAlbum.getQName()).thenReturn(albumQName); - Mockito.when(containerLibrary.getDataChildByName(albumQName)).thenReturn(listAlbum); + Mockito.when(this.listAlbum.getQName()).thenReturn(this.albumQName); + Mockito.when(this.containerLibrary.getDataChildByName(this.albumQName)).thenReturn(this.listAlbum); - Mockito.when(leafName.getQName()).thenReturn(nameQName); - Mockito.when(listAlbum.getDataChildByName(nameQName)).thenReturn(leafName); + Mockito.when(this.leafName.getQName()).thenReturn(this.nameQName); + Mockito.when(this.listAlbum.getDataChildByName(this.nameQName)).thenReturn(this.leafName); } /** @@ -117,12 +119,12 @@ public class ParserFieldsParameterTest { @Test public void parseFieldsParameterSimplePathTest() { final String input = "library"; - final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); assertNotNull(parsedFields); assertEquals(1, parsedFields.size()); assertEquals(1, parsedFields.get(0).size()); - assertTrue(parsedFields.get(0).contains(libraryQName)); + assertTrue(parsedFields.get(0).contains(this.libraryQName)); } /** @@ -131,13 +133,13 @@ public class ParserFieldsParameterTest { @Test public void parseFieldsParameterDoublePathTest() { final String input = "library;player"; - final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); assertNotNull(parsedFields); assertEquals(1, parsedFields.size()); assertEquals(2, parsedFields.get(0).size()); - assertTrue(parsedFields.get(0).contains(libraryQName)); - assertTrue(parsedFields.get(0).contains(playerQName)); + assertTrue(parsedFields.get(0).contains(this.libraryQName)); + assertTrue(parsedFields.get(0).contains(this.playerQName)); } /** @@ -146,19 +148,19 @@ public class ParserFieldsParameterTest { @Test public void parseFieldsParameterSubPathTest() { final String input = "library/album/name"; - final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); assertNotNull(parsedFields); assertEquals(3, parsedFields.size()); assertEquals(1, parsedFields.get(0).size()); - assertTrue(parsedFields.get(0).contains(libraryQName)); + assertTrue(parsedFields.get(0).contains(this.libraryQName)); assertEquals(1, parsedFields.get(1).size()); - assertTrue(parsedFields.get(1).contains(albumQName)); + assertTrue(parsedFields.get(1).contains(this.albumQName)); assertEquals(1, parsedFields.get(2).size()); - assertTrue(parsedFields.get(2).contains(nameQName)); + assertTrue(parsedFields.get(2).contains(this.nameQName)); } /** @@ -167,19 +169,19 @@ public class ParserFieldsParameterTest { @Test public void parseFieldsParameterChildrenPathTest() { final String input = "library(album(name))"; - final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); assertNotNull(parsedFields); assertEquals(3, parsedFields.size()); assertEquals(1, parsedFields.get(0).size()); - assertTrue(parsedFields.get(0).contains(libraryQName)); + assertTrue(parsedFields.get(0).contains(this.libraryQName)); assertEquals(1, parsedFields.get(1).size()); - assertTrue(parsedFields.get(1).contains(albumQName)); + assertTrue(parsedFields.get(1).contains(this.albumQName)); assertEquals(1, parsedFields.get(2).size()); - assertTrue(parsedFields.get(2).contains(nameQName)); + assertTrue(parsedFields.get(2).contains(this.nameQName)); } /** @@ -188,13 +190,13 @@ public class ParserFieldsParameterTest { @Test public void parseFieldsParameterNamespaceTest() { final String input = "augmented-jukebox:augmented-library"; - final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + final List> parsedFields = ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); assertNotNull(parsedFields); assertEquals(1, parsedFields.size()); assertEquals(1, parsedFields.get(0).size()); - assertTrue(parsedFields.get(0).contains(augmentedLibraryQName)); + assertTrue(parsedFields.get(0).contains(this.augmentedLibraryQName)); } /** @@ -205,7 +207,7 @@ public class ParserFieldsParameterTest { final String input = "*"; try { - ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); fail("Test should fail due to not expected character used in parameter input value"); } catch (final RestconfDocumentedException e) { // Bad request @@ -223,7 +225,7 @@ public class ParserFieldsParameterTest { final String input = "library("; try { - ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); fail("Test should fail due to missing closing parenthesis"); } catch (final RestconfDocumentedException e) { // Bad request @@ -241,7 +243,7 @@ public class ParserFieldsParameterTest { final String input = "library(not-existing)"; try { - ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); fail("Test should fail due to missing child node in parent node"); } catch (final RestconfDocumentedException e) { // Bad request @@ -259,7 +261,7 @@ public class ParserFieldsParameterTest { final String input = "library(album);"; try { - ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); fail("Test should fail due to unexpected character after parenthesis"); } catch (final RestconfDocumentedException e) { // Bad request @@ -277,7 +279,7 @@ public class ParserFieldsParameterTest { final String input = "library(album)player"; try { - ParserFieldsParameter.parseFieldsParameter(identifierContext, input); + ParserFieldsParameter.parseFieldsParameter(this.identifierContext, input); fail("Test should fail due to missing semicolon after parenthesis"); } catch (final RestconfDocumentedException e) { // Bad request diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserIdentifierTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserIdentifierTest.java index 368456a97c..f87ef35882 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserIdentifierTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/parser/ParserIdentifierTest.java @@ -40,6 +40,7 @@ import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Unit tests for {@link ParserIdentifier} @@ -101,25 +102,26 @@ public class ParserIdentifierTest { @Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); - schemaContext = TestRestconfUtils.loadSchemaContext("/parser-identifier"); - schemaContextOnMountPoint = TestRestconfUtils.loadSchemaContext("/parser-identifier"); + this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier")); + this.schemaContextOnMountPoint = + YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier")); // create and register mount point - mountPoint = SimpleDOMMountPoint.create( + this.mountPoint = SimpleDOMMountPoint.create( YangInstanceIdentifier.builder() .node(QName.create("mount:point", "2016-06-02", "mount-container")) .node(QName.create("mount:point", "2016-06-02", "point-number")) .build(), ImmutableClassToInstanceMap.copyOf(Maps.newHashMap()), - schemaContextOnMountPoint + this.schemaContextOnMountPoint ); - mountPointService = new DOMMountPointServiceImpl(); - ((DOMMountPointServiceImpl) mountPointService).registerMountPoint(mountPoint); + this.mountPointService = new DOMMountPointServiceImpl(); + ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint); // register mount point with null schema context - when(mockMountPoint.getSchemaContext()).thenReturn(null); - when(mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY)).thenReturn(Optional.of(mockMountPoint)); + when(this.mockMountPoint.getSchemaContext()).thenReturn(null); + when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY)).thenReturn(Optional.of(this.mockMountPoint)); } /** @@ -133,7 +135,7 @@ public class ParserIdentifierTest { @Test public void toInstanceIdentifierTest() { final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier( - TEST_IDENT, schemaContext, Optional.absent()); + TEST_IDENT, this.schemaContext, Optional.absent()); assertEquals("Returned not expected identifier", TEST_IDENT_RESULT, context .getInstanceIdentifier().toString()); @@ -146,7 +148,7 @@ public class ParserIdentifierTest { @Test public void toInstanceIdentifierOtherModulesTest() { final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier( - TEST_IDENT_OTHERS, schemaContext, Optional.absent()); + TEST_IDENT_OTHERS, this.schemaContext, Optional.absent()); assertEquals("Returned not expected identifier", TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString()); @@ -159,16 +161,16 @@ public class ParserIdentifierTest { @Test public void toInstanceIdentifierMountPointTest() { final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier( - MOUNT_POINT_IDENT + "/" + TEST_IDENT, schemaContext, Optional.of(mountPointService)); + MOUNT_POINT_IDENT + "/" + TEST_IDENT, this.schemaContext, Optional.of(this.mountPointService)); assertEquals("Returned not expected identifier", TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString()); assertEquals("Mount point not found", - mountPoint, context.getMountPoint()); + this.mountPoint, context.getMountPoint()); assertEquals("Schema context from mount point expected", - schemaContextOnMountPoint, context.getSchemaContext()); + this.schemaContextOnMountPoint, context.getSchemaContext()); } /** @@ -178,7 +180,7 @@ public class ParserIdentifierTest { @Test public void toInstanceIdentifierNullIdentifierTest() { final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier( - null, schemaContext, Optional.absent()); + null, this.schemaContext, Optional.absent()); assertEquals("Returned not expected identifier", YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier()); } @@ -189,7 +191,7 @@ public class ParserIdentifierTest { */ @Test public void toInstanceIdentifierNullSchemaContextNegativeTest() { - thrown.expect(NullPointerException.class); + this.thrown.expect(NullPointerException.class); ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.absent()); } @@ -199,7 +201,7 @@ public class ParserIdentifierTest { @Test public void toInstanceIdentifierEmptyIdentifierTest() { final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier( - "", schemaContext, Optional.absent()); + "", this.schemaContext, Optional.absent()); assertEquals("Returned not expected identifier", YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier()); } @@ -209,8 +211,8 @@ public class ParserIdentifierTest { */ @Test public void toInstanceIdentifierInvalidIdentifierNegativeTest() { - thrown.expect(IllegalArgumentException.class); - ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, schemaContext, Optional.absent()); + this.thrown.expect(IllegalArgumentException.class); + ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.absent()); } /** @@ -219,8 +221,8 @@ public class ParserIdentifierTest { */ @Test public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() { - thrown.expect(IllegalArgumentException.class); - ParserIdentifier.toInstanceIdentifier(INVALID_MOUNT_POINT_IDENT, schemaContext, Optional.of(mountPointService)); + this.thrown.expect(IllegalArgumentException.class); + ParserIdentifier.toInstanceIdentifier(INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService)); } /** @@ -232,7 +234,7 @@ public class ParserIdentifierTest { public void toInstanceIdentifierMissingMountPointNegativeTest() { try { ParserIdentifier.toInstanceIdentifier( - "" + "/" + RestconfConstants.MOUNT, schemaContext, Optional.of(mountPointService)); + "" + "/" + RestconfConstants.MOUNT, this.schemaContext, Optional.of(this.mountPointService)); fail("Test should fail due to missing mount point"); } catch (final RestconfDocumentedException e) { assertEquals("Not expected error type", @@ -252,7 +254,7 @@ public class ParserIdentifierTest { @Test public void toInstanceIdentifierMissingMountPointServiceNegativeTest() { try { - ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, schemaContext, Optional.absent()); + ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.absent()); fail("Test should fail due to absent mount point service"); } catch (final RestconfDocumentedException e) { assertEquals("Not expected error type", @@ -399,7 +401,7 @@ public class ParserIdentifierTest { */ @Test public void makeQNameFromIdentifierNullIdentifierNegativeTest() { - thrown.expect(NullPointerException.class); + this.thrown.expect(NullPointerException.class); ParserIdentifier.makeQNameFromIdentifier(null); } @@ -455,7 +457,7 @@ public class ParserIdentifierTest { @Test public void toSchemaExportContextFromIdentifierTest() { final SchemaExportContext exportContext = ParserIdentifier. - toSchemaExportContextFromIdentifier(schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null); + toSchemaExportContextFromIdentifier(this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null); assertNotNull("Export context should be parsed", exportContext); @@ -477,7 +479,7 @@ public class ParserIdentifierTest { @Test public void toSchemaExportContextFromIdentifierNotFoundTest() { final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier( - schemaContext, + this.schemaContext, "not-existing-module" + "/" + "2016-01-01", null); @@ -494,7 +496,7 @@ public class ParserIdentifierTest { public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() { try { ParserIdentifier.toSchemaExportContextFromIdentifier( - schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null); + this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null); fail("Test should fail due to invalid identifier supplied"); } catch (final RestconfDocumentedException e) { assertEquals("Not expected error type", @@ -513,9 +515,9 @@ public class ParserIdentifierTest { @Test public void toSchemaExportContextFromIdentifierMountPointTest() { final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier( - schemaContext, + this.schemaContext, MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, - mountPointService); + this.mountPointService); final Module module = exportContext.getModule(); assertNotNull("Export context should contains test module", module); @@ -535,9 +537,9 @@ public class ParserIdentifierTest { @Test public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() { final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier( - schemaContext, + this.schemaContext, MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01", - mountPointService); + this.mountPointService); assertNotNull("Export context should be parsed", exportContext); assertNull("Not-existing module should be null", exportContext.getModule()); @@ -552,9 +554,9 @@ public class ParserIdentifierTest { public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() { try { ParserIdentifier.toSchemaExportContextFromIdentifier( - schemaContext, + this.schemaContext, MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, - mountPointService); + this.mountPointService); fail("Test should fail due to invalid identifier supplied"); } catch (final RestconfDocumentedException e) { @@ -573,8 +575,8 @@ public class ParserIdentifierTest { */ @Test public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() { - thrown.expect(NullPointerException.class); - ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContext, null, null); + this.thrown.expect(NullPointerException.class); + ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null); } /** @@ -583,7 +585,7 @@ public class ParserIdentifierTest { */ @Test public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() { - thrown.expect(NullPointerException.class); + this.thrown.expect(NullPointerException.class); ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null); } @@ -594,7 +596,7 @@ public class ParserIdentifierTest { */ @Test public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() { - thrown.expect(NullPointerException.class); + this.thrown.expect(NullPointerException.class); ParserIdentifier.toSchemaExportContextFromIdentifier( null, MOUNT_POINT_IDENT @@ -602,7 +604,7 @@ public class ParserIdentifierTest { + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, - mountPointService); + this.mountPointService); } /** @@ -612,9 +614,9 @@ public class ParserIdentifierTest { */ @Test public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() { - thrown.expect(NullPointerException.class); + this.thrown.expect(NullPointerException.class); ParserIdentifier.toSchemaExportContextFromIdentifier( - schemaContext, + this.schemaContext, MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME @@ -629,15 +631,15 @@ public class ParserIdentifierTest { */ @Test public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() { - thrown.expect(NullPointerException.class); + this.thrown.expect(NullPointerException.class); ParserIdentifier.toSchemaExportContextFromIdentifier( - schemaContext, + this.schemaContext, "/" + RestconfConstants.MOUNT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, - mockMountPointService); + this.mockMountPointService); } } diff --git a/restconf/sal-rest-docgen/pom.xml b/restconf/sal-rest-docgen/pom.xml index 838b84a9c7..d36a7d6ab9 100644 --- a/restconf/sal-rest-docgen/pom.xml +++ b/restconf/sal-rest-docgen/pom.xml @@ -88,11 +88,14 @@ org.opendaylight.yangtools yang-parser-api - org.opendaylight.yangtools yang-parser-impl + + org.opendaylight.yangtools + yang-test-util + org.osgi diff --git a/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/DocGenTestHelper.java b/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/DocGenTestHelper.java index 9295afb106..3adc856983 100644 --- a/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/DocGenTestHelper.java +++ b/restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/DocGenTestHelper.java @@ -17,9 +17,11 @@ import java.io.File; import java.io.FileNotFoundException; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.List; import java.util.Set; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; @@ -30,10 +32,7 @@ import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class DocGenTestHelper { @@ -42,8 +41,7 @@ public class DocGenTestHelper { private SchemaContext schemaContext; public Set loadModules(final String resourceDirectory) - throws FileNotFoundException, - URISyntaxException, ReactorException { + throws URISyntaxException, FileNotFoundException, ReactorException { final URI resourceDirUri = getClass().getResource(resourceDirectory).toURI(); final File testDir = new File(resourceDirUri); @@ -51,13 +49,12 @@ public class DocGenTestHelper { if (fileList == null) { throw new FileNotFoundException(resourceDirectory.toString()); } - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + final List files = new ArrayList<>(); for (final String fileName : fileList) { - final File file = new File(testDir, fileName); - reactor.addSource(new YangStatementSourceImpl(new NamedFileInputStream(file, file.getPath()))); + files.add(new File(testDir, fileName)); } - this.schemaContext = reactor.buildEffective(); + this.schemaContext = YangParserTestUtils.parseYangSources(files); return this.schemaContext.getModules(); }