Speed up YT891 test 31/86631/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Dec 2019 14:59:06 +0000 (15:59 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Dec 2019 16:13:06 +0000 (17:13 +0100)
Rather than parsing SchemaContext multiple times, just use @BeforeClass
to initialize it once.

Change-Id: I4c9e5c30a2767bab35133557121e0ff1710e688c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Yangtools891Test.java

index 23ade8241264e2959f80b3a950d636376fb65a2b..b40652cf6bdc5e721b63b92e3654f53170935dd4 100644 (file)
@@ -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();