Fix unit test CS warnings in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / modification / WriteModificationTest.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
13 import com.google.common.base.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.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
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 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
23
24 public class WriteModificationTest extends AbstractModificationTest {
25
26     @Test
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);
34
35         //Check if it's in the datastore
36         Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
37         Assert.assertTrue(data.isPresent());
38     }
39
40     @Test
41     public void testSerialization() {
42         YangInstanceIdentifier path = TestModel.TEST_PATH;
43         NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create()
44                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
45                 .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
46
47         WriteModification expected = new WriteModification(path, data);
48
49         WriteModification clone = (WriteModification) SerializationUtils.clone(expected);
50         assertEquals("getPath", expected.getPath(), clone.getPath());
51         assertEquals("getData", expected.getData(), clone.getData());
52     }
53 }