Bug 5085: Clean-up test and retest JUnit tests
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ConfigStatementValidationTest.java
index f35ad36e1a136a76da145cac9dd0a6210945e075..5322b9887bf2a2395113fce670a8ac081945b5b1 100644 (file)
@@ -5,6 +5,7 @@
  * 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.assertNotNull;
@@ -27,6 +28,7 @@ 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;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,20 +39,20 @@ public class ConfigStatementValidationTest {
     private static final Short ONE_ID = 1;
     private static final Short TWO_ID = 2;
 
-    private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
-            .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
+    private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier
+            .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
             .build();
 
-    private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
-            .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
+    private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier
+            .builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
             .build();
 
-    private static final MapEntryNode INNER_FOO_ENTRY_NODE =
-            ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "foo");
+    private static final MapEntryNode INNER_FOO_ENTRY_NODE = ImmutableNodes.mapEntry(TestModel.INNER_LIST_QNAME,
+            TestModel.NAME_QNAME, "foo");
 
-    private static final MapEntryNode INNER_BAR_ENTRY_NODE =
-            ImmutableNodes.mapEntryBuilder(QName.create(TestModel.TEST_QNAME, "inner-list2"), TestModel.NAME_QNAME, "foo")
-                    .withChild(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "value")).build();
+    private static final MapEntryNode INNER_BAR_ENTRY_NODE = ImmutableNodes
+            .mapEntryBuilder(QName.create(TestModel.TEST_QNAME, "inner-list2"), TestModel.NAME_QNAME, "foo")
+            .withChild(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "value")).build();
 
     private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
             .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(INNER_FOO_ENTRY_NODE) //
@@ -65,37 +67,32 @@ public class ConfigStatementValidationTest {
     private SchemaContext schemaContext;
 
     private static ContainerNode createFooTestContainerNode() {
-        return ImmutableContainerNodeBuilder
-                .create()
+        return ImmutableContainerNodeBuilder.create()
                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
-                .withChild(
-                        mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
-                                .withChild(FOO_NODE).build()).build();
+                .withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(FOO_NODE).build()).build();
     }
 
     private static ContainerNode createBarTestContainerNode() {
-        return ImmutableContainerNodeBuilder
-                .create()
+        return ImmutableContainerNodeBuilder.create()
                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
-                .withChild(
-                        mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
-                                .withChild(BAR_NODE).build()).build();
+                .withChild(mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(BAR_NODE).build()).build();
     }
 
     @Before
-    public void prepare() {
+    public void prepare() throws ReactorException {
         schemaContext = TestModel.createTestContext();
         assertNotNull("Schema context must not be null.", schemaContext);
     }
 
-    @Test(expected=SchemaValidationFailedException.class)
+    @Test(expected = SchemaValidationFailedException.class)
     public void testOnPathFail() throws DataValidationFailedException {
-        final InMemoryDataTree inMemoryDataTree =
-                (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
+        final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
+                TreeType.CONFIGURATION);
         inMemoryDataTree.setSchemaContext(schemaContext);
         final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
-        final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node(new YangInstanceIdentifier.NodeIdentifier(TestModel.INNER_LIST_QNAME))
-                .node(INNER_FOO_ENTRY_NODE.getIdentifier());
+        final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node(
+                new YangInstanceIdentifier.NodeIdentifier(TestModel.INNER_LIST_QNAME)).node(
+                INNER_FOO_ENTRY_NODE.getIdentifier());
         modificationTree.write(ii, INNER_FOO_ENTRY_NODE);
 
         inMemoryDataTree.validate(modificationTree);
@@ -103,10 +100,10 @@ public class ConfigStatementValidationTest {
         inMemoryDataTree.commit(prepare);
     }
 
-    @Test(expected=SchemaValidationFailedException.class)
+    @Test(expected = SchemaValidationFailedException.class)
     public void testOnDataFail() throws DataValidationFailedException {
-        final InMemoryDataTree inMemoryDataTree =
-                (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
+        final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
+                TreeType.CONFIGURATION);
         inMemoryDataTree.setSchemaContext(schemaContext);
         final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         modificationTree.write(TestModel.TEST_PATH, createFooTestContainerNode());
@@ -116,10 +113,10 @@ public class ConfigStatementValidationTest {
         inMemoryDataTree.commit(prepare);
     }
 
-    @Test(expected=SchemaValidationFailedException.class)
+    @Test(expected = SchemaValidationFailedException.class)
     public void testOnDataLeafFail() throws DataValidationFailedException {
-        final InMemoryDataTree inMemoryDataTree =
-                (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
+        final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
+                TreeType.CONFIGURATION);
         inMemoryDataTree.setSchemaContext(schemaContext);
         final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         modificationTree.write(TestModel.TEST_PATH, createBarTestContainerNode());
@@ -129,13 +126,13 @@ public class ConfigStatementValidationTest {
         inMemoryDataTree.commit(prepare);
     }
 
-    @Test(expected=SchemaValidationFailedException.class)
+    @Test(expected = SchemaValidationFailedException.class)
     public void testOnPathCaseLeafFail() throws DataValidationFailedException {
-        final InMemoryDataTree inMemoryDataTree =
-                (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
+        final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
+                TreeType.CONFIGURATION);
         inMemoryDataTree.setSchemaContext(schemaContext);
-        final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(
-                QName.create(TestModel.TEST_QNAME, "choice1"));
+        final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
+                TestModel.TEST_QNAME, "choice1"));
         final YangInstanceIdentifier.NodeIdentifier case2ContId = new YangInstanceIdentifier.NodeIdentifier(
                 QName.create(TestModel.TEST_QNAME, "case2-cont"));
         final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id).node(case2ContId);
@@ -144,19 +141,19 @@ public class ConfigStatementValidationTest {
 
         final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
         modificationTree.write(ii, case2Cont);
-
+        modificationTree.ready();
         inMemoryDataTree.validate(modificationTree);
         final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
         inMemoryDataTree.commit(prepare);
     }
 
-    @Test(expected=VerifyException.class)
+    @Test(expected = VerifyException.class)
     public void testOnDataCaseLeafFail() throws DataValidationFailedException {
-        final InMemoryDataTree inMemoryDataTree =
-                (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
+        final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(
+                TreeType.CONFIGURATION);
         inMemoryDataTree.setSchemaContext(schemaContext);
-        final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(
-                QName.create(TestModel.TEST_QNAME, "choice1"));
+        final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
+                TestModel.TEST_QNAME, "choice1"));
         final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id);
         final ChoiceNode choice1 = Builders.choiceBuilder().withNodeIdentifier(choice1Id)
                 .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case1-leaf1"), "leaf-value")).build();