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.BindingAwareConsumer;
17 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
18 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.common.RpcResult;
29 * covers creating, reading and deleting of an item in dataStore
31 public class DataServiceIT extends AbstractIT {
32 protected DataBrokerService consumerDataService;
36 * Ignored this, because classes here are constructed from
37 * very different class loader as MD-SAL is run into,
38 * this is code is run from different classloader.
43 public void test() throws Exception {
44 BindingAwareConsumer consumer = session -> consumerDataService = session.getSALService(DataBrokerService.class);
46 broker.registerConsumer(consumer);
48 assertNotNull(consumerDataService);
51 DataModificationTransaction transaction = consumerDataService.beginTransaction();
52 assertNotNull(transaction);
54 InstanceIdentifier<UnorderedList> node1 = createNodeRef("0");
55 DataObject node = consumerDataService.readOperationalData(node1);
57 UnorderedList nodeData1 = createNode("0");
59 transaction.putOperationalData(node1, nodeData1);
60 Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
61 assertNotNull(commitResult);
63 RpcResult<TransactionStatus> result = commitResult.get();
65 assertNotNull(result);
66 assertNotNull(result.getResult());
67 assertEquals(TransactionStatus.COMMITED, result.getResult());
69 UnorderedList readedData = (UnorderedList) consumerDataService.readOperationalData(node1);
70 assertNotNull(readedData);
71 assertEquals(nodeData1.getKey(), readedData.getKey());
73 DataModificationTransaction transaction2 = consumerDataService.beginTransaction();
74 assertNotNull(transaction2);
76 transaction2.removeOperationalData(node1);
78 Future<RpcResult<TransactionStatus>> commitResult2 = transaction2.commit();
79 assertNotNull(commitResult2);
81 RpcResult<TransactionStatus> result2 = commitResult2.get();
83 assertNotNull(result2);
84 assertNotNull(result2.getResult());
85 assertEquals(TransactionStatus.COMMITED, result2.getResult());
87 DataObject readedData2 = consumerDataService.readOperationalData(node1);
88 assertNull(readedData2);
92 private static InstanceIdentifier<UnorderedList> createNodeRef(final String string) {
93 UnorderedListKey key = new UnorderedListKey(string);
94 return InstanceIdentifier.builder(Lists.class).child(UnorderedContainer.class).child(UnorderedList.class, key).build();
97 private static UnorderedList createNode(final String string) {
98 UnorderedListBuilder ret = new UnorderedListBuilder();
99 UnorderedListKey nodeKey = new UnorderedListKey(string);
101 ret.setName("name of " + string);
102 ret.setName("value of " + string);