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 javax.inject.Inject;
15 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.BindingAwareBroker.ConsumerContext;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
20 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
21 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
22 import org.opendaylight.controller.sal.core.api.Broker;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey;
28 import org.opendaylight.yangtools.yang.binding.DataObject;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
33 * covers creating, reading and deleting of an item in dataStore
35 public class DataServiceIT extends AbstractIT {
37 protected DataBrokerService consumerDataService;
44 * Ignored this, because classes here are constructed from
45 * very different class loader as MD-SAL is run into,
46 * this is code is run from different classloader.
51 public void test() throws Exception {
52 BindingAwareConsumer consumer1 = new BindingAwareConsumer() {
55 public void onSessionInitialized(final ConsumerContext session) {
56 consumerDataService = session.getSALService(DataBrokerService.class);
59 broker.registerConsumer(consumer1);
61 assertNotNull(consumerDataService);
64 DataModificationTransaction transaction = consumerDataService.beginTransaction();
65 assertNotNull(transaction);
67 InstanceIdentifier<UnorderedList> node1 = createNodeRef("0");
68 DataObject node = consumerDataService.readConfigurationData(node1);
70 UnorderedList nodeData1 = createNode("0");
72 transaction.putConfigurationData(node1, nodeData1);
73 Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
74 assertNotNull(commitResult);
76 RpcResult<TransactionStatus> result = commitResult.get();
78 assertNotNull(result);
79 assertNotNull(result.getResult());
80 assertEquals(TransactionStatus.COMMITED, result.getResult());
82 UnorderedList readedData = (UnorderedList) consumerDataService.readConfigurationData(node1);
83 assertNotNull(readedData);
84 assertEquals(nodeData1.getKey(), readedData.getKey());
86 DataModificationTransaction transaction2 = consumerDataService.beginTransaction();
87 assertNotNull(transaction2);
89 transaction2.removeConfigurationData(node1);
91 Future<RpcResult<TransactionStatus>> commitResult2 = transaction2.commit();
92 assertNotNull(commitResult2);
94 RpcResult<TransactionStatus> result2 = commitResult2.get();
96 assertNotNull(result2);
97 assertNotNull(result2.getResult());
98 assertEquals(TransactionStatus.COMMITED, result2.getResult());
100 DataObject readedData2 = consumerDataService.readConfigurationData(node1);
101 assertNull(readedData2);
105 private static InstanceIdentifier<UnorderedList> createNodeRef(final String string) {
106 UnorderedListKey key = new UnorderedListKey(string);
107 return InstanceIdentifier.builder(Lists.class).child(UnorderedContainer.class).child(UnorderedList.class, key).build();
110 private static UnorderedList createNode(final String string) {
111 UnorderedListBuilder ret = new UnorderedListBuilder();
112 UnorderedListKey nodeKey = new UnorderedListKey(string);
114 ret.setName("name of " + string);
115 ret.setName("value of " + string);