Bug 2268: Use streaming for Modification payload
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / modification / MergeModificationTest.java
1 package org.opendaylight.controller.cluster.datastore.modification;
2
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;
7 import org.junit.Test;
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;
14
15 public class MergeModificationTest extends AbstractModificationTest{
16
17     @Test
18     public void testApply() throws Exception {
19         //TODO : Need to write a better test for this
20
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);
27
28         //Check if it's in the datastore
29         Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
30         Assert.assertTrue(data.isPresent());
31
32     }
33
34     @Test
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();
40
41         MergeModification expected = new MergeModification(path, data);
42
43         MergeModification clone = (MergeModification) SerializationUtils.clone(expected);
44         assertEquals("getPath", expected.getPath(), clone.getPath());
45         assertEquals("getData", expected.getData(), clone.getData());
46     }
47 }