Clean up modification tests
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / modification / DeleteModificationTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.modification;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.util.Optional;
13 import org.apache.commons.lang.SerializationUtils;
14 import org.junit.Test;
15 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
16 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
17 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19
20 public class DeleteModificationTest extends AbstractModificationTest {
21     @Test
22     public void testApply() throws Exception {
23         // Write something into the datastore
24         DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
25         WriteModification writeModification = new WriteModification(TestModel.TEST_PATH, TEST_CONTAINER);
26         writeModification.apply(writeTransaction);
27         commitTransaction(writeTransaction);
28
29         // Check if it's in the datastore
30         assertEquals(Optional.of(TEST_CONTAINER), readData(TestModel.TEST_PATH));
31
32         // Delete stuff from the datastore
33         DOMStoreWriteTransaction deleteTransaction = store.newWriteOnlyTransaction();
34         DeleteModification deleteModification = new DeleteModification(TestModel.TEST_PATH);
35         deleteModification.apply(deleteTransaction);
36         commitTransaction(deleteTransaction);
37
38         assertEquals(Optional.empty(), readData(TestModel.TEST_PATH));
39     }
40
41     @Test
42     public void testSerialization() {
43         YangInstanceIdentifier path = TestModel.TEST_PATH;
44
45         DeleteModification expected = new DeleteModification(path);
46
47         DeleteModification clone = (DeleteModification) SerializationUtils.clone(expected);
48         assertEquals("getPath", expected.getPath(), clone.getPath());
49     }
50 }