Bug 2268: Use streaming for Modification payload
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / modification / WriteModificationTest.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 WriteModificationTest extends AbstractModificationTest {
16
17     @Test
18     public void testApply() throws Exception {
19         //Write something into the datastore
20         DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
21         WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
22                 ImmutableNodes.containerNode(TestModel.TEST_QNAME));
23         writeModification.apply(writeTransaction);
24         commitTransaction(writeTransaction);
25
26         //Check if it's in the datastore
27         Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
28         Assert.assertTrue(data.isPresent());
29     }
30
31     @Test
32     public void testSerialization() {
33         YangInstanceIdentifier path = TestModel.TEST_PATH;
34         NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
35                 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
36                 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
37
38         WriteModification expected = new WriteModification(path, data);
39
40         WriteModification clone = (WriteModification) SerializationUtils.clone(expected);
41         assertEquals("getPath", expected.getPath(), clone.getPath());
42         assertEquals("getData", expected.getData(), clone.getData());
43     }
44 }