AbstractConcurrentDataBrokerTest @deprecate-s the AbstractDataBrokerTest
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / WriteTransactionTest.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.md.sal.binding.impl.test;
9
10 import static org.junit.Assert.assertTrue;
11
12 import java.util.concurrent.ExecutionException;
13
14 import org.junit.Test;
15 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
16 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
17 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 import com.google.common.base.Optional;
28
29
30 public class WriteTransactionTest extends AbstractConcurrentDataBrokerTest {
31
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().setKey(TOP_LIST_KEY).build();
36
37     @Test
38     public void test() throws InterruptedException, ExecutionException {
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();
43     }
44
45     @Test
46     public void testPutCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
47         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
48         writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
49         writeTx.submit().checkedGet();
50
51         ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
52         Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
53         assertTrue("Top node must exists after commit",topNode.isPresent());
54         Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
55         assertTrue("List node must exists after commit",listNode.isPresent());
56     }
57
58     @Test
59     public void testMergeCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
60         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
61         writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
62         writeTx.submit().checkedGet();
63
64         ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
65         Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
66         assertTrue("Top node must exists after commit",topNode.isPresent());
67         Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
68         assertTrue("List node must exists after commit",listNode.isPresent());
69     }
70
71 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.