X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FPruningDataTreeModificationTest.java;h=7a8d065b14e0834a8ad0e921d3285b5d2af2fee9;hp=5e7c1cadff8f14b14d56e01929c9a74405202412;hb=5464f50be733df1bbbe31cf05665d542d3b7c5e7;hpb=561058be77594a026abbdbe82616fc65c7f58f48 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java index 5e7c1cadff..7a8d065b14 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java @@ -22,15 +22,16 @@ import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.T import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.innerNode; import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.outerNode; import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.outerNodeEntry; + import com.google.common.base.Optional; import com.google.common.reflect.Reflection; -import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.cluster.datastore.Shard; import org.opendaylight.controller.cluster.datastore.ShardDataTree; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel; @@ -41,6 +42,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor; @@ -70,22 +72,19 @@ public class PruningDataTreeModificationTest { private PruningDataTreeModification pruningDataTreeModification; @Before - public void setUp(){ + public void setUp() { MockitoAnnotations.initMocks(this); dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); dataTree.setSchemaContext(SCHEMA_CONTEXT); realModification = dataTree.takeSnapshot().newModification(); - proxyModification = Reflection.newProxy(DataTreeModification.class, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - try { - method.invoke(mockModification, args); - return method.invoke(realModification, args); - } catch (InvocationTargetException e) { - throw e.getCause(); - } + proxyModification = Reflection.newProxy(DataTreeModification.class, (proxy, method, args) -> { + try { + method.invoke(mockModification, args); + return method.invoke(realModification, args); + } catch (InvocationTargetException e) { + throw e.getCause(); } }); @@ -93,14 +92,14 @@ public class PruningDataTreeModificationTest { } @Test - public void testDelete(){ + public void testDelete() { pruningDataTreeModification.delete(CarsModel.BASE_PATH); verify(mockModification, times(1)).delete(CarsModel.BASE_PATH); } @Test - public void testDeleteOnException(){ + public void testDeleteOnException() { YangInstanceIdentifier path = CarsModel.BASE_PATH; doThrow(SchemaValidationFailedException.class).when(mockModification).delete(path); @@ -111,7 +110,7 @@ public class PruningDataTreeModificationTest { @Test - public void testMerge(){ + public void testMerge() { NormalizedNode normalizedNode = CarsModel.create(); YangInstanceIdentifier path = CarsModel.BASE_PATH; pruningDataTreeModification.merge(path, normalizedNode); @@ -120,7 +119,7 @@ public class PruningDataTreeModificationTest { } @Test - public void testMergeWithInvalidNamespace() throws DataValidationFailedException{ + public void testMergeWithInvalidNamespace() throws DataValidationFailedException { NormalizedNode normalizedNode = PeopleModel.emptyContainer(); YangInstanceIdentifier path = PeopleModel.BASE_PATH; @@ -133,15 +132,15 @@ public class PruningDataTreeModificationTest { } @Test - public void testMergeWithInvalidChildNodeNames() throws DataValidationFailedException{ + public void testMergeWithInvalidChildNodeNames() throws DataValidationFailedException { ContainerNode augContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild( ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build(); DataContainerChild outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); - ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).withChild(augContainer). - withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")).build(); + ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create() + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) + .withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")).build(); YangInstanceIdentifier path = TestModel.TEST_PATH; @@ -158,7 +157,7 @@ public class PruningDataTreeModificationTest { } @Test - public void testMergeWithValidNamespaceAndInvalidNodeName() throws DataValidationFailedException{ + public void testMergeWithValidNamespaceAndInvalidNodeName() throws DataValidationFailedException { NormalizedNode normalizedNode = ImmutableNodes.containerNode(INVALID_TEST_QNAME); YangInstanceIdentifier path = INVALID_TEST_PATH; @@ -171,7 +170,7 @@ public class PruningDataTreeModificationTest { } @Test - public void testWrite(){ + public void testWrite() { NormalizedNode normalizedNode = CarsModel.create(); YangInstanceIdentifier path = CarsModel.BASE_PATH; pruningDataTreeModification.write(path, normalizedNode); @@ -180,26 +179,30 @@ public class PruningDataTreeModificationTest { } @Test - public void testWriteRootNode() throws Exception{ - ShardDataTree shardDataTree = new ShardDataTree(SCHEMA_CONTEXT, TreeType.CONFIGURATION); - DataTreeModification mod = shardDataTree.newModification(); + public void testWriteRootNode() throws Exception { + final DataTree localDataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); + localDataTree.setSchemaContext(SCHEMA_CONTEXT); + DataTreeModification mod = localDataTree.takeSnapshot().newModification(); mod.write(CarsModel.BASE_PATH, CarsModel.create()); - shardDataTree.commit(mod); + mod.ready(); + localDataTree.validate(mod); + localDataTree.commit(localDataTree.prepare(mod)); - NormalizedNode normalizedNode = shardDataTree.readNode(YangInstanceIdentifier.EMPTY).get(); + NormalizedNode normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get(); pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode); dataTree.commit(getCandidate()); Optional> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY); assertEquals("Root present", true, actual.isPresent()); assertEquals("Root node", normalizedNode, actual.get()); - } @Test - public void testWriteRootNodeWithInvalidChild() throws Exception{ - ShardDataTree shardDataTree = new ShardDataTree(SCHEMA_CONTEXT, TreeType.CONFIGURATION); + public void testWriteRootNodeWithInvalidChild() throws Exception { + final Shard mockShard = Mockito.mock(Shard.class); + + ShardDataTree shardDataTree = new ShardDataTree(mockShard, SCHEMA_CONTEXT, TreeType.CONFIGURATION); NormalizedNode root = shardDataTree.readNode(YangInstanceIdentifier.EMPTY).get(); NormalizedNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( @@ -215,7 +218,7 @@ public class PruningDataTreeModificationTest { } @Test - public void testWriteWithInvalidNamespace() throws DataValidationFailedException{ + public void testWriteWithInvalidNamespace() throws DataValidationFailedException { NormalizedNode normalizedNode = PeopleModel.emptyContainer(); YangInstanceIdentifier path = PeopleModel.BASE_PATH; @@ -228,16 +231,16 @@ public class PruningDataTreeModificationTest { } @Test - public void testWriteWithInvalidChildNodeNames() throws DataValidationFailedException{ + public void testWriteWithInvalidChildNodeNames() throws DataValidationFailedException { ContainerNode augContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild( ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build(); DataContainerChild outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two"))); - ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).withChild(augContainer). - withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")). - withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build(); + ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create() + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) + .withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")) + .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build(); YangInstanceIdentifier path = TestModel.TEST_PATH; @@ -245,9 +248,9 @@ public class PruningDataTreeModificationTest { dataTree.commit(getCandidate()); - ContainerNode prunedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode). - withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build(); + ContainerNode prunedNode = ImmutableContainerNodeBuilder.create() + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode) + .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name")).build(); Optional> actual = dataTree.takeSnapshot().readNode(path); assertEquals("After pruning present", true, actual.isPresent()); @@ -255,14 +258,14 @@ public class PruningDataTreeModificationTest { } @Test - public void testReady(){ + public void testReady() { pruningDataTreeModification.ready(); verify(mockModification).ready(); } @Test - public void testApplyToCursor(){ + public void testApplyToCursor() { DataTreeModificationCursor dataTreeModificationCursor = mock(DataTreeModificationCursor.class); pruningDataTreeModification.applyToCursor(dataTreeModificationCursor); @@ -270,26 +273,27 @@ public class PruningDataTreeModificationTest { } @Test - public void testReadNode(){ + public void testReadNode() { pruningDataTreeModification.readNode(CarsModel.BASE_PATH); verify(mockModification).readNode(CarsModel.BASE_PATH); } @Test - public void testNewModification(){ + public void testNewModification() { realModification.ready(); DataTreeModification dataTreeModification = pruningDataTreeModification.newModification(); - assertTrue("new modification not of type PruningDataTreeModification", dataTreeModification instanceof PruningDataTreeModification); + assertTrue("new modification not of type PruningDataTreeModification", + dataTreeModification instanceof PruningDataTreeModification); } private DataTreeCandidateTip getCandidate() throws DataValidationFailedException { pruningDataTreeModification.ready(); - DataTreeModification mod = pruningDataTreeModification.getResultingModification(); + DataTreeModification mod = pruningDataTreeModification.delegate(); mod = mod == proxyModification ? realModification : mod; dataTree.validate(mod); DataTreeCandidateTip candidate = dataTree.prepare(mod); return candidate; } -} \ No newline at end of file +}