Merge "BUG 720 - YANG leaf as JSON input *<*:* couldn't be saved"
[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 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 WriteModificationTest extends AbstractModificationTest{
13
14     @Test
15     public void testApply() throws Exception {
16         //Write something into the datastore
17         DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
18         WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
19                 ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext());
20         writeModification.apply(writeTransaction);
21         commitTransaction(writeTransaction);
22
23         //Check if it's in the datastore
24         Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
25         Assert.assertTrue(data.isPresent());
26     }
27
28     @Test
29     public void testSerialization() {
30         SchemaContext schemaContext = TestModel.createTestContext();
31         NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
32         WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
33                 node, schemaContext);
34
35         Object serialized = writeModification.toSerializable();
36
37         WriteModification newModification = WriteModification.fromSerializable(serialized, schemaContext);
38
39         Assert.assertEquals("getPath", TestModel.TEST_PATH, newModification.getPath());
40         Assert.assertEquals("getData", node, newModification.getData());
41     }
42 }