1 package org.opendaylight.controller.cluster.datastore.modification;
3 import static org.junit.Assert.assertEquals;
4 import com.google.common.base.Optional;
5 import org.apache.commons.lang.SerializationUtils;
6 import org.junit.Assert;
8 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
9 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
10 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
12 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
13 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
15 public class MergeModificationTest extends AbstractModificationTest{
18 public void testApply() throws Exception {
19 //TODO : Need to write a better test for this
21 //Write something into the datastore
22 DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
23 MergeModification writeModification = new MergeModification(TestModel.TEST_PATH,
24 ImmutableNodes.containerNode(TestModel.TEST_QNAME));
25 writeModification.apply(writeTransaction);
26 commitTransaction(writeTransaction);
28 //Check if it's in the datastore
29 Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
30 Assert.assertTrue(data.isPresent());
35 public void testSerialization() {
36 YangInstanceIdentifier path = TestModel.TEST_PATH;
37 NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
38 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
39 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
41 MergeModification expected = new MergeModification(path, data);
43 MergeModification clone = (MergeModification) SerializationUtils.clone(expected);
44 assertEquals("getPath", expected.getPath(), clone.getPath());
45 assertEquals("getData", expected.getData(), clone.getData());