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%2Fpersisted%2FCommitTransactionPayloadTest.java;h=c081b89137e154b2d5d5ab3b7338b1da23b62a71;hp=31dc624a11c6998a48c1a9fd27720212d85c60e5;hb=beff6b6befd02f9a6dd7a4db10daad611776afab;hpb=5464f50be733df1bbbe31cf05665d542d3b7c5e7 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/CommitTransactionPayloadTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/CommitTransactionPayloadTest.java index 31dc624a11..c081b89137 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/CommitTransactionPayloadTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/CommitTransactionPayloadTest.java @@ -18,6 +18,8 @@ import org.apache.commons.lang3.SerializationUtils; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.AbstractTest; +import org.opendaylight.controller.cluster.datastore.persisted.DataTreeCandidateInputOutput.DataTreeCandidateWithVersion; +import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -25,12 +27,16 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; 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.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; 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.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.data.impl.schema.tree.InMemoryDataTreeFactory; public class CommitTransactionPayloadTest extends AbstractTest { static final QName LEAF_SET = QName.create(TestModel.TEST_QNAME, "leaf-set"); @@ -62,42 +68,29 @@ public class CommitTransactionPayloadTest extends AbstractTest { } } - private static void assertCandidateEquals(final DataTreeCandidate expected, final DataTreeCandidate actual) { - assertEquals("root path", expected.getRootPath(), actual.getRootPath()); - - final DataTreeCandidateNode expRoot = expected.getRootNode(); - final DataTreeCandidateNode actRoot = expected.getRootNode(); - assertEquals("root type", expRoot.getModificationType(), actRoot.getModificationType()); - - switch (actRoot.getModificationType()) { - case DELETE: - case WRITE: - assertEquals("root data", expRoot.getDataAfter(), actRoot.getDataAfter()); - break; - case SUBTREE_MODIFIED: - assertChildrenEquals(expRoot.getChildNodes(), actRoot.getChildNodes()); - break; - default: - fail("Unexpect root type " + actRoot.getModificationType()); - break; - } - - assertCandidateNodeEquals(expected.getRootNode(), actual.getRootNode()); + private static void assertCandidateEquals(final DataTreeCandidate expected, + final DataTreeCandidateWithVersion actual) { + final DataTreeCandidate candidate = actual.getCandidate(); + assertEquals("root path", expected.getRootPath(), candidate.getRootPath()); + assertCandidateNodeEquals(expected.getRootNode(), candidate.getRootNode()); } private static void assertCandidateNodeEquals(final DataTreeCandidateNode expected, final DataTreeCandidateNode actual) { assertEquals("child type", expected.getModificationType(), actual.getModificationType()); - assertEquals("child identifier", expected.getIdentifier(), actual.getIdentifier()); switch (actual.getModificationType()) { case DELETE: case WRITE: + assertEquals("child identifier", expected.getIdentifier(), actual.getIdentifier()); assertEquals("child data", expected.getDataAfter(), actual.getDataAfter()); break; case SUBTREE_MODIFIED: + assertEquals("child identifier", expected.getIdentifier(), actual.getIdentifier()); assertChildrenEquals(expected.getChildNodes(), actual.getChildNodes()); break; + case UNMODIFIED: + break; default: fail("Unexpect root type " + actual.getModificationType()); break; @@ -117,7 +110,7 @@ public class CommitTransactionPayloadTest extends AbstractTest { @Test public void testCandidateSerialization() throws IOException { final CommitTransactionPayload payload = CommitTransactionPayload.create(nextTransactionId(), candidate); - assertEquals("payload size", 181, payload.size()); + assertEquals("payload size", 156, payload.size()); } @Test @@ -190,4 +183,17 @@ public class CommitTransactionPayloadTest extends AbstractTest { CommitTransactionPayload payload = CommitTransactionPayload.create(nextTransactionId(), candidate); assertCandidateEquals(candidate, payload.getCandidate().getValue()); } + + @Test + public void testUnmodifiedRootCandidate() throws Exception { + final DataTree dataTree = new InMemoryDataTreeFactory().create( + DataTreeConfiguration.DEFAULT_CONFIGURATION, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG)); + + DataTreeModification modification = dataTree.takeSnapshot().newModification(); + modification.ready(); + candidate = dataTree.prepare(modification); + + CommitTransactionPayload payload = CommitTransactionPayload.create(nextTransactionId(), candidate); + assertCandidateEquals(candidate, payload.getCandidate().getValue()); + } }