2 * Copyright (c) 2014 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.md.sal.binding.impl.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import com.google.common.base.Optional;
14 import java.util.concurrent.ExecutionException;
15 import java.util.concurrent.TimeUnit;
16 import java.util.concurrent.TimeoutException;
17 import org.junit.Test;
18 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
19 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
20 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 public class WriteTransactionTest extends AbstractConcurrentDataBrokerTest {
32 private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
33 private static final TopLevelListKey TOP_LIST_KEY = new TopLevelListKey("foo");
34 private static final InstanceIdentifier<TopLevelList> NODE_PATH = TOP_PATH.child(TopLevelList.class, TOP_LIST_KEY);
35 private static final TopLevelList NODE = new TopLevelListBuilder().withKey(TOP_LIST_KEY).build();
39 public void testSubmit() throws InterruptedException, ExecutionException, TimeoutException {
40 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
41 writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
42 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
43 writeTx.submit().get(5, TimeUnit.SECONDS);
45 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
46 Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
47 assertTrue("List node must exists after commit", listNode.isPresent());
48 assertEquals("List node", NODE, listNode.get());
52 public void testCommit() throws InterruptedException, ExecutionException, TimeoutException {
53 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
54 writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
55 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
56 writeTx.commit().get(5, TimeUnit.SECONDS);
58 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
59 Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
60 assertTrue("List node must exists after commit", listNode.isPresent());
61 assertEquals("List node", NODE, listNode.get());
65 public void testPutCreateParentsSuccess() throws InterruptedException, ExecutionException, TimeoutException {
66 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
67 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
68 writeTx.commit().get(5, TimeUnit.SECONDS);
70 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
71 Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
72 assertTrue("Top node must exists after commit",topNode.isPresent());
73 Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
74 assertTrue("List node must exists after commit",listNode.isPresent());
78 public void testMergeCreateParentsSuccess() throws InterruptedException, ExecutionException, TimeoutException {
79 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
80 writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
81 writeTx.commit().get(5, TimeUnit.SECONDS);
83 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
84 Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
85 assertTrue("Top node must exists after commit",topNode.isPresent());
86 Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
87 assertTrue("List node must exists after commit",listNode.isPresent());