From 2645b72cbef49a22f7520cb19b49c2d4b337ce7d Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 23 Feb 2018 13:27:02 +0100 Subject: [PATCH] Cleanup resources allocated in @BeforeClass This cleans up static fields after tests have been run. Change-Id: Idf48234157b2196fadfdabcffd5628ad397639d5 Signed-off-by: Robert Varga --- .../odlext/parser/Bug3874ExtensionTest.java | 6 + .../yangtools/rfc6536/parser/NACMTest.java | 6 + .../rfc7952/parser/AnnotationTest.java | 6 + .../rfc8040/parser/YangDataExtensionTest.java | 6 + .../data/codec/gson/AnyXmlSupportTest.java | 6 + .../yang/data/codec/gson/Bug4501Test.java | 6 + .../yang/data/codec/gson/Bug5446Test.java | 21 +-- .../yang/data/codec/gson/Bug6112Test.java | 6 + .../yang/data/codec/gson/Bug8083Test.java | 6 + .../gson/JsonStreamToNormalizedNodeTest.java | 6 + .../gson/NormalizedNodeToJsonStreamTest.java | 6 + .../gson/StreamToNormalizedNodeTest.java | 7 + .../gson/YangModeledAnyXmlSupportTest.java | 7 + .../yang/data/codec/xml/Bug5446Test.java | 30 ++-- .../yang/data/codec/xml/Bug8675Test.java | 9 +- .../data/codec/xml/XmlStreamUtilsTest.java | 7 + .../codec/xml/XmlToNormalizedNodesTest.java | 148 ++++++++---------- .../DataTreeCandidateValidatorTest.java | 28 ++-- .../DataTreeCandidateValidatorTest2.java | 122 +++++++-------- .../DataTreeCandidateValidatorTest3.java | 134 ++++++++-------- .../leafref/context/LeafRefContextTest.java | 10 +- .../LeafRefContextTreeBuilderTest.java | 15 +- .../impl/schema/InstanceIdToNodesTest.java | 12 +- .../yang/stmt/EffectiveStatementTypeTest.java | 7 + .../yang/stmt/IncludedStmtsTest.java | 6 + 25 files changed, 344 insertions(+), 279 deletions(-) diff --git a/yang/odlext-parser-support/src/test/java/org/opendaylight/yangtools/odlext/parser/Bug3874ExtensionTest.java b/yang/odlext-parser-support/src/test/java/org/opendaylight/yangtools/odlext/parser/Bug3874ExtensionTest.java index cf83d6068e..fb5e14f662 100644 --- a/yang/odlext-parser-support/src/test/java/org/opendaylight/yangtools/odlext/parser/Bug3874ExtensionTest.java +++ b/yang/odlext-parser-support/src/test/java/org/opendaylight/yangtools/odlext/parser/Bug3874ExtensionTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertTrue; import java.net.URI; import java.util.List; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.odlext.model.api.OpenDaylightExtensionsStatements; @@ -45,6 +46,11 @@ public class Bug3874ExtensionTest { .build(); } + @AfterClass + public static void freeReactor() { + reactor = null; + } + @Test public void test() throws Exception { SchemaContext context = reactor.newBuild() diff --git a/yang/rfc6536-parser-support/src/test/java/org/opendaylight/yangtools/rfc6536/parser/NACMTest.java b/yang/rfc6536-parser-support/src/test/java/org/opendaylight/yangtools/rfc6536/parser/NACMTest.java index cab1230f2f..b5dd4a6576 100644 --- a/yang/rfc6536-parser-support/src/test/java/org/opendaylight/yangtools/rfc6536/parser/NACMTest.java +++ b/yang/rfc6536-parser-support/src/test/java/org/opendaylight/yangtools/rfc6536/parser/NACMTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.IOException; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.rfc6536.model.api.DefaultDenyAllSchemaNode; @@ -42,6 +43,11 @@ public class NACMTest { .build(); } + @AfterClass + public static void freeReactor() { + reactor = null; + } + @Test public void testResolution() throws ReactorException, IOException, YangSyntaxErrorException { final BuildAction build = reactor.newBuild(); diff --git a/yang/rfc7952-parser-support/src/test/java/org/opendaylight/yangtools/rfc7952/parser/AnnotationTest.java b/yang/rfc7952-parser-support/src/test/java/org/opendaylight/yangtools/rfc7952/parser/AnnotationTest.java index 9d3f9a5f3f..e03b04f83f 100644 --- a/yang/rfc7952-parser-support/src/test/java/org/opendaylight/yangtools/rfc7952/parser/AnnotationTest.java +++ b/yang/rfc7952-parser-support/src/test/java/org/opendaylight/yangtools/rfc7952/parser/AnnotationTest.java @@ -15,6 +15,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Map; import java.util.Optional; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode; @@ -42,6 +43,11 @@ public class AnnotationTest { .build(); } + @AfterClass + public static void freeReactor() { + reactor = null; + } + @Test public void testAnnotationResolution() throws ReactorException, IOException, YangSyntaxErrorException { final BuildAction build = reactor.newBuild(); diff --git a/yang/rfc8040-parser-support/src/test/java/org/opendaylight/yangtools/rfc8040/parser/YangDataExtensionTest.java b/yang/rfc8040-parser-support/src/test/java/org/opendaylight/yangtools/rfc8040/parser/YangDataExtensionTest.java index 69c58ff5cb..396de474c8 100644 --- a/yang/rfc8040-parser-support/src/test/java/org/opendaylight/yangtools/rfc8040/parser/YangDataExtensionTest.java +++ b/yang/rfc8040-parser-support/src/test/java/org/opendaylight/yangtools/rfc8040/parser/YangDataExtensionTest.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.net.URI; import java.util.List; import java.util.Set; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.rfc8040.model.api.YangDataSchemaNode; @@ -73,6 +74,11 @@ public class YangDataExtensionTest { .build(); } + @AfterClass + public static void freeReactor() { + reactor = null; + } + @Test public void testYangData() throws Exception { final SchemaContext schemaContext = reactor.newBuild().addSources(FOO_MODULE, IETF_RESTCONF_MODULE) diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java index 19a47fe794..75f5622346 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java @@ -26,6 +26,7 @@ import java.io.StringReader; import java.net.URISyntaxException; import java.util.Optional; import javax.xml.transform.dom.DOMSource; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.util.xml.UntrustedXML; @@ -60,6 +61,11 @@ public class AnyXmlSupportTest { schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang"); } + @AfterClass + public static void cleanup() { + schemaContext = null; + } + @Test public void anyXmlNodeWithSimpleValueInContainer() throws IOException, URISyntaxException { final String inputJson = loadTextFile("/complexjson/anyxml-node-with-simple-value-in-container.json"); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java index eee52da712..9cde9b39bd 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.StringReader; import java.net.URISyntaxException; import java.util.Optional; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -41,6 +42,11 @@ public class Bug4501Test { schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug-4501/yang"); } + @AfterClass + public static void cleanup() { + schemaContext = null; + } + @Test public void testCorrectInput() throws IOException, URISyntaxException { final String inputJson = loadTextFile("/bug-4501/json/foo-correct.json"); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java index 4d0600a258..c18324d018 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java @@ -21,6 +21,7 @@ import java.io.StringWriter; import java.io.Writer; import java.net.URI; import java.net.URISyntaxException; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -42,20 +43,21 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class Bug5446Test { - private static QNameModule fooModuleQName; - private static QName rootQName; - private static QName ipAddressQName; + private static final QNameModule FOO_MODULE = QNameModule.create(URI.create("foo"), Revision.of("2015-11-05")); + private static final QName ROOT_QNAME = QName.create(FOO_MODULE, "root"); + private static final QName IP_ADDRESS_QNAME = QName.create(FOO_MODULE, "ip-address"); private static SchemaContext schemaContext; @BeforeClass public static void init() { - fooModuleQName = QNameModule.create(URI.create("foo"), Revision.of("2015-11-05")); - rootQName = QName.create(fooModuleQName, "root"); - ipAddressQName = QName.create(fooModuleQName, "ip-address"); - schemaContext = YangParserTestUtils.parseYangResources(Bug5446Test.class, "/bug5446/yang/foo.yang"); } + @AfterClass + public static void cleanup() { + schemaContext = null; + } + @Test public void test() throws IOException, JsonIOException, JsonSyntaxException, URISyntaxException { final DataContainerChild rootNode = createRootNode(); @@ -85,8 +87,9 @@ public class Bug5446Test { } private static ContainerNode createRootNode() { - LeafNode ipAddress = ImmutableNodes.leafNode(ipAddressQName, BaseEncoding.base64().decode("fwAAAQ==")); - return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(rootQName)) + LeafNode ipAddress = ImmutableNodes.leafNode(IP_ADDRESS_QNAME, + BaseEncoding.base64().decode("fwAAAQ==")); + return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ROOT_QNAME)) .withChild(ipAddress).build(); } } diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java index eaffe4c15a..8c2b96d013 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.StringReader; import java.net.URISyntaxException; import java.util.Optional; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -38,6 +39,11 @@ public class Bug6112Test { schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug-6112/yang"); } + @AfterClass + public static void cleanup() { + schemaContext = null; + } + private static NormalizedNode readJson(final String jsonPath) throws IOException, URISyntaxException { final String inputJson = loadTextFile(jsonPath); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java index 5409e73fec..b5db7b97ad 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.StringReader; import java.net.URI; import java.net.URISyntaxException; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -74,6 +75,11 @@ public class Bug8083Test { FULL_SCHEMA_CONTEXT = YangParserTestUtils.parseYangResourceDirectory("/bug8083/yang/"); } + @AfterClass + public static void cleanup() { + FULL_SCHEMA_CONTEXT = null; + } + @Test public void testInstanceIdentifierSerializeNew() throws IOException { assertEquals("/example-foomod:top/foo-list[name='key-value']/example-barmod:bar-container/bar-leaf", diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java index 822bda7f6f..50c8bd0bed 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.StringReader; import java.net.URISyntaxException; import java.util.Collections; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.Empty; @@ -51,6 +52,11 @@ public class JsonStreamToNormalizedNodeTest { schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang"); } + @AfterClass + public static void cleanup() { + schemaContext = null; + } + @Test public void leafNodeInContainer() throws IOException, URISyntaxException { final String inputJson = loadTextFile("/complexjson/leaf-node-in-container.json"); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java index bf30b77bc3..a5e0781b65 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java @@ -27,6 +27,7 @@ import java.io.Writer; import java.net.URISyntaxException; import java.util.HashSet; import java.util.Iterator; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.Empty; @@ -58,6 +59,11 @@ public class NormalizedNodeToJsonStreamTest { schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang"); } + @AfterClass + public static void cleanup() { + schemaContext = null; + } + @Test public void leafNodeInContainer() throws IOException, URISyntaxException { final Writer writer = new StringWriter(); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java index 9a968cb43d..73f11dc477 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.net.URISyntaxException; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; @@ -43,6 +44,12 @@ public class StreamToNormalizedNodeTest { "/complexjson/complex-json.json").toURI())); } + @AfterClass + public static void cleanup() { + schemaContext = null; + streamAsString = null; + } + /** * Demonstrates how to log events produced by a {@link JsonReader}. */ diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java index 4da8a82bac..23fae93299 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java @@ -27,6 +27,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -78,6 +79,12 @@ public class YangModeledAnyXmlSupportTest { data = (ContainerNode) result.getResult(); } + @AfterClass + public static void cleanup() { + schemaContext = null; + data = null; + } + @Test public void jsonToNormalizedNodesTest() throws IOException, URISyntaxException, SAXException { final String inputJson = loadTextFile("/yang-modeled-anyxml/json/baz.json"); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5446Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5446Test.java index 5d0237020e..d297f8e84b 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5446Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5446Test.java @@ -5,7 +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.yangtools.yang.data.codec.xml; import static java.util.Objects.requireNonNull; @@ -58,30 +57,22 @@ public class Bug5446Test extends XMLTestCase { XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE); } - private final QNameModule fooModuleQName; - private final QName rootQName; - private final QName ipAddressQName; - private final SchemaContext schemaContext; - - public Bug5446Test() throws Exception { - fooModuleQName = QNameModule.create(URI.create("foo"), Revision.of("2015-11-05")); - rootQName = QName.create(fooModuleQName, "root"); - ipAddressQName = QName.create(fooModuleQName, "ip-address"); - - schemaContext = YangParserTestUtils.parseYangResource("/bug5446/yang/foo.yang"); - } + private static final QNameModule FOO_MODULE = QNameModule.create(URI.create("foo"), Revision.of("2015-11-05")); + private static final QName ROOT_QNAME = QName.create(FOO_MODULE, "root"); + private static final QName IP_ADDRESS_QNAME = QName.create(FOO_MODULE, "ip-address"); @Test public void test() throws Exception { + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug5446/yang/foo.yang"); final Document doc = loadDocument("/bug5446/xml/foo.xml"); final ContainerNode docNode = createDocNode(); - Optional> root = docNode.getChild(new NodeIdentifier(rootQName)); + Optional> root = docNode.getChild(new NodeIdentifier(ROOT_QNAME)); assertTrue(root.orElse(null) instanceof ContainerNode); Optional> child = ((ContainerNode) root.orElse(null)) - .getChild(new NodeIdentifier(ipAddressQName)); + .getChild(new NodeIdentifier(IP_ADDRESS_QNAME)); assertTrue(child.orElse(null) instanceof LeafNode); LeafNode ipAdress = (LeafNode) child.get(); @@ -103,11 +94,12 @@ public class Bug5446Test extends XMLTestCase { assertXMLEqual(expectedXMLString, serializationResultXMLString); } - private ContainerNode createDocNode() { - LeafNode ipAddress = ImmutableNodes.leafNode(ipAddressQName, BaseEncoding.base64().decode("fwAAAQ==")); - ContainerNode root = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(rootQName)) + private static ContainerNode createDocNode() { + LeafNode ipAddress = ImmutableNodes.leafNode(IP_ADDRESS_QNAME, BaseEncoding.base64() + .decode("fwAAAQ==")); + ContainerNode root = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ROOT_QNAME)) .withChild(ipAddress).build(); - return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(rootQName)).withChild(root) + return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ROOT_QNAME)).withChild(root) .build(); } diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java index 55e2c06cdd..9eac513f17 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull; import java.io.InputStream; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -35,11 +36,17 @@ public class Bug8675Test { private static Module fooModule; @BeforeClass - public static void setup() throws Exception { + public static void setup() { schemaContext = YangParserTestUtils.parseYangResource("/bug8675/foo.yang"); fooModule = schemaContext.getModules().iterator().next(); } + @AfterClass + public static void cleanup() { + fooModule = null; + schemaContext = null; + } + @Test public void testParsingEmptyElements() throws Exception { final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName( diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java index 1d7e209ed0..5447f05eac 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java @@ -26,6 +26,7 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamWriter; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -61,6 +62,12 @@ public class XmlStreamUtilsTest { assertNotNull(leafRefModule); } + @AfterClass + public static void cleanup() { + leafRefModule = null; + schemaContext = null; + } + @Test public void testWriteAttribute() throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlToNormalizedNodesTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlToNormalizedNodesTest.java index 1f6d21fd17..a483ce7670 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlToNormalizedNodesTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlToNormalizedNodesTest.java @@ -25,6 +25,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -52,71 +53,51 @@ import org.xml.sax.SAXException; public class XmlToNormalizedNodesTest { + private static final QNameModule FOO_MODULE = QNameModule.create(URI.create("foo-namespace")); + private static final QName PARENT_CONTAINER = QName.create(FOO_MODULE, "parent-container"); + + private static final QNameModule BAZ_MODULE = QNameModule.create(URI.create("baz-namespace")); + private static final QName OUTER_CONTAINER = QName.create(BAZ_MODULE, "outer-container"); + + private static final QName MY_CONTAINER_1 = QName.create(BAZ_MODULE, "my-container-1"); + private static final QName MY_KEYED_LIST = QName.create(BAZ_MODULE, "my-keyed-list"); + private static final QName MY_KEY_LEAF = QName.create(BAZ_MODULE, "my-key-leaf"); + private static final QName MY_LEAF_IN_LIST_1 = QName.create(BAZ_MODULE, "my-leaf-in-list-1"); + private static final QName MY_LEAF_IN_LIST_2 = QName.create(BAZ_MODULE, "my-leaf-in-list-2"); + private static final QName MY_LEAF_1 = QName.create(BAZ_MODULE, "my-leaf-1"); + private static final QName MY_LEAFLIST = QName.create(BAZ_MODULE, "my-leaf-list"); + + private static final QName MY_CONTAINER_2 = QName.create(BAZ_MODULE, "my-container-2"); + private static final QName INNER_CONTAINER = QName.create(BAZ_MODULE, "inner-container"); + private static final QName MY_LEAF_2 = QName.create(BAZ_MODULE, "my-leaf-2"); + private static final QName MY_LEAF_3 = QName.create(BAZ_MODULE, "my-leaf-3"); + private static final QName MY_CHOICE = QName.create(BAZ_MODULE, "my-choice"); + private static final QName MY_LEAF_IN_CASE_2 = QName.create(BAZ_MODULE, "my-leaf-in-case-2"); + + private static final QName MY_CONTAINER_3 = QName.create(BAZ_MODULE, "my-container-3"); + private static final QName MY_DOUBLY_KEYED_LIST = QName.create(BAZ_MODULE, "my-doubly-keyed-list"); + private static final QName MY_FIRST_KEY_LEAF = QName.create(BAZ_MODULE, "my-first-key-leaf"); + private static final QName MY_SECOND_KEY_LEAF = QName.create(BAZ_MODULE, "my-second-key-leaf"); + private static final QName MY_LEAF_IN_LIST_3 = QName.create(BAZ_MODULE, "my-leaf-in-list-3"); + private static SchemaContext schemaContext; private static ContainerSchemaNode outerContainerSchema; private static ContainerSchemaNode parentContainerSchema; - private static QNameModule fooModule; - private static QName parentContainer; - - private static QNameModule bazModule; - private static QName outerContainer; - - private static QName myContainer1; - private static QName myKeyedList; - private static QName myKeyLeaf; - private static QName myLeafInList1; - private static QName myLeafInList2; - private static QName myLeaf1; - private static QName myLeafList; - - private static QName myContainer2; - private static QName innerContainer; - private static QName myLeaf2; - private static QName myLeaf3; - private static QName myChoice; - private static QName myLeafInCase2; - - private static QName myContainer3; - private static QName myDoublyKeyedList; - private static QName myFirstKeyLeaf; - private static QName mySecondKeyLeaf; - private static QName myLeafInList3; - @BeforeClass public static void setup() { - fooModule = QNameModule.create(URI.create("foo-namespace")); - parentContainer = QName.create(fooModule, "parent-container"); - - bazModule = QNameModule.create(URI.create("baz-namespace")); - outerContainer = QName.create(bazModule, "outer-container"); - - myContainer1 = QName.create(bazModule, "my-container-1"); - myKeyedList = QName.create(bazModule, "my-keyed-list"); - myKeyLeaf = QName.create(bazModule, "my-key-leaf"); - myLeafInList1 = QName.create(bazModule, "my-leaf-in-list-1"); - myLeafInList2 = QName.create(bazModule, "my-leaf-in-list-2"); - myLeaf1 = QName.create(bazModule, "my-leaf-1"); - myLeafList = QName.create(bazModule, "my-leaf-list"); - - myContainer2 = QName.create(bazModule, "my-container-2"); - innerContainer = QName.create(bazModule, "inner-container"); - myLeaf2 = QName.create(bazModule, "my-leaf-2"); - myLeaf3 = QName.create(bazModule, "my-leaf-3"); - myChoice = QName.create(bazModule, "my-choice"); - myLeafInCase2 = QName.create(bazModule, "my-leaf-in-case-2"); - - myContainer3 = QName.create(bazModule, "my-container-3"); - myDoublyKeyedList = QName.create(bazModule, "my-doubly-keyed-list"); - myFirstKeyLeaf = QName.create(bazModule, "my-first-key-leaf"); - mySecondKeyLeaf = QName.create(bazModule, "my-second-key-leaf"); - myLeafInList3 = QName.create(bazModule, "my-leaf-in-list-3"); - schemaContext = YangParserTestUtils.parseYangResourceDirectory("/"); parentContainerSchema = (ContainerSchemaNode) SchemaContextUtil.findNodeInSchemaContext(schemaContext, - ImmutableList.of(parentContainer)); + ImmutableList.of(PARENT_CONTAINER)); outerContainerSchema = (ContainerSchemaNode) SchemaContextUtil.findNodeInSchemaContext(schemaContext, - ImmutableList.of(outerContainer)); + ImmutableList.of(OUTER_CONTAINER)); + } + + @AfterClass + public static void cleanup() { + schemaContext = null; + parentContainerSchema = null; + outerContainerSchema = null; } @Test @@ -311,80 +292,81 @@ public class XmlToNormalizedNodesTest { private static NormalizedNode buildOuterContainerNode() { // my-container-1 - MapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myKeyedList)) + MapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_KEYED_LIST)) .withChild(Builders.mapEntryBuilder().withNodeIdentifier( - new NodeIdentifierWithPredicates(myKeyedList, myKeyLeaf, "listkeyvalue1")) - .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1)) + new NodeIdentifierWithPredicates(MY_KEYED_LIST, MY_KEY_LEAF, "listkeyvalue1")) + .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_IN_LIST_1)) .withValue("listleafvalue1").build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2)) + .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_IN_LIST_2)) .withValue("listleafvalue2").build()).build()) .withChild(Builders.mapEntryBuilder().withNodeIdentifier( - new NodeIdentifierWithPredicates(myKeyedList, myKeyLeaf, "listkeyvalue2")) - .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1)) + new NodeIdentifierWithPredicates(MY_KEYED_LIST, MY_KEY_LEAF, "listkeyvalue2")) + .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_IN_LIST_1)) .withValue("listleafvalue12").build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2)) + .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_IN_LIST_2)) .withValue("listleafvalue22").build()).build()).build(); - LeafNode myLeaf1Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf1)) + LeafNode myLeaf1Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_1)) .withValue("value1").build(); - LeafSetNode myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(myLeafList)) + LeafSetNode myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAFLIST)) .withChild(Builders.leafSetEntryBuilder().withNodeIdentifier( - new NodeWithValue<>(myLeafList, "lflvalue1")).withValue("lflvalue1").build()) + new NodeWithValue<>(MY_LEAFLIST, "lflvalue1")).withValue("lflvalue1").build()) .withChild(Builders.leafSetEntryBuilder().withNodeIdentifier( - new NodeWithValue<>(myLeafList, "lflvalue2")).withValue("lflvalue2").build()).build(); + new NodeWithValue<>(MY_LEAFLIST, "lflvalue2")).withValue("lflvalue2").build()).build(); ContainerNode myContainer1Node = Builders.containerBuilder().withNodeIdentifier( - new NodeIdentifier(myContainer1)) + new NodeIdentifier(MY_CONTAINER_1)) .withChild(myKeyedListNode) .withChild(myLeaf1Node) .withChild(myLeafListNode).build(); // my-container-2 ContainerNode innerContainerNode = Builders.containerBuilder().withNodeIdentifier( - new NodeIdentifier(innerContainer)) - .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf2)) + new NodeIdentifier(INNER_CONTAINER)) + .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_2)) .withValue("value2").build()).build(); - LeafNode myLeaf3Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf3)) + LeafNode myLeaf3Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_3)) .withValue("value3").build(); - ChoiceNode myChoiceNode = Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(myChoice)) - .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInCase2)) + ChoiceNode myChoiceNode = Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(MY_CHOICE)) + .withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_IN_CASE_2)) .withValue("case2value").build()).build(); ContainerNode myContainer2Node = Builders.containerBuilder().withNodeIdentifier( - new NodeIdentifier(myContainer2)) + new NodeIdentifier(MY_CONTAINER_2)) .withChild(innerContainerNode) .withChild(myLeaf3Node) .withChild(myChoiceNode).build(); // my-container-3 Map keys = new HashMap<>(); - keys.put(myFirstKeyLeaf, "listkeyvalue1"); - keys.put(mySecondKeyLeaf, "listkeyvalue2"); + keys.put(MY_FIRST_KEY_LEAF, "listkeyvalue1"); + keys.put(MY_SECOND_KEY_LEAF, "listkeyvalue2"); - MapNode myDoublyKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myDoublyKeyedList)) + MapNode myDoublyKeyedListNode = Builders.mapBuilder() + .withNodeIdentifier(new NodeIdentifier(MY_DOUBLY_KEYED_LIST)) .withChild(Builders.mapEntryBuilder().withNodeIdentifier( - new NodeIdentifierWithPredicates(myDoublyKeyedList, keys)) + new NodeIdentifierWithPredicates(MY_DOUBLY_KEYED_LIST, keys)) .withChild(Builders.leafBuilder().withNodeIdentifier( - new NodeIdentifier(myLeafInList3)).withValue("listleafvalue1").build()).build()) + new NodeIdentifier(MY_LEAF_IN_LIST_3)).withValue("listleafvalue1").build()).build()) .build(); AugmentationNode myDoublyKeyedListAugNode = Builders.augmentationBuilder().withNodeIdentifier( - new AugmentationIdentifier(Collections.singleton(myDoublyKeyedList))) + new AugmentationIdentifier(Collections.singleton(MY_DOUBLY_KEYED_LIST))) .withChild(myDoublyKeyedListNode).build(); ContainerNode myContainer3Node = Builders.containerBuilder().withNodeIdentifier( - new NodeIdentifier(myContainer3)) + new NodeIdentifier(MY_CONTAINER_3)) .withChild(myDoublyKeyedListAugNode).build(); AugmentationNode myContainer3AugNode = Builders.augmentationBuilder().withNodeIdentifier( - new AugmentationIdentifier(Collections.singleton(myContainer3))) + new AugmentationIdentifier(Collections.singleton(MY_CONTAINER_3))) .withChild(myContainer3Node).build(); ContainerNode outerContainerNode = Builders.containerBuilder().withNodeIdentifier( - new NodeIdentifier(outerContainer)) + new NodeIdentifier(OUTER_CONTAINER)) .withChild(myContainer1Node) .withChild(myContainer2Node) .withChild(myContainer3AugNode).build(); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java index c700a40a51..f75ae2fc9f 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import org.apache.log4j.BasicConfigurator; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -100,17 +101,6 @@ public class DataTreeCandidateValidatorTest { @BeforeClass public static void init() { - initSchemaContext(); - - initLeafRefContext(); - - initQnames(); - - initDataTree(); - - } - - private static void initSchemaContext() { context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); final Set modules = context.getModules(); @@ -121,13 +111,8 @@ public class DataTreeCandidateValidatorTest { } valModuleQname = valModule.getQNameModule(); - } - - private static void initLeafRefContext() { rootLeafRefContext = LeafRefContext.create(context); - } - private static void initQnames() { odl = QName.create(valModuleQname, "odl-project"); project = QName.create(valModuleQname, "project"); name = QName.create(valModuleQname, "name"); @@ -163,9 +148,6 @@ public class DataTreeCandidateValidatorTest { leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list"); - } - - private static void initDataTree() { inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context); final DataTreeModification initialDataTreeModification = inMemoryDataTree @@ -185,6 +167,14 @@ public class DataTreeCandidateValidatorTest { inMemoryDataTree.commit(writeContributorsCandidate); } + @AfterClass + public static void cleanup() { + inMemoryDataTree = null; + rootLeafRefContext = null; + valModule = null; + context = null; + } + @Test public void dataTreeCanditateValidationTest() { write(); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java index 134870db5b..477d2db5d2 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertTrue; import java.util.Set; import org.apache.log4j.BasicConfigurator; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -78,10 +79,61 @@ public class DataTreeCandidateValidatorTest2 { @BeforeClass public static void init() { - initSchemaContext(); - initLeafRefContext(); - initQnames(); - initDataTree(); + context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); + + final Set modules = context.getModules(); + for (final Module module : modules) { + if (module.getName().equals("leafref-validation2")) { + mainModule = module; + } + } + + rootModuleQname = mainModule.getQNameModule(); + rootLeafRefContext = LeafRefContext.create(context); + + chips = QName.create(rootModuleQname, "chips"); + chip = QName.create(rootModuleQname, "chip"); + devType = QName.create(rootModuleQname, "dev_type"); + chipDesc = QName.create(rootModuleQname, "chip_desc"); + + devices = QName.create(rootModuleQname, "devices"); + device = QName.create(rootModuleQname, "device"); + typeText = QName.create(rootModuleQname, "type_text"); + devDesc = QName.create(rootModuleQname, "dev_desc"); + sn = QName.create(rootModuleQname, "sn"); + defaultIp = QName.create(rootModuleQname, "default_ip"); + + deviceTypeStr = QName.create(rootModuleQname, "device_types"); + deviceType = QName.create(rootModuleQname, "device_type"); + type = QName.create(rootModuleQname, "type"); + desc = QName.create(rootModuleQname, "desc"); + + inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context); + final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); + final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(chips); + final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode); + final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips); + initialDataTreeModification.write(path1, chipsContainer); + + final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule + .getDataChildByName(deviceTypeStr); + final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode); + final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr); + initialDataTreeModification.write(path2, deviceTypesContainer); + + initialDataTreeModification.ready(); + final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification); + + inMemoryDataTree.commit(writeChipsCandidate); + LOG.debug("{}", inMemoryDataTree); + } + + @AfterClass + public static void cleanup() { + inMemoryDataTree = null; + rootLeafRefContext = null; + mainModule = null; + context = null; } @Test @@ -128,68 +180,6 @@ public class DataTreeCandidateValidatorTest2 { LOG.debug("{}", inMemoryDataTree); } - private static void initQnames() { - - chips = QName.create(rootModuleQname, "chips"); - chip = QName.create(rootModuleQname, "chip"); - devType = QName.create(rootModuleQname, "dev_type"); - chipDesc = QName.create(rootModuleQname, "chip_desc"); - - devices = QName.create(rootModuleQname, "devices"); - device = QName.create(rootModuleQname, "device"); - typeText = QName.create(rootModuleQname, "type_text"); - devDesc = QName.create(rootModuleQname, "dev_desc"); - sn = QName.create(rootModuleQname, "sn"); - defaultIp = QName.create(rootModuleQname, "default_ip"); - - deviceTypeStr = QName.create(rootModuleQname, "device_types"); - deviceType = QName.create(rootModuleQname, "device_type"); - type = QName.create(rootModuleQname, "type"); - desc = QName.create(rootModuleQname, "desc"); - } - - private static void initSchemaContext() { - context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); - - final Set modules = context.getModules(); - for (final Module module : modules) { - if (module.getName().equals("leafref-validation2")) { - mainModule = module; - } - } - - rootModuleQname = mainModule.getQNameModule(); - } - - private static void initDataTree() { - - inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context); - - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - - final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(chips); - final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode); - final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips); - initialDataTreeModification.write(path1, chipsContainer); - - final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(deviceTypeStr); - final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode); - final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr); - initialDataTreeModification.write(path2, deviceTypesContainer); - - initialDataTreeModification.ready(); - final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification); - - inMemoryDataTree.commit(writeChipsCandidate); - - LOG.debug("{}", inMemoryDataTree); - } - - private static void initLeafRefContext() { - rootLeafRefContext = LeafRefContext.create(context); - } - private static ContainerNode createDevTypeStrContainer(final ContainerSchemaNode container) { final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.getDataChildByName(deviceType); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java index 37b9c34c8e..5884ab2c1f 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertTrue; import java.util.Set; import org.apache.log4j.BasicConfigurator; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -81,10 +82,69 @@ public class DataTreeCandidateValidatorTest3 { @BeforeClass public static void init() { - initSchemaContext(); - initLeafRefContext(); - initQnames(); - initDataTree(); + context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); + + final Set modules = context.getModules(); + for (final Module module : modules) { + if (module.getName().equals("leafref-validation3")) { + mainModule = module; + } + } + + rootModuleQname = mainModule.getQNameModule(); + rootLeafRefContext = LeafRefContext.create(context); + + + chips = QName.create(rootModuleQname, "chips"); + chip = QName.create(rootModuleQname, "chip"); + devType = QName.create(rootModuleQname, "dev_type"); + chipDesc = QName.create(rootModuleQname, "chip_desc"); + + devices = QName.create(rootModuleQname, "devices"); + device = QName.create(rootModuleQname, "device"); + typeText1 = QName.create(rootModuleQname, "type_text1"); + typeText2 = QName.create(rootModuleQname, "type_text2"); + typeText3 = QName.create(rootModuleQname, "type_text3"); + devDesc = QName.create(rootModuleQname, "dev_desc"); + sn = QName.create(rootModuleQname, "sn"); + defaultIp = QName.create(rootModuleQname, "default_ip"); + + deviceTypeStr = QName.create(rootModuleQname, "device_types"); + deviceType = QName.create(rootModuleQname, "device_type"); + type1 = QName.create(rootModuleQname, "type1"); + type2 = QName.create(rootModuleQname, "type2"); + type3 = QName.create(rootModuleQname, "type3"); + desc = QName.create(rootModuleQname, "desc"); + + inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context); + + final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); + + final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(chips); + final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode); + final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips); + initialDataTreeModification.write(path1, chipsContainer); + + final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule + .getDataChildByName(deviceTypeStr); + final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode); + final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr); + initialDataTreeModification.write(path2, deviceTypesContainer); + + initialDataTreeModification.ready(); + final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification); + + inMemoryDataTree.commit(writeChipsCandidate); + + LOG.debug("{}", inMemoryDataTree); + } + + @AfterClass + public static void cleanup() { + inMemoryDataTree = null; + rootLeafRefContext = null; + mainModule = null; + context = null; } @Test @@ -171,72 +231,6 @@ public class DataTreeCandidateValidatorTest3 { assertTrue(exception); } - private static void initQnames() { - - chips = QName.create(rootModuleQname, "chips"); - chip = QName.create(rootModuleQname, "chip"); - devType = QName.create(rootModuleQname, "dev_type"); - chipDesc = QName.create(rootModuleQname, "chip_desc"); - - devices = QName.create(rootModuleQname, "devices"); - device = QName.create(rootModuleQname, "device"); - typeText1 = QName.create(rootModuleQname, "type_text1"); - typeText2 = QName.create(rootModuleQname, "type_text2"); - typeText3 = QName.create(rootModuleQname, "type_text3"); - devDesc = QName.create(rootModuleQname, "dev_desc"); - sn = QName.create(rootModuleQname, "sn"); - defaultIp = QName.create(rootModuleQname, "default_ip"); - - deviceTypeStr = QName.create(rootModuleQname, "device_types"); - deviceType = QName.create(rootModuleQname, "device_type"); - type1 = QName.create(rootModuleQname, "type1"); - type2 = QName.create(rootModuleQname, "type2"); - type3 = QName.create(rootModuleQname, "type3"); - desc = QName.create(rootModuleQname, "desc"); - } - - private static void initSchemaContext() { - context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); - - final Set modules = context.getModules(); - for (final Module module : modules) { - if (module.getName().equals("leafref-validation3")) { - mainModule = module; - } - } - - rootModuleQname = mainModule.getQNameModule(); - } - - private static void initDataTree() { - - inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context); - - final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification(); - - final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.getDataChildByName(chips); - final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode); - final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips); - initialDataTreeModification.write(path1, chipsContainer); - - final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule - .getDataChildByName(deviceTypeStr); - final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode); - final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr); - initialDataTreeModification.write(path2, deviceTypesContainer); - - initialDataTreeModification.ready(); - final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification); - - inMemoryDataTree.commit(writeChipsCandidate); - - LOG.debug("{}", inMemoryDataTree); - } - - private static void initLeafRefContext() { - rootLeafRefContext = LeafRefContext.create(context); - } - private static ContainerNode createDevTypeStrContainer(final ContainerSchemaNode container) { final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.getDataChildByName(deviceType); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java index b76940c5ae..9d2a02bebe 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertTrue; import java.util.Map; import java.util.Set; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -26,7 +27,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class LeafRefContextTest { - private static SchemaContext context; private static Module rootMod; private static QNameModule root; @@ -47,6 +47,14 @@ public class LeafRefContextTest { rootLeafRefContext = LeafRefContext.create(context); } + @AfterClass + public static void cleanup() { + context = null; + root = null; + rootMod = null; + rootLeafRefContext = null; + } + @Test public void test() { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java index 32ff88de6f..86ce040fed 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java @@ -15,6 +15,7 @@ import static org.junit.Assert.assertTrue; import java.util.List; import java.util.Set; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -34,9 +35,7 @@ public class LeafRefContextTreeBuilderTest { private static final Logger LOG = LoggerFactory.getLogger(LeafRefContextTreeBuilderTest.class); private static SchemaContext context; - private static Module impMod; private static Module tstMod; - private static QNameModule imp; private static QNameModule tst; private static LeafRefContext rootLeafRefContext; @@ -46,20 +45,24 @@ public class LeafRefContextTreeBuilderTest { final Set modules = context.getModules(); for (final Module module : modules) { - if (module.getName().equals("import-mod")) { - impMod = module; - } if (module.getName().equals("leafref-test")) { tstMod = module; } } - imp = impMod.getQNameModule(); tst = tstMod.getQNameModule(); rootLeafRefContext = LeafRefContext.create(context); } + @AfterClass + public static void cleanup() { + context = null; + tst = null; + tstMod = null; + rootLeafRefContext = null; + } + @Test public void buildLeafRefContextTreeTest1() { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java index 7cf9c328b9..778a0945d1 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java @@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.data.impl.schema; import static org.junit.Assert.assertEquals; import java.util.Collections; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -50,13 +51,14 @@ public class InstanceIdToNodesTest { private final NodeWithValue leafListWithValue = new NodeWithValue<>( leafList.getNodeType(), "abcd"); - static SchemaContext createTestContext() { - return YangParserTestUtils.parseYangResources(InstanceIdToNodesTest.class, "/filter-test.yang"); - } - @BeforeClass public static void setUp() { - ctx = createTestContext(); + ctx = YangParserTestUtils.parseYangResources(InstanceIdToNodesTest.class, "/filter-test.yang"); + } + + @AfterClass + public static void teardown() { + ctx = null; } @Test diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java index 901e9181f7..4c646622f3 100644 --- a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java +++ b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java @@ -18,6 +18,7 @@ import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResour import com.google.common.collect.Range; import java.util.List; import java.util.Optional; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -66,6 +67,12 @@ public class EffectiveStatementTypeTest { assertNotNull(types); } + @AfterClass + public static void teardown() { + effectiveSchemaContext = null; + types = null; + } + @Test public void testBinary() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-binary")); diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludedStmtsTest.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludedStmtsTest.java index 9065e0096f..e078597c8a 100644 --- a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludedStmtsTest.java +++ b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/IncludedStmtsTest.java @@ -17,6 +17,7 @@ import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResour import java.util.Iterator; import java.util.Set; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -40,6 +41,11 @@ public class IncludedStmtsTest { .buildEffective(); } + @AfterClass + public static void teardown() { + result = null; + } + @Test public void includedTypedefsTest() { final Module testModule = result.findModules("root-module").iterator().next(); -- 2.36.6