Make DataTreeTip.prepare() throw a checked exception 01/84801/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Sep 2019 08:02:45 +0000 (10:02 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Sep 2019 09:16:05 +0000 (11:16 +0200)
Not all validation can be done during validate() phase, hence
allow validation failures to be reported cleanly.

Change-Id: I88dbe90c2e4b2fc79fad836939183fa43151ae6c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/DataTreeTip.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.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/Bug4454Test.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/ListConstraintsValidation.java

index f38a457228452b11b652b2cebcd900fd25528bbd..a46563e487f4e13d89d442883b32f166be58ad8c 100644 (file)
@@ -24,6 +24,7 @@ public interface DataTreeTip {
      * @throws DataValidationFailedException If modification data is not valid.
      * @throws NullPointerException if modification is null
      * @throws IllegalArgumentException if modification is unrecognized
+     * @throws DataValidationFailedException if modification would result in inconsistent data tree
      */
     void validate(DataTreeModification modification) throws DataValidationFailedException;
 
@@ -34,9 +35,9 @@ public interface DataTreeTip {
      * @return candidate data tree
      * @throws NullPointerException if modification is null
      * @throws IllegalArgumentException if modification is unrecognized
+     * @throws DataValidationFailedException if modification would result in inconsistent data tree
      */
-    // FIXME: 4.0.0: throw DataValidationFailedException or similar
-    DataTreeCandidateTip prepare(DataTreeModification modification);
+    DataTreeCandidateTip prepare(DataTreeModification modification) throws DataValidationFailedException;
 
     /**
      * {@inheritDoc}
index 46a6338e955f95f49fce35fca2b7248006a7297c..b5327e16f99fa247e06367dad4b09b5b43b98a05 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidation;
@@ -99,7 +100,7 @@ public class DataTreeCandidateValidatorTest {
     }
 
     @BeforeClass
-    public static void init()  {
+    public static void init() throws DataValidationFailedException {
         context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
 
         final Set<Module> modules = context.getModules();
@@ -175,7 +176,7 @@ public class DataTreeCandidateValidatorTest {
     }
 
     @Test
-    public void dataTreeCanditateValidationTest() {
+    public void dataTreeCanditateValidationTest() throws DataValidationFailedException {
         write();
 
         write2();
@@ -189,7 +190,7 @@ public class DataTreeCandidateValidatorTest {
         writeIntoMapEntry();
     }
 
-    private static void writeContributors() {
+    private static void writeContributors() throws DataValidationFailedException {
 
         final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
                 .findDataChildByName(odlContributor).get();
@@ -232,7 +233,7 @@ public class DataTreeCandidateValidatorTest {
 
     }
 
-    private static void writeIntoMapEntry() {
+    private static void writeIntoMapEntry() throws DataValidationFailedException {
 
         final Map<QName, Object> keys = new HashMap<>();
         keys.put(name, "New Project");
@@ -278,7 +279,7 @@ public class DataTreeCandidateValidatorTest {
 
     }
 
-    private static void writeMapEntry() {
+    private static void writeMapEntry() throws DataValidationFailedException {
 
         final Map<QName, Object> keys = new HashMap<>();
         keys.put(name, "New Project");
@@ -330,7 +331,7 @@ public class DataTreeCandidateValidatorTest {
 
     }
 
-    private static void write() {
+    private static void write() throws DataValidationFailedException {
 
         final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
                 .findDataChildByName(odlContributor).get();
@@ -378,7 +379,7 @@ public class DataTreeCandidateValidatorTest {
         assertTrue(exception);
     }
 
-    private static void write2() {
+    private static void write2() throws DataValidationFailedException {
 
         final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule.findDataChildByName(odl).get();
         final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon.findDataChildByName(con1).get();
@@ -553,7 +554,7 @@ public class DataTreeCandidateValidatorTest {
         return mapEntryBuilder.build();
     }
 
-    private static void delete() {
+    private static void delete() throws DataValidationFailedException {
 
         final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
                 .of(odlContributor);
@@ -562,8 +563,7 @@ public class DataTreeCandidateValidatorTest {
         delete.delete(contributorPath);
         delete.ready();
 
-        final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree
-                .prepare(delete);
+        final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree.prepare(delete);
 
         LOG.debug("*************************");
         LOG.debug("Before delete: ");
index 4450c8ae2c2cd12f2a2b7fde96506e32ea172573..7ea56da58d7476eb3040bea20f3c4a78ec1c05cb 100644 (file)
@@ -28,6 +28,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidation;
@@ -78,7 +79,7 @@ public class DataTreeCandidateValidatorTest2 {
     }
 
     @BeforeClass
-    public static void init() {
+    public static void init() throws DataValidationFailedException {
         context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
 
         final Set<Module> modules = context.getModules();
@@ -138,12 +139,11 @@ public class DataTreeCandidateValidatorTest2 {
     }
 
     @Test
-    public void dataTreeCanditateValidationTest2() {
-
+    public void dataTreeCanditateValidationTest2() throws DataValidationFailedException {
         writeDevices();
     }
 
-    private static void writeDevices() {
+    private static void writeDevices() throws DataValidationFailedException {
 
         final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
                 .get();
index ef8f4243c8bf34027f84bc6626870ec184860479..0aa847c80c63b309e142fc78e02753e84939b0b8 100644 (file)
@@ -28,6 +28,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefDataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefValidation;
@@ -81,7 +82,7 @@ public class DataTreeCandidateValidatorTest3 {
     }
 
     @BeforeClass
-    public static void init() {
+    public static void init() throws DataValidationFailedException {
         context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");
 
         final Set<Module> modules = context.getModules();
@@ -149,20 +150,15 @@ public class DataTreeCandidateValidatorTest3 {
     }
 
     @Test
-    public void dataTreeCanditateValidationTest2() {
-
+    public void dataTreeCanditateValidationTest2() throws DataValidationFailedException {
         writeDevices();
-
         mergeDevices();
     }
 
-    private static void writeDevices() {
-
+    private static void writeDevices() throws DataValidationFailedException {
         final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
                 .get();
-
         final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode);
-
         final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices);
         final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
         writeModification.write(devicesPath, devicesContainer);
@@ -194,7 +190,7 @@ public class DataTreeCandidateValidatorTest3 {
         LOG.debug("{}", inMemoryDataTree);
     }
 
-    private static void mergeDevices() {
+    private static void mergeDevices() throws DataValidationFailedException {
 
         final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
                 .get();
index 3edde4b56b9e2739d5919fd36d4b5c222d5cf63a..cd9c35f577da93b816b99d2f33adeb3cdea1d82d 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 
@@ -28,7 +29,7 @@ public class Bug3674Test extends AbstractTestModelTest {
     private DataTree tree;
 
     @Before
-    public void setUp() {
+    public void setUp() throws DataValidationFailedException {
         tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
 
         // Create the top-level container
@@ -39,7 +40,7 @@ public class Bug3674Test extends AbstractTestModelTest {
     }
 
     @Test
-    public void testDeleteOfNonExistingNode() {
+    public void testDeleteOfNonExistingNode() throws DataValidationFailedException {
         final DataTreeModification mod = tree.takeSnapshot().newModification();
         mod.delete(TestModel.OUTER_LIST_PATH);
         mod.ready();
index e33347e08cfa42515ce0c8721e2ddd88a679ae6a..4241ea6192df94d2bb5c68e9d00a0ee8cf732e63 100644 (file)
@@ -118,7 +118,7 @@ public class Bug4454Test {
     }
 
     @Before
-    public void prepare() {
+    public void prepare() throws DataValidationFailedException {
         inMemoryDataTree =  new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
             schemaContext);
         final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
index 90421793dc356df9500912aff8cd989af0535619..b2ba0afb6b2ea92c42888a18c18c5729aafb000e 100644 (file)
@@ -30,7 +30,7 @@ public class DataTreeTransactionTest extends AbstractTestModelTest {
     }
 
     @Test
-    public void testSealedPrepare() {
+    public void testSealedPrepare() throws DataValidationFailedException {
         final DataTreeModification mod = tree.takeSnapshot().newModification();
         mod.ready();
         tree.prepare(mod);
@@ -43,7 +43,7 @@ public class DataTreeTransactionTest extends AbstractTestModelTest {
     }
 
     @Test(expected = IllegalArgumentException.class)
-    public void testUnsealedPrepare() {
+    public void testUnsealedPrepare() throws DataValidationFailedException {
         final DataTreeModification mod = tree.takeSnapshot().newModification();
         tree.prepare(mod);
     }
index ad50073a34f6c24bb5c6fa3dd4fb514bea2e7e03..771cdfbf3af39d80d23bee91b642d1aeddac135c 100644 (file)
@@ -47,7 +47,7 @@ public class ErrorReportingTest extends AbstractTestModelTest {
     }
 
     @Test
-    public void parentConcurrentlyDeletedExisting() {
+    public void parentConcurrentlyDeletedExisting() throws DataValidationFailedException {
         DataTreeModification initial = tree.takeSnapshot().newModification();
         // We write node without creating parent
         initial.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
index abe4acb82f0cabc1b800a77ecc85aac1fd612c37..86b08d677ecc20ed2686af1442ee1c2ff9ff158e 100644 (file)
@@ -85,7 +85,7 @@ public class ListConstraintsValidation {
     }
 
     @Before
-    public void prepare() {
+    public void prepare() throws DataValidationFailedException {
         inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
             schemaContext);
         final DataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();