Update CursorAwareDataTree{Modification,Snapshot} API
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / DataTreeCandidatesTest.java
index e3160a839c4f096ef811e8247b65c5d6eabccf7c..20361ddacff64cc772e23908b37f153153409459 100644 (file)
@@ -13,15 +13,16 @@ import static org.junit.Assert.fail;
 
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 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.DataTreeCandidates;
+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.DataTreeModificationCursor;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
@@ -31,7 +32,7 @@ import org.slf4j.LoggerFactory;
 
 public class DataTreeCandidatesTest {
 
-    private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidates.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidatesTest.class);
 
     private static final SchemaContext SCHEMA_CONTEXT = TestModel.createTestContext();
 
@@ -39,8 +40,7 @@ public class DataTreeCandidatesTest {
 
     @Before
     public void setUp() throws Exception {
-        dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-        dataTree.setSchemaContext(SCHEMA_CONTEXT);
+        dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
 
         final ContainerNode testContainer = ImmutableContainerNodeBuilder.create()
                 .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
@@ -49,8 +49,9 @@ public class DataTreeCandidatesTest {
                         .build())
                 .build();
 
-        final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) dataTree.takeSnapshot().newModification();
-        final DataTreeModificationCursor cursor = modification.createCursor(YangInstanceIdentifier.EMPTY);
+        final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) dataTree.takeSnapshot()
+                .newModification();
+        final DataTreeModificationCursor cursor = modification.openCursor();
         cursor.write(TestModel.TEST_PATH.getLastPathArgument(), testContainer);
         modification.ready();
 
@@ -60,16 +61,20 @@ public class DataTreeCandidatesTest {
     }
 
     @Test
-    public void testRootedCandidate() throws Exception {
-        final DataTree innerDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL, TestModel.INNER_CONTAINER_PATH);
-        innerDataTree.setSchemaContext(SCHEMA_CONTEXT);
+    public void testRootedCandidate() throws DataValidationFailedException {
+        final DataTree innerDataTree = new InMemoryDataTreeFactory().create(
+            new DataTreeConfiguration.Builder(TreeType.OPERATIONAL)
+            .setMandatoryNodesValidation(true)
+            .setRootPath(TestModel.INNER_CONTAINER_PATH)
+            .setUniqueIndexes(true).build(), SCHEMA_CONTEXT);
 
         final LeafNode<String> leaf = ImmutableLeafNodeBuilder.<String>create()
                 .withNodeIdentifier(new NodeIdentifier(TestModel.VALUE_QNAME))
                 .withValue("testing-value")
                 .build();
 
-        final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) innerDataTree.takeSnapshot().newModification();
+        final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) innerDataTree.takeSnapshot()
+                .newModification();
         modification.write(TestModel.VALUE_PATH, leaf);
 
         modification.ready();
@@ -78,7 +83,8 @@ public class DataTreeCandidatesTest {
         dataTree.commit(candidate);
 
         final DataTreeModification newModification = dataTree.takeSnapshot().newModification();
-        final DataTreeCandidate newCandidate = DataTreeCandidates.newDataTreeCandidate(TestModel.INNER_CONTAINER_PATH, candidate.getRootNode());
+        final DataTreeCandidate newCandidate = DataTreeCandidates.newDataTreeCandidate(TestModel.INNER_CONTAINER_PATH,
+            candidate.getRootNode());
 
         try {
             // lets see if getting the identifier of the root node throws an exception
@@ -95,4 +101,4 @@ public class DataTreeCandidatesTest {
         final LeafNode<?> readLeaf = (LeafNode<?>) newModification.readNode(TestModel.INNER_VALUE_PATH).get();
         assertEquals(readLeaf, leaf);
     }
-}
\ No newline at end of file
+}