9daaa0da9739640d35cfac49fe7323d27378735c
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / modification / DeleteModificationTest.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.controller.sal.core.spi.data.DOMStoreWriteTransaction;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
14
15 public class DeleteModificationTest 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         // Delete stuff from the datastore
31         DOMStoreWriteTransaction deleteTransaction = store.newWriteOnlyTransaction();
32         DeleteModification deleteModification = new DeleteModification(TestModel.TEST_PATH);
33         deleteModification.apply(deleteTransaction);
34         commitTransaction(deleteTransaction);
35
36         data = readData(TestModel.TEST_PATH);
37         Assert.assertFalse(data.isPresent());
38     }
39
40     @Test
41     public void testSerialization() {
42         YangInstanceIdentifier path = TestModel.TEST_PATH;
43
44         DeleteModification expected = new DeleteModification(path);
45
46         DeleteModification clone = (DeleteModification) SerializationUtils.clone(expected);
47         assertEquals("getPath", expected.getPath(), clone.getPath());
48     }
49 }