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;
11 import com.google.common.base.Optional;
12 import java.util.concurrent.ExecutionException;
13 import org.junit.Test;
14 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TopBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 public class WriteTransactionTest extends AbstractDataBrokerTest {
28 private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
29 private static final TopLevelListKey TOP_LIST_KEY = new TopLevelListKey("foo");
30 private static final InstanceIdentifier<TopLevelList> NODE_PATH = TOP_PATH.child(TopLevelList.class, TOP_LIST_KEY);
31 private static final TopLevelList NODE = new TopLevelListBuilder().setKey(TOP_LIST_KEY).build();
33 public void test() throws InterruptedException, ExecutionException {
34 final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
35 writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
36 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
37 writeTx.submit().get();
41 public void testPutCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
43 final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
44 writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
45 writeTx.submit().checkedGet();
47 final ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
48 final Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
49 assertTrue("Top node must exists after commit",topNode.isPresent());
50 final Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
51 assertTrue("List node must exists after commit",listNode.isPresent());
55 public void testMergeCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
57 final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
58 writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
59 writeTx.submit().checkedGet();
61 final ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
62 final Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
63 assertTrue("Top node must exists after commit",topNode.isPresent());
64 final Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
65 assertTrue("List node must exists after commit",listNode.isPresent());