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