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;
29 public class WriteTransactionTest extends AbstractConcurrentDataBrokerTest {
31 private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
32 private static final TopLevelListKey TOP_LIST_KEY = new TopLevelListKey("foo");
33 private static final InstanceIdentifier<TopLevelList> NODE_PATH = TOP_PATH.child(TopLevelList.class, TOP_LIST_KEY);
34 private static final TopLevelList NODE = new TopLevelListBuilder().setKey(TOP_LIST_KEY).build();
38 public void testSubmit() throws InterruptedException, ExecutionException, TimeoutException {
39 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
40 writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
41 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
42 writeTx.submit().get(5, TimeUnit.SECONDS);
44 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
45 Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
46 assertTrue("List node must exists after commit", listNode.isPresent());
47 assertEquals("List node", NODE, listNode.get());
51 public void testCommit() throws InterruptedException, ExecutionException, TimeoutException {
52 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
53 writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
54 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
55 writeTx.commit().get(5, TimeUnit.SECONDS);
57 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
58 Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
59 assertTrue("List node must exists after commit", listNode.isPresent());
60 assertEquals("List node", NODE, listNode.get());
64 public void testPutCreateParentsSuccess() throws InterruptedException, ExecutionException, TimeoutException {
65 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
66 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
67 writeTx.commit().get(5, TimeUnit.SECONDS);
69 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
70 Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
71 assertTrue("Top node must exists after commit",topNode.isPresent());
72 Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
73 assertTrue("List node must exists after commit",listNode.isPresent());
77 public void testMergeCreateParentsSuccess() throws InterruptedException, ExecutionException, TimeoutException {
78 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
79 writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
80 writeTx.commit().get(5, TimeUnit.SECONDS);
82 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
83 Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
84 assertTrue("Top node must exists after commit",topNode.isPresent());
85 Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
86 assertTrue("List node must exists after commit",listNode.isPresent());