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.controller.sal.binding.test.connect.dom;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
14 import java.util.concurrent.Future;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
18 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
19 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
30 // FIXME: Migrate to use new Data Broker APIs
31 @SuppressWarnings("deprecation")
32 public class BrokerIntegrationTest extends AbstractDataServiceTest {
35 public void simpleModifyOperation() throws Exception {
37 NodeRef node1 = createNodeRef("0");
38 DataObject node = baDataService.readConfigurationData(node1.getValue());
40 Node nodeData1 = createNode("0");
42 DataModificationTransaction transaction = baDataService.beginTransaction();
43 transaction.putConfigurationData(node1.getValue(), nodeData1);
44 Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
45 assertNotNull(commitResult);
47 RpcResult<TransactionStatus> result = commitResult.get();
49 assertNotNull(result);
50 assertNotNull(result.getResult());
51 assertEquals(TransactionStatus.COMMITED, result.getResult());
53 Node readedData = (Node) baDataService.readConfigurationData(node1.getValue());
54 assertNotNull(readedData);
55 assertEquals(nodeData1.getKey(), readedData.getKey());
57 NodeRef nodeFoo = createNodeRef("foo");
58 NodeRef nodeBar = createNodeRef("bar");
59 Node nodeFooData = createNode("foo");
60 Node nodeBarData = createNode("bar");
62 DataModificationTransaction insertMoreTr = baDataService.beginTransaction();
63 insertMoreTr.putConfigurationData(nodeFoo.getValue(), nodeFooData);
64 insertMoreTr.putConfigurationData(nodeBar.getValue(), nodeBarData);
65 RpcResult<TransactionStatus> result2 = insertMoreTr.commit().get();
67 assertNotNull(result2);
68 assertNotNull(result2.getResult());
69 assertEquals(TransactionStatus.COMMITED, result.getResult());
71 Nodes allNodes = (Nodes) baDataService.readConfigurationData(InstanceIdentifier.builder(Nodes.class)
73 assertNotNull(allNodes);
74 assertNotNull(allNodes.getNode());
75 assertEquals(3, allNodes.getNode().size());
78 * We create transaction no 2
81 DataModificationTransaction removalTransaction = baDataService.beginTransaction();
82 assertNotNull(transaction);
88 removalTransaction.removeConfigurationData(node1.getValue());
91 * We commit transaction
93 Future<RpcResult<TransactionStatus>> commitResult2 = removalTransaction.commit();
94 assertNotNull(commitResult2);
96 RpcResult<TransactionStatus> result3 = commitResult2.get();
98 assertNotNull(result3);
99 assertNotNull(result3.getResult());
100 assertEquals(TransactionStatus.COMMITED, result2.getResult());
102 DataObject readedData2 = baDataService.readConfigurationData(node1.getValue());
103 assertNull(readedData2);
106 private static NodeRef createNodeRef(final String string) {
107 NodeKey key = new NodeKey(new NodeId(string));
108 InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
110 return new NodeRef(path);
113 private static Node createNode(final String string) {
114 NodeBuilder ret = new NodeBuilder();
115 ret.setId(new NodeId(string));
116 ret.setKey(new NodeKey(ret.getId()));