Fix license header violations in sal-distributed-datastore
[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
9 package org.opendaylight.controller.cluster.datastore.modification;
10
11 import static org.junit.Assert.assertEquals;
12 import com.google.common.base.Optional;
13 import org.apache.commons.lang.SerializationUtils;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
22
23 public class DeleteModificationTest extends AbstractModificationTest {
24
25     @Test
26     public void testApply() throws Exception {
27         // Write something into the datastore
28         DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
29         WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
30                 ImmutableNodes.containerNode(TestModel.TEST_QNAME));
31         writeModification.apply(writeTransaction);
32         commitTransaction(writeTransaction);
33
34         // Check if it's in the datastore
35         Optional<NormalizedNode<?, ?>> data = readData(TestModel.TEST_PATH);
36         Assert.assertTrue(data.isPresent());
37
38         // Delete stuff from the datastore
39         DOMStoreWriteTransaction deleteTransaction = store.newWriteOnlyTransaction();
40         DeleteModification deleteModification = new DeleteModification(TestModel.TEST_PATH);
41         deleteModification.apply(deleteTransaction);
42         commitTransaction(deleteTransaction);
43
44         data = readData(TestModel.TEST_PATH);
45         Assert.assertFalse(data.isPresent());
46     }
47
48     @Test
49     public void testSerialization() {
50         YangInstanceIdentifier path = TestModel.TEST_PATH;
51
52         DeleteModification expected = new DeleteModification(path);
53
54         DeleteModification clone = (DeleteModification) SerializationUtils.clone(expected);
55         assertEquals("getPath", expected.getPath(), clone.getPath());
56     }
57 }