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;
15 import java.util.concurrent.Future;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
20 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
22 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
30 import org.opendaylight.yangtools.yang.binding.DataObject;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
34 public class BrokerIntegrationTest extends AbstractDataServiceTest {
37 public void simpleModifyOperation() throws Exception {
39 NodeRef node1 = createNodeRef("0");
40 DataObject node = baDataService.readConfigurationData(node1.getValue());
42 Node nodeData1 = createNode("0");
44 DataModificationTransaction transaction = baDataService.beginTransaction();
45 transaction.putConfigurationData(node1.getValue(), nodeData1);
46 Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
47 assertNotNull(commitResult);
49 RpcResult<TransactionStatus> result = commitResult.get();
51 assertNotNull(result);
52 assertNotNull(result.getResult());
53 assertEquals(TransactionStatus.COMMITED, result.getResult());
55 Node readedData = (Node) baDataService.readConfigurationData(node1.getValue());
56 assertNotNull(readedData);
57 assertEquals(nodeData1.getKey(), readedData.getKey());
59 NodeRef nodeFoo = createNodeRef("foo");
60 NodeRef nodeBar = createNodeRef("bar");
61 Node nodeFooData = createNode("foo");
62 Node nodeBarData = createNode("bar");
64 DataModificationTransaction insertMoreTr = baDataService.beginTransaction();
65 insertMoreTr.putConfigurationData(nodeFoo.getValue(), nodeFooData);
66 insertMoreTr.putConfigurationData(nodeBar.getValue(), nodeBarData);
67 RpcResult<TransactionStatus> result2 = insertMoreTr.commit().get();
69 assertNotNull(result2);
70 assertNotNull(result2.getResult());
71 assertEquals(TransactionStatus.COMMITED, result.getResult());
73 Nodes allNodes = (Nodes) baDataService.readConfigurationData(InstanceIdentifier.builder(Nodes.class)
75 assertNotNull(allNodes);
76 assertNotNull(allNodes.getNode());
77 assertEquals(3, allNodes.getNode().size());
80 * We create transaction no 2
83 DataModificationTransaction removalTransaction = baDataService.beginTransaction();
84 assertNotNull(transaction);
90 removalTransaction.removeConfigurationData(node1.getValue());
93 * We commit transaction
95 Future<RpcResult<TransactionStatus>> commitResult2 = removalTransaction.commit();
96 assertNotNull(commitResult2);
98 RpcResult<TransactionStatus> result3 = commitResult2.get();
100 assertNotNull(result3);
101 assertNotNull(result3.getResult());
102 assertEquals(TransactionStatus.COMMITED, result2.getResult());
104 DataObject readedData2 = baDataService.readConfigurationData(node1.getValue());
105 assertNull(readedData2);
108 private static NodeRef createNodeRef(String string) {
109 NodeKey key = new NodeKey(new NodeId(string));
110 InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, key)
112 return new NodeRef(path);
115 private static Node createNode(String string) {
116 NodeBuilder ret = new NodeBuilder();
117 ret.setId(new NodeId(string));
118 ret.setKey(new NodeKey(ret.getId()));