From: Robert Varga Date: Mon, 30 Dec 2019 14:59:06 +0000 (+0100) Subject: Speed up YT891 test X-Git-Tag: v3.0.8~18 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=0f761d195da680f03b5454b4246922cb8ebb50a9;p=yangtools.git Speed up YT891 test Rather than parsing SchemaContext multiple times, just use @BeforeClass to initialize it once. Change-Id: I4c9e5c30a2767bab35133557121e0ff1710e688c Signed-off-by: Robert Varga (cherry picked from commit d76d0664c6090138b90d3e184746d5f9af64b3ea) --- diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Yangtools891Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Yangtools891Test.java index 23ade82412..b40652cf6b 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Yangtools891Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Yangtools891Test.java @@ -9,7 +9,9 @@ package org.opendaylight.yangtools.yang.data.codec.xml; import java.io.InputStream; import javax.xml.stream.XMLStreamReader; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.QName; @@ -44,23 +46,36 @@ public class Yangtools891Test { private static final QName BAZ_TOP = QName.create(BAZ_NS, BAZ_REV, "baz-top"); private static final YangInstanceIdentifier BAZ_TOP_ID = YangInstanceIdentifier.of(BAZ_TOP); - private SchemaContext schemaContext; - private LeafRefContext leafRefContext; + private static SchemaContext schemaContext; + private static LeafRefContext leafRefContext; + private static ContainerSchemaNode fooTopNode; + private static ContainerSchemaNode bazTopNode; + private DataTree dataTree; - private ContainerSchemaNode fooTopNode; - private ContainerSchemaNode bazTopNode; @Before - public void setup() { + public void before() { + dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext); + } + + @BeforeClass + public static void beforeClass() { schemaContext = YangParserTestUtils.parseYangResourceDirectory("/yangtools891"); leafRefContext = LeafRefContext.create(schemaContext); - dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext); final Module fooModule = schemaContext.findModule(FOO, Revision.of(FOO_REV)).get(); fooTopNode = (ContainerSchemaNode) fooModule.findDataChildByName(FOO_TOP).get(); final Module bazModule = schemaContext.findModule(BAZ, Revision.of(BAZ_REV)).get(); bazTopNode = (ContainerSchemaNode) bazModule.findDataChildByName(BAZ_TOP).get(); } + @AfterClass + public static void afterClass() { + schemaContext = null; + leafRefContext = null; + fooTopNode = null; + bazTopNode = null; + } + @Test public void testValid() throws Exception { final NormalizedNode fooTop = readNode("/yangtools891/grouping-with-list-valid.xml", fooTopNode); @@ -110,7 +125,8 @@ public class Yangtools891Test { LeafRefValidation.validate(writeContributorsCandidate, leafRefContext); } - private NormalizedNode readNode(final String filename, final ContainerSchemaNode node) throws Exception { + private static NormalizedNode readNode(final String filename, final ContainerSchemaNode node) + throws Exception { final InputStream resourceAsStream = Yangtools891Test.class.getResourceAsStream(filename); final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream); final NormalizedNodeResult result = new NormalizedNodeResult();