Merge "BUG-1958 Fix leafref path in config-yang module."
[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 com.google.common.base.Optional;
4 import org.junit.Assert;
5 import org.junit.Test;
6 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
7 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
8 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
9 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
10 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
11
12 public class MergeModificationTest extends AbstractModificationTest{
13
14     @Test
15     public void testApply() throws Exception {
16         //TODO : Need to write a better test for this
17
18         //Write something into the datastore
19         DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
20         MergeModification writeModification = new MergeModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext());
21         writeModification.apply(writeTransaction);
22         commitTransaction(writeTransaction);
23
24         //Check if it's in the datastore
25         Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
26         Assert.assertTrue(data.isPresent());
27
28     }
29
30     @Test
31     public void testSerialization() {
32         SchemaContext schemaContext = TestModel.createTestContext();
33         NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
34         MergeModification mergeModification = new MergeModification(TestModel.TEST_PATH,
35                 node, schemaContext);
36
37         Object serialized = mergeModification.toSerializable();
38
39         MergeModification newModification = MergeModification.fromSerializable(serialized, schemaContext);
40
41         Assert.assertEquals("getPath", TestModel.TEST_PATH, newModification.getPath());
42         Assert.assertEquals("getData", node, newModification.getData());
43     }
44 }