1 package org.opendaylight.controller.sal.binding.test.connect.dom;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertNull;
8 import java.util.concurrent.Future;
11 import org.junit.Test;
12 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
13 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
15 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
27 public class BrokerIntegrationTest extends AbstractDataServiceTest {
30 public void simpleModifyOperation() throws Exception {
32 NodeRef node1 = createNodeRef("0");
33 DataObject node = baDataService.readConfigurationData(node1.getValue());
35 Node nodeData1 = createNode("0");
37 DataModificationTransaction transaction = baDataService.beginTransaction();
38 transaction.putConfigurationData(node1.getValue(), nodeData1);
39 Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
40 assertNotNull(commitResult);
42 RpcResult<TransactionStatus> result = commitResult.get();
44 assertNotNull(result);
45 assertNotNull(result.getResult());
46 assertEquals(TransactionStatus.COMMITED, result.getResult());
48 Node readedData = (Node) baDataService.readConfigurationData(node1.getValue());
49 assertNotNull(readedData);
50 assertEquals(nodeData1.getKey(), readedData.getKey());
52 NodeRef nodeFoo = createNodeRef("foo");
53 NodeRef nodeBar = createNodeRef("bar");
54 Node nodeFooData = createNode("foo");
55 Node nodeBarData = createNode("bar");
57 DataModificationTransaction insertMoreTr = baDataService.beginTransaction();
58 insertMoreTr.putConfigurationData(nodeFoo.getValue(), nodeFooData);
59 insertMoreTr.putConfigurationData(nodeBar.getValue(), nodeBarData);
60 RpcResult<TransactionStatus> result2 = insertMoreTr.commit().get();
62 assertNotNull(result2);
63 assertNotNull(result2.getResult());
64 assertEquals(TransactionStatus.COMMITED, result.getResult());
66 Nodes allNodes = (Nodes) baDataService.readConfigurationData(InstanceIdentifier.builder(Nodes.class)
68 assertNotNull(allNodes);
69 assertNotNull(allNodes.getNode());
70 assertEquals(3, allNodes.getNode().size());
73 * We create transaction no 2
76 DataModificationTransaction removalTransaction = baDataService.beginTransaction();
77 assertNotNull(transaction);
83 removalTransaction.removeConfigurationData(node1.getValue());
86 * We commit transaction
88 Future<RpcResult<TransactionStatus>> commitResult2 = removalTransaction.commit();
89 assertNotNull(commitResult2);
91 RpcResult<TransactionStatus> result3 = commitResult2.get();
93 assertNotNull(result3);
94 assertNotNull(result3.getResult());
95 assertEquals(TransactionStatus.COMMITED, result2.getResult());
97 DataObject readedData2 = baDataService.readConfigurationData(node1.getValue());
98 assertNull(readedData2);
101 private static NodeRef createNodeRef(String string) {
102 NodeKey key = new NodeKey(new NodeId(string));
103 InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
105 return new NodeRef(path);
108 private static Node createNode(String string) {
109 NodeBuilder ret = new NodeBuilder();
110 ret.setId(new NodeId(string));
111 ret.setKey(new NodeKey(ret.getId()));