2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore.modification;
11 import static org.junit.Assert.assertEquals;
13 import java.util.Optional;
14 import org.apache.commons.lang.SerializationUtils;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
18 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
19 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
24 public class DeleteModificationTest extends AbstractModificationTest {
27 public void testApply() throws Exception {
28 // Write something into the datastore
29 DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
30 WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
31 ImmutableNodes.containerNode(TestModel.TEST_QNAME));
32 writeModification.apply(writeTransaction);
33 commitTransaction(writeTransaction);
35 // Check if it's in the datastore
36 Optional<NormalizedNode> data = readData(TestModel.TEST_PATH);
37 Assert.assertTrue(data.isPresent());
39 // Delete stuff from the datastore
40 DOMStoreWriteTransaction deleteTransaction = store.newWriteOnlyTransaction();
41 DeleteModification deleteModification = new DeleteModification(TestModel.TEST_PATH);
42 deleteModification.apply(deleteTransaction);
43 commitTransaction(deleteTransaction);
45 data = readData(TestModel.TEST_PATH);
46 Assert.assertFalse(data.isPresent());
50 public void testSerialization() {
51 YangInstanceIdentifier path = TestModel.TEST_PATH;
53 DeleteModification expected = new DeleteModification(path);
55 DeleteModification clone = (DeleteModification) SerializationUtils.clone(expected);
56 assertEquals("getPath", expected.getPath(), clone.getPath());