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.test.sal.binding.it;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
14 import com.google.inject.Inject;
15 import java.util.concurrent.Future;
16 import org.junit.Before;
17 import org.junit.Ignore;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
22 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
23 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
24 import org.opendaylight.controller.sal.core.api.Broker;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
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 DataServiceTest extends AbstractTest {
36 protected DataBrokerService consumerDataService;
43 public void setUp() throws Exception {
48 * Ignored this, because classes here are constructed from
49 * very different class loader as MD-SAL is run into,
50 * this is code is run from different classloader.
55 public void test() throws Exception {
56 BindingAwareConsumer consumer1 = new BindingAwareConsumer() {
59 public void onSessionInitialized(final ConsumerContext session) {
60 consumerDataService = session.getSALService(DataBrokerService.class);
63 broker.registerConsumer(consumer1, getBundleContext());
65 assertNotNull(consumerDataService);
68 DataModificationTransaction transaction = consumerDataService.beginTransaction();
69 assertNotNull(transaction);
71 InstanceIdentifier<Node> node1 = createNodeRef("0");
72 DataObject node = consumerDataService.readConfigurationData(node1);
74 Node nodeData1 = createNode("0");
76 transaction.putConfigurationData(node1, nodeData1);
77 Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
78 assertNotNull(commitResult);
80 RpcResult<TransactionStatus> result = commitResult.get();
82 assertNotNull(result);
83 assertNotNull(result.getResult());
84 assertEquals(TransactionStatus.COMMITED, result.getResult());
86 Node readedData = (Node) consumerDataService.readConfigurationData(node1);
87 assertNotNull(readedData);
88 assertEquals(nodeData1.getKey(), readedData.getKey());
91 DataModificationTransaction transaction2 = consumerDataService.beginTransaction();
92 assertNotNull(transaction);
94 transaction2.removeConfigurationData(node1);
96 Future<RpcResult<TransactionStatus>> commitResult2 = transaction2.commit();
97 assertNotNull(commitResult2);
99 RpcResult<TransactionStatus> result2 = commitResult2.get();
101 assertNotNull(result2);
102 assertNotNull(result2.getResult());
103 assertEquals(TransactionStatus.COMMITED, result2.getResult());
105 DataObject readedData2 = consumerDataService.readConfigurationData(node1);
106 assertNull(readedData2);
112 private static InstanceIdentifier<Node> createNodeRef(final String string) {
113 NodeKey key = new NodeKey(new NodeId(string));
114 return InstanceIdentifier.builder(Nodes.class).child(Node.class, key).build();
117 private static Node createNode(final String string) {
118 NodeBuilder ret = new NodeBuilder();
119 NodeId id = new NodeId(string);
120 ret.setKey(new NodeKey(id));