Optimize IMDT tests 45/80145/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 28 Jan 2019 12:55:19 +0000 (13:55 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 5 Feb 2019 00:32:00 +0000 (01:32 +0100)
These tests are sharing a SchemaContext, do not set it up multiple
times but reuse it across runs.

Change-Id: If9e27ace5e0e3af966102019d57ef074aa652c5b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 9a54c14ce6741052d838e988dd8972271f7db2c4)

15 files changed:
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractTestModelTest.java [new file with mode: 0644]
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690Test.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug5968MergeTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug5968Test.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/CaseAugmentTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/CaseExclusionTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConcurrentTreeModificationTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ConfigStatementValidationTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeCandidatesTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeTransactionTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ErrorReportingTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MandatoryLeafTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModificationMetadataTreeTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java

diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractTestModelTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractTestModelTest.java
new file mode 100644 (file)
index 0000000..ad9e54b
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2019 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.impl.schema.tree;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public abstract class AbstractTestModelTest {
+    static SchemaContext SCHEMA_CONTEXT;
+
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = TestModel.createTestContext();
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
+    }
+}
index 518f6eb641d9a46ef7f815f47326615116b7242e..2dbe0b45b38f9e1cc45fc7ff8b055d18ca6c96b4 100644 (file)
@@ -28,9 +28,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
-public class Bug2690Test {
+public class Bug2690Test extends AbstractTestModelTest {
     private static final YangInstanceIdentifier NAME_PATH = YangInstanceIdentifier.of(TestModel.NON_PRESENCE_QNAME)
             .node(TestModel.NAME_QNAME);
 
@@ -39,7 +38,7 @@ public class Bug2690Test {
     @Before
     public void prepare() {
         inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
-            YangParserTestUtils.parseYangResource("/odl-datastore-test.yang"));
+            SCHEMA_CONTEXT);
     }
 
     @Test
index f70789933330451af7100ce4b5bbd6b209e2368a..3edde4b56b9e2739d5919fd36d4b5c222d5cf63a 100644 (file)
@@ -24,13 +24,12 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
  *           DataTreeModification, but should appear as UNMODIFIED in the
  *           resulting DataTreeCandidate.
  */
-public class Bug3674Test {
+public class Bug3674Test extends AbstractTestModelTest {
     private DataTree tree;
 
     @Before
     public void setUp() {
-        tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
-            TestModel.createTestContext());
+        tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
 
         // Create the top-level container
         final DataTreeModification mod = tree.takeSnapshot().newModification();
index 7ffedcab0a2bf9d4c583e4982fc9edaaf4a9a4fe..ae1e998e35becfc36e3331fc06f3cc3f91187cb5 100644 (file)
@@ -8,11 +8,11 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -40,12 +40,16 @@ public class Bug5968MergeTest {
     private static final QName LIST_ID = QName.create(NS, REV, "list-id");
     private static final QName MANDATORY_LEAF = QName.create(NS, REV, "mandatory-leaf");
     private static final QName COMMON_LEAF = QName.create(NS, REV, "common-leaf");
-    private SchemaContext schemaContext;
+    private static SchemaContext SCHEMA_CONTEXT;
 
-    @Before
-    public void init() {
-        this.schemaContext = TestModel.createTestContext("/bug5968/foo.yang");
-        assertNotNull("Schema context must not be null.", this.schemaContext);
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = TestModel.createTestContext("/bug5968/foo.yang");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
     }
 
     private static DataTree initDataTree(final SchemaContext schemaContext, final boolean withMapNode)
@@ -77,7 +81,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void mergeInvalidContainerTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
 
         final MapNode myList = createMap(true);
         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
@@ -101,7 +105,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void mergeInvalidMapTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         mergeMap(modificationTree, true);
 
@@ -120,7 +124,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void mergeInvalidMapEntryTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = initDataTree(schemaContext, true);
+        final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         mergeMapEntry(modificationTree, "1", null, "common-value");
@@ -191,7 +195,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void mergeValidContainerTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
 
         final MapNode myList = createMap(false);
         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
@@ -207,7 +211,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void mergeValidMapTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         mergeMap(modificationTree, false);
 
@@ -219,7 +223,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void mergeValidMapEntryTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = initDataTree(schemaContext, true);
+        final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         mergeMapEntry(modificationTree, "1", "mandatory-value", "common-value");
@@ -232,7 +236,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void validMultiStepsMergeTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         modificationTree.merge(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@@ -254,7 +258,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void invalidMultiStepsMergeTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         modificationTree.merge(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@@ -298,7 +302,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void validMultiStepsWriteAndMergeTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@@ -320,7 +324,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void invalidMultiStepsWriteAndMergeTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@@ -349,7 +353,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void validMapEntryMultiCommitMergeTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@@ -381,7 +385,7 @@ public class Bug5968MergeTest {
 
     @Test
     public void invalidMapEntryMultiCommitMergeTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         modificationTree.write(YangInstanceIdentifier.of(ROOT), createContainerBuilder().build());
@@ -433,7 +437,7 @@ public class Bug5968MergeTest {
      */
     @Test
     public void validMapEntryMultiCommitMergeTest2() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         final DataTreeModification modificationTree2 = inMemoryDataTree.takeSnapshot().newModification();
 
index 952e0e569ef5c15e79c7bf7d62342e034174fff6..0fad655e34dcda13ff4ba6df3f7134a105de73ba 100644 (file)
@@ -8,11 +8,11 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -39,12 +39,17 @@ public class Bug5968Test {
     private static final QName LIST_ID = QName.create(NS, REV, "list-id");
     private static final QName MANDATORY_LEAF = QName.create(NS, REV, "mandatory-leaf");
     private static final QName COMMON_LEAF = QName.create(NS, REV, "common-leaf");
-    private SchemaContext schemaContext;
 
-    @Before
-    public void init() {
-        this.schemaContext = TestModel.createTestContext("/bug5968/foo.yang");
-        assertNotNull("Schema context must not be null.", this.schemaContext);
+    private static SchemaContext SCHEMA_CONTEXT;
+
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = TestModel.createTestContext("/bug5968/foo.yang");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
     }
 
     private static DataTree initDataTree(final SchemaContext schemaContext, final boolean withMapNode)
@@ -76,7 +81,7 @@ public class Bug5968Test {
 
     @Test
     public void writeInvalidContainerTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
 
         final MapNode myList = createMap(true);
         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
@@ -100,7 +105,7 @@ public class Bug5968Test {
 
     @Test
     public void writeInvalidMapTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         writeMap(modificationTree, true);
 
@@ -119,7 +124,7 @@ public class Bug5968Test {
 
     @Test
     public void writeInvalidMapEntryTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = initDataTree(schemaContext, true);
+        final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         writeMapEntry(modificationTree, "1", null, "common-value");
@@ -180,7 +185,7 @@ public class Bug5968Test {
 
     @Test
     public void writeValidContainerTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
 
         final MapNode myList = createMap(false);
         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
@@ -196,7 +201,7 @@ public class Bug5968Test {
 
     @Test
     public void writeValidMapTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = emptyDataTree(schemaContext);
+        final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         writeMap(modificationTree, false);
 
@@ -208,7 +213,7 @@ public class Bug5968Test {
 
     @Test
     public void writeValidMapEntryTest() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = initDataTree(schemaContext, true);
+        final DataTree inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
 
         writeMapEntry(modificationTree, "1", "mandatory-value", "common-value");
index edc2091720bc7183041504eca9ee408ba9398d5f..82cdd360fef262719b454ef9bab954f112a562f3 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
 
 import com.google.common.collect.ImmutableSet;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
@@ -28,8 +28,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class CaseAugmentTest {
-
-    private SchemaContext schemaContext;
     private static final QName CHOICE1_QNAME = QName.create(TestModel.TEST_QNAME, "choice1");
     private static final QName C1L1_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf1");
     private static final QName C1L2_QNAME = QName.create(TestModel.TEST_QNAME, "case1-leaf2");
@@ -39,15 +37,21 @@ public class CaseAugmentTest {
     private static final AugmentationIdentifier AUGMENT_ID = new AugmentationIdentifier(
         ImmutableSet.of(C1L2_QNAME, C1L3_QNAME));
 
-    @Before
-    public void prepare() {
-        schemaContext = TestModel.createTestContext("/case-augment-test.yang");
-        assertNotNull("Schema context must not be null.", schemaContext);
+    private static SchemaContext SCHEMA_CONTEXT;
+
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = TestModel.createTestContext("/case-augment-test.yang");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
     }
 
-    private DataTree initDataTree() {
-        DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
-            DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+    private static DataTree initDataTree() {
+        DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION,
+            SCHEMA_CONTEXT);
         return inMemoryDataTree;
     }
 
index 89a2c0be84a73072b7d940a8b5f94e80e410cfff..4ac26ac68116fb8042e9430d02df8150714806a8 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
 
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -27,22 +28,28 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class CaseExclusionTest {
+    private static SchemaContext SCHEMA_CONTEXT;
 
-    private SchemaContext schemaContext;
+    private DataTree inMemoryDataTree;
 
-    @Before
-    public void prepare() {
-        schemaContext = TestModel.createTestContext("/case-exclusion-test.yang");
-        assertNotNull("Schema context must not be null.", schemaContext);
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = TestModel.createTestContext("/case-exclusion-test.yang");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
     }
 
-    private DataTree initDataTree() {
-        return new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+    @Before
+    public void before() {
+        inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION,
+            SCHEMA_CONTEXT);
     }
 
     @Test
     public void testCorrectCaseWrite() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = initDataTree();
         final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
 
         final ContainerNode container = Builders
@@ -63,7 +70,6 @@ public class CaseExclusionTest {
 
     @Test(expected = IllegalArgumentException.class)
     public void testCaseExclusion() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = initDataTree();
         final NodeIdentifier choice1Id = new NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
 
         final ContainerNode container = Builders
@@ -92,7 +98,6 @@ public class CaseExclusionTest {
 
     @Test(expected = IllegalArgumentException.class)
     public void testCaseExclusionOnChoiceWrite() throws DataValidationFailedException {
-        final DataTree inMemoryDataTree = initDataTree();
         // Container write
         final ContainerNode container = Builders.containerBuilder()
                 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build();
index 8765cd6b991347ed53aef65135a7985193716bb6..86434523ea61bb3b71f8beeb899ce4a8c70a55f9 100644 (file)
@@ -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.impl.schema.tree;
 
 import static org.junit.Assert.assertFalse;
@@ -31,11 +30,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ConcurrentTreeModificationTest {
+public class ConcurrentTreeModificationTest extends AbstractTestModelTest {
     private static final Logger LOG = LoggerFactory.getLogger(ConcurrentTreeModificationTest.class);
 
     private static final Short ONE_ID = 1;
@@ -59,15 +57,13 @@ public class ConcurrentTreeModificationTest {
             .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).build())
             .build();
 
-    private SchemaContext schemaContext;
     private DataTree inMemoryDataTree;
 
+
     @Before
     public void prepare() {
-        schemaContext = TestModel.createTestContext();
-        assertNotNull("Schema context must not be null.", schemaContext);
         inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
-            schemaContext);
+            SCHEMA_CONTEXT);
     }
 
     private static ContainerNode createFooTestContainerNode() {
index 33b1701f83118bfac88d305ea3b12ec8d47c3c29..c4271ea7a714ecbf092f5abeb28cb2d8474af428 100644 (file)
@@ -8,13 +8,11 @@
 
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import static org.junit.Assert.assertNotNull;
 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
 
 import com.google.common.base.VerifyException;
-import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -29,10 +27,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailed
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 // TODO: expand these tests to catch some more obscure cases
-public class ConfigStatementValidationTest {
+public class ConfigStatementValidationTest extends AbstractTestModelTest {
     private static final Short ONE_ID = 1;
     private static final Short TWO_ID = 2;
 
@@ -61,8 +58,6 @@ public class ConfigStatementValidationTest {
                     .build())
             .build();
 
-    private SchemaContext schemaContext;
-
     private static ContainerNode createFooTestContainerNode() {
         return ImmutableContainerNodeBuilder.create()
                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
@@ -75,16 +70,10 @@ public class ConfigStatementValidationTest {
                 .withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(BAR_NODE).build()).build();
     }
 
-    @Before
-    public void prepare() {
-        schemaContext = TestModel.createTestContext();
-        assertNotNull("Schema context must not be null.", schemaContext);
-    }
-
     @Test(expected = SchemaValidationFailedException.class)
     public void testOnPathFail() throws DataValidationFailedException {
         final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
-            DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+            DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node(
                 new YangInstanceIdentifier.NodeIdentifier(TestModel.INNER_LIST_QNAME)).node(
@@ -99,7 +88,7 @@ public class ConfigStatementValidationTest {
     @Test(expected = SchemaValidationFailedException.class)
     public void testOnDataFail() throws DataValidationFailedException {
         final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
-            DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+            DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         modificationTree.write(TestModel.TEST_PATH, createFooTestContainerNode());
         modificationTree.ready();
@@ -111,7 +100,7 @@ public class ConfigStatementValidationTest {
     @Test(expected = SchemaValidationFailedException.class)
     public void testOnDataLeafFail() throws DataValidationFailedException {
         final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
-            DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+            DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
         final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         modificationTree.write(TestModel.TEST_PATH, createBarTestContainerNode());
         modificationTree.ready();
@@ -123,7 +112,7 @@ public class ConfigStatementValidationTest {
     @Test(expected = SchemaValidationFailedException.class)
     public void testOnPathCaseLeafFail() throws DataValidationFailedException {
         final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
-            DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+            DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
         final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
                 TestModel.TEST_QNAME, "choice1"));
         final YangInstanceIdentifier.NodeIdentifier case2ContId = new YangInstanceIdentifier.NodeIdentifier(
@@ -143,7 +132,7 @@ public class ConfigStatementValidationTest {
     @Test(expected = VerifyException.class)
     public void testOnDataCaseLeafFail() throws DataValidationFailedException {
         final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
-            DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
+            DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
         final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
                 TestModel.TEST_QNAME, "choice1"));
         final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id);
index 20361ddacff64cc772e23908b37f153153409459..084e4418d71bfae87b3254613f5e9611d4db3d4f 100644 (file)
@@ -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.impl.schema.tree;
 
 import static org.junit.Assert.assertEquals;
@@ -30,12 +29,10 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class DataTreeCandidatesTest {
+public class DataTreeCandidatesTest extends AbstractTestModelTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidatesTest.class);
 
-    private static final SchemaContext SCHEMA_CONTEXT = TestModel.createTestContext();
-
     private DataTree dataTree;
 
     @Before
index 1ce0fdb7bbbd4629c8be8376e550c8bc740c5e7d..90421793dc356df9500912aff8cd989af0535619 100644 (file)
@@ -14,13 +14,12 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguratio
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 
-public class DataTreeTransactionTest {
+public class DataTreeTransactionTest extends AbstractTestModelTest {
     private DataTree tree;
 
     @Before
     public void setUp() {
-        tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
-            TestModel.createTestContext());
+        tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
     }
 
     @Test
index 90928a1a30b46884e5980563cb8af14196528e7e..ad50073a34f6c24bb5c6fa3dd4fb514bea2e7e03 100644 (file)
@@ -20,14 +20,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailed
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 
-public class ErrorReportingTest {
+public class ErrorReportingTest extends AbstractTestModelTest {
 
     private DataTree tree;
 
     @Before
     public void setup() {
-        tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
-            TestModel.createTestContext());
+        tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
     }
 
     @Test
index a9509322919a9e705d6c6b880b5bc4aa2fa61ea6..943c1de02d4a6b59069969e902fc3349f918f091 100644 (file)
@@ -8,10 +8,10 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
 
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -28,18 +28,22 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class MandatoryLeafTest {
 
-    private SchemaContext schemaContext;
+    private static SchemaContext SCHEMA_CONTEXT;
 
-    @Before
-    public void prepare() {
-        schemaContext = TestModel.createTestContext("/mandatory-leaf-test.yang");
-        assertNotNull("Schema context must not be null.", schemaContext);
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = TestModel.createTestContext("/mandatory-leaf-test.yang");
     }
 
-    private DataTree initDataTree(final boolean enableValidation) {
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
+    }
+
+    private static DataTree initDataTree(final boolean enableValidation) {
         return new InMemoryDataTreeFactory().create(
                 new DataTreeConfiguration.Builder(TreeType.CONFIGURATION).setMandatoryNodesValidation(enableValidation)
-                        .build(), schemaContext);
+                        .build(), SCHEMA_CONTEXT);
     }
 
     @Test
index c44addb20500a363fac4233364b85b1bb19977db..18aa79987419f3af19c9f2da030172442455cf77 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /*
  * Schema structure of document is
@@ -57,7 +56,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  *      }
  * }
  */
-public class ModificationMetadataTreeTest {
+public class ModificationMetadataTreeTest extends AbstractTestModelTest {
 
     private static final Short ONE_ID = 1;
     private static final Short TWO_ID = 2;
@@ -90,14 +89,11 @@ public class ModificationMetadataTreeTest {
                     .build())
                     .build();
 
-    private SchemaContext schemaContext;
     private RootModificationApplyOperation rootOper;
 
     @Before
     public void prepare() {
-        schemaContext = TestModel.createTestContext();
-        assertNotNull("Schema context must not be null.", schemaContext);
-        rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext,
+        rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
             DataTreeConfiguration.DEFAULT_OPERATIONAL));
     }
 
@@ -121,7 +117,7 @@ public class ModificationMetadataTreeTest {
     public NormalizedNode<?, ?> createDocumentOne() {
         return ImmutableContainerNodeBuilder
                 .create()
-                .withNodeIdentifier(new NodeIdentifier(schemaContext.getQName()))
+                .withNodeIdentifier(new NodeIdentifier(SCHEMA_CONTEXT.getQName()))
                 .withChild(createTestContainer()).build();
 
     }
@@ -139,7 +135,7 @@ public class ModificationMetadataTreeTest {
     @Test
     public void basicReadWrites() {
         final DataTreeModification modificationTree = new InMemoryDataTreeModification(
-            new InMemoryDataTreeSnapshot(schemaContext,
+            new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper), rootOper);
         final Optional<NormalizedNode<?, ?>> originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH);
         assertTrue(originalBarNode.isPresent());
@@ -166,7 +162,7 @@ public class ModificationMetadataTreeTest {
          * Creates empty Snapshot with associated schema context.
          */
         final DataTree t = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
-            schemaContext);
+            SCHEMA_CONTEXT);
 
         /**
          *
index 919178ca17dcce3e4fb8a2bfd34dcd6800ec1c0d..323eadef24860e526100ac6368f4311722609f7c 100644 (file)
@@ -30,11 +30,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class StoreTreeNodesTest {
+public class StoreTreeNodesTest extends AbstractTestModelTest {
     private static final Logger LOG = LoggerFactory.getLogger(StoreTreeNodesTest.class);
 
     private static final Short ONE_ID = 1;
@@ -64,28 +63,25 @@ public class StoreTreeNodesTest {
                     .build())
                     .build();
 
-    private SchemaContext schemaContext;
     private RootModificationApplyOperation rootOper;
 
     @Before
     public void prepare() {
-        schemaContext = TestModel.createTestContext();
-        assertNotNull("Schema context must not be null.", schemaContext);
-        rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext,
+        rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
             DataTreeConfiguration.DEFAULT_OPERATIONAL));
     }
 
     public NormalizedNode<?, ?> createDocumentOne() {
         return ImmutableContainerNodeBuilder
                 .create()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()))
+                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(SCHEMA_CONTEXT.getQName()))
                 .withChild(createTestContainer()).build();
 
     }
 
     @Test
     public void findNodeTestNodeFound() {
-        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
         final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
         final Optional<TreeNode> node = StoreTreeNodes.findNode(rootNode, OUTER_LIST_1_PATH);
@@ -94,7 +90,7 @@ public class StoreTreeNodesTest {
 
     @Test
     public void findNodeTestNodeNotFound() {
-        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
         final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
         final YangInstanceIdentifier outerList1InvalidPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
@@ -106,7 +102,7 @@ public class StoreTreeNodesTest {
 
     @Test
     public void findNodeCheckedTestNodeFound() {
-        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
         final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
         TreeNode foundNode = null;
@@ -120,7 +116,7 @@ public class StoreTreeNodesTest {
 
     @Test
     public void findNodeCheckedTestNodeNotFound() {
-        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
         final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
         final YangInstanceIdentifier outerList1InvalidPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
@@ -136,7 +132,7 @@ public class StoreTreeNodesTest {
 
     @Test
     public void findClosestOrFirstMatchTestNodeExists() {
-        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
         final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
         final Optional<TreeNode> expectedNode = StoreTreeNodes.findNode(rootNode, TWO_TWO_PATH);
@@ -148,7 +144,7 @@ public class StoreTreeNodesTest {
 
     @Test
     public void findClosestOrFirstMatchTestNodeDoesNotExist() {
-        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
         final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
         final YangInstanceIdentifier outerListInnerListPath = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH)
@@ -168,7 +164,7 @@ public class StoreTreeNodesTest {
 
     @Test
     public void getChildTestChildFound() {
-        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
         final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
         final Optional<TreeNode> node = StoreTreeNodes.getChild(Optional.ofNullable(rootNode),
@@ -178,7 +174,7 @@ public class StoreTreeNodesTest {
 
     @Test
     public void getChildTestChildNotFound() {
-        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext,
+        final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
                 TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper);
         final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode();
         final Optional<TreeNode> node = StoreTreeNodes.getChild(Optional.ofNullable(rootNode),