b504837d6780aa344eb706a786733b321a2fa65e
[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.AbstractDataBrokerTest;
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 AbstractDataBrokerTest {
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     @Test
37     public void test() throws InterruptedException, ExecutionException {
38         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
39         writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
40         writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
41         writeTx.submit().get();
42     }
43
44     @Test
45     public void testPutCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
46
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
61         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
62         writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
63         writeTx.submit().checkedGet();
64
65         ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
66         Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
67         assertTrue("Top node must exists after commit",topNode.isPresent());
68         Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
69         assertTrue("List node must exists after commit",listNode.isPresent());
70     }
71
72 }

©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.