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.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;
24 public class MergeModificationTest extends AbstractModificationTest {
27 public void testApply() throws Exception {
28 //TODO : Need to write a better test for this
30 //Write something into the datastore
31 DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
32 MergeModification writeModification = new MergeModification(TestModel.TEST_PATH,
33 ImmutableNodes.containerNode(TestModel.TEST_QNAME));
34 writeModification.apply(writeTransaction);
35 commitTransaction(writeTransaction);
37 //Check if it's in the datastore
38 Optional<NormalizedNode> data = readData(TestModel.TEST_PATH);
39 Assert.assertTrue(data.isPresent());
44 public void testSerialization() {
45 YangInstanceIdentifier path = TestModel.TEST_PATH;
46 NormalizedNode data = ImmutableContainerNodeBuilder.create()
47 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
48 .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
50 MergeModification expected = new MergeModification(path, data);
52 MergeModification clone = (MergeModification) SerializationUtils.clone(expected);
53 assertEquals("getPath", expected.getPath(), clone.getPath());
54 assertEquals("getData", expected.getData(), clone.getData());