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
8 package org.opendaylight.controller.cluster.datastore.modification;
10 import static org.junit.Assert.assertEquals;
12 import java.util.Optional;
13 import org.apache.commons.lang.SerializationUtils;
14 import org.junit.Test;
15 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
16 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
20 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
22 public class WriteModificationTest extends AbstractModificationTest {
24 public void testApply() throws Exception {
25 //Write something into the datastore
26 DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
27 WriteModification writeModification = new WriteModification(TestModel.TEST_PATH, TEST_CONTAINER);
28 writeModification.apply(writeTransaction);
29 commitTransaction(writeTransaction);
31 //Check if it's in the datastore
32 assertEquals(Optional.of(TEST_CONTAINER), readData(TestModel.TEST_PATH));
36 public void testSerialization() {
37 YangInstanceIdentifier path = TestModel.TEST_PATH;
38 NormalizedNode data = ImmutableContainerNodeBuilder.create()
39 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
40 .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
42 WriteModification expected = new WriteModification(path, data);
44 WriteModification clone = (WriteModification) SerializationUtils.clone(expected);
45 assertEquals("getPath", expected.getPath(), clone.getPath());
46 assertEquals("getData", expected.getData(), clone.getData());