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.mdsal.binding.dom.adapter.test;
10 import static org.junit.Assert.assertTrue;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
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;
28 public class WriteTransactionTest extends AbstractDataBrokerTest {
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();
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();
43 public void testPutCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
45 final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
46 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
47 writeTx.submit().checkedGet();
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());
57 public void testMergeCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
59 final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
60 writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
61 writeTx.submit().checkedGet();
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());