Do not use MoreExecutors.sameThreadExecutor()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / modification / MergeModificationTest.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.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
21 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
22
23 public class MergeModificationTest extends AbstractModificationTest{
24
25     @Test
26     public void testApply() throws Exception {
27         //TODO : Need to write a better test for this
28
29         //Write something into the datastore
30         DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
31         MergeModification writeModification = new MergeModification(TestModel.TEST_PATH,
32                 ImmutableNodes.containerNode(TestModel.TEST_QNAME));
33         writeModification.apply(writeTransaction);
34         commitTransaction(writeTransaction);
35
36         //Check if it's in the datastore
37         Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
38         Assert.assertTrue(data.isPresent());
39
40     }
41
42     @Test
43     public void testSerialization() {
44         YangInstanceIdentifier path = TestModel.TEST_PATH;
45         NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
46                 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
47                 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
48
49         MergeModification expected = new MergeModification(path, data);
50
51         MergeModification clone = (MergeModification) SerializationUtils.clone(expected);
52         assertEquals("getPath", expected.getPath(), clone.getPath());
53         assertEquals("getData", expected.getData(), clone.getData());
54     }
55 }