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;
7 import java.util.concurrent.Executors;
8 import java.util.concurrent.Future;
10 import org.junit.Before;
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;
14 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
15 import org.opendaylight.controller.sal.binding.impl.DataBrokerImpl;
16 import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndependentDataServiceConnector;
17 import org.opendaylight.controller.sal.binding.impl.connect.dom.MappingServiceImpl;
18 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
19 import org.opendaylight.controller.sal.dom.broker.impl.HashMapDataStore;
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 import com.google.common.util.concurrent.ListeningExecutorService;
31 import com.google.common.util.concurrent.MoreExecutors;
33 public class BrokerIntegrationTest {
35 DataBrokerService biDataService;
36 DataProviderService baDataService;
37 private MappingServiceImpl mappingServiceImpl;
38 private MappingServiceImpl mappingService;
39 private DataBrokerImpl baDataImpl;
40 private org.opendaylight.controller.sal.dom.broker.DataBrokerImpl biDataImpl;
41 private ListeningExecutorService executor;
42 private BindingIndependentDataServiceConnector connectorServiceImpl;
43 private HashMapDataStore dataStore;
48 executor = MoreExecutors.sameThreadExecutor();
49 baDataImpl = new DataBrokerImpl();
50 baDataService = baDataImpl;
51 baDataImpl.setExecutor(executor);
53 biDataImpl = new org.opendaylight.controller.sal.dom.broker.DataBrokerImpl();
54 biDataService = biDataImpl;
55 biDataImpl.setExecutor(executor);
57 dataStore = new HashMapDataStore();
58 org.opendaylight.yangtools.yang.data.api.InstanceIdentifier treeRoot = org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.builder().toInstance();
59 biDataImpl.registerConfigurationReader(treeRoot, dataStore);
60 biDataImpl.registerOperationalReader(treeRoot, dataStore);
61 biDataImpl.registerCommitHandler(treeRoot, dataStore);
63 mappingServiceImpl = new MappingServiceImpl();
64 mappingService = mappingServiceImpl;
67 connectorServiceImpl = new BindingIndependentDataServiceConnector();
68 connectorServiceImpl.setBaDataService(baDataService);
69 connectorServiceImpl.setBiDataService(biDataService);
70 connectorServiceImpl.setMappingService(mappingServiceImpl);
71 connectorServiceImpl.start();
73 String[] yangFiles = new String[] { "yang-ext.yang", "ietf-inet-types.yang", "ietf-yang-types.yang",
74 "node-inventory.yang" };
76 mappingService.onGlobalContextUpdated(MappingServiceTest.getContext(yangFiles));
80 public void simpleModifyOperation() throws Exception {
82 DataModificationTransaction transaction = baDataService.beginTransaction();
83 assertNotNull(transaction);
85 NodeRef node1 = createNodeRef("0");
86 DataObject node = baDataService.readConfigurationData(node1.getValue());
88 Node nodeData1 = createNode("0");
90 transaction.putConfigurationData(node1.getValue(), nodeData1);
91 Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
92 assertNotNull(commitResult);
94 RpcResult<TransactionStatus> result = commitResult.get();
96 assertNotNull(result);
97 assertNotNull(result.getResult());
98 assertEquals(TransactionStatus.COMMITED, result.getResult());
100 Node readedData = (Node) baDataService.readConfigurationData(node1.getValue());
101 assertNotNull(readedData);
102 assertEquals(nodeData1.getKey(), readedData.getKey());
105 DataModificationTransaction transaction2 = baDataService.beginTransaction();
106 assertNotNull(transaction);
108 transaction2.removeConfigurationData(node1.getValue());
110 Future<RpcResult<TransactionStatus>> commitResult2 = transaction2.commit();
111 assertNotNull(commitResult2);
113 RpcResult<TransactionStatus> result2 = commitResult2.get();
115 assertNotNull(result2);
116 assertNotNull(result2.getResult());
117 assertEquals(TransactionStatus.COMMITED, result2.getResult());
119 DataObject readedData2 = baDataService.readConfigurationData(node1.getValue());
120 assertNull(readedData2);
123 private static NodeRef createNodeRef(String string) {
124 NodeKey key = new NodeKey(new NodeId(string));
125 InstanceIdentifier<Node> path = InstanceIdentifier.builder().node(Nodes.class).node(Node.class, key)
127 return new NodeRef(path);
130 private static Node createNode(String string) {
131 NodeBuilder ret = new NodeBuilder();
132 ret.setId(new NodeId(string));
133 ret.setKey(new NodeKey(ret.getId()));