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;
13 import java.util.concurrent.Future;
14 import org.junit.Test;
15 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
18 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
19 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
30 * covers creating, reading and deleting of an item in dataStore
32 public class DataServiceIT extends AbstractIT {
33 protected DataBrokerService consumerDataService;
37 * Ignored this, because classes here are constructed from
38 * very different class loader as MD-SAL is run into,
39 * this is code is run from different classloader.
44 public void test() throws Exception {
45 BindingAwareConsumer consumer = new BindingAwareConsumer() {
48 public void onSessionInitialized(final ConsumerContext session) {
49 consumerDataService = session.getSALService(DataBrokerService.class);
53 broker.registerConsumer(consumer);
55 assertNotNull(consumerDataService);
58 DataModificationTransaction transaction = consumerDataService.beginTransaction();
59 assertNotNull(transaction);
61 InstanceIdentifier<UnorderedList> node1 = createNodeRef("0");
62 DataObject node = consumerDataService.readOperationalData(node1);
64 UnorderedList nodeData1 = createNode("0");
66 transaction.putOperationalData(node1, nodeData1);
67 Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
68 assertNotNull(commitResult);
70 RpcResult<TransactionStatus> result = commitResult.get();
72 assertNotNull(result);
73 assertNotNull(result.getResult());
74 assertEquals(TransactionStatus.COMMITED, result.getResult());
76 UnorderedList readedData = (UnorderedList) consumerDataService.readOperationalData(node1);
77 assertNotNull(readedData);
78 assertEquals(nodeData1.getKey(), readedData.getKey());
80 DataModificationTransaction transaction2 = consumerDataService.beginTransaction();
81 assertNotNull(transaction2);
83 transaction2.removeOperationalData(node1);
85 Future<RpcResult<TransactionStatus>> commitResult2 = transaction2.commit();
86 assertNotNull(commitResult2);
88 RpcResult<TransactionStatus> result2 = commitResult2.get();
90 assertNotNull(result2);
91 assertNotNull(result2.getResult());
92 assertEquals(TransactionStatus.COMMITED, result2.getResult());
94 DataObject readedData2 = consumerDataService.readOperationalData(node1);
95 assertNull(readedData2);
99 private static InstanceIdentifier<UnorderedList> createNodeRef(final String string) {
100 UnorderedListKey key = new UnorderedListKey(string);
101 return InstanceIdentifier.builder(Lists.class).child(UnorderedContainer.class).child(UnorderedList.class, key).build();
104 private static UnorderedList createNode(final String string) {
105 UnorderedListBuilder ret = new UnorderedListBuilder();
106 UnorderedListKey nodeKey = new UnorderedListKey(string);
108 ret.setName("name of " + string);
109 ret.setName("value of " + string);