Remove deprecation suppression
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / connect / dom / BrokerIntegrationTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.binding.test.connect.dom;
9
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.data.DataModificationTransaction;
17 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25
26 public class BrokerIntegrationTest extends AbstractDataServiceTest {
27
28     private static final TopLevelListKey TLL_FOO_KEY = new TopLevelListKey("foo");
29     private static final TopLevelListKey TLL_BAR_KEY = new TopLevelListKey("bar");
30     private static final TopLevelListKey TLL_BAZ_KEY = new TopLevelListKey("baz");
31     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.builder(Top.class).build();
32     private static final InstanceIdentifier<TopLevelList> FOO_PATH = TOP_PATH.child(TopLevelList.class, TLL_FOO_KEY);
33     private static final InstanceIdentifier<TopLevelList> BAR_PATH = TOP_PATH.child(TopLevelList.class, TLL_BAR_KEY);
34     private static final InstanceIdentifier<TopLevelList> BAZ_PATH = TOP_PATH.child(TopLevelList.class, TLL_BAZ_KEY);
35
36     @Test
37     public void simpleModifyOperation() throws Exception {
38
39         DataObject tllFoo = baDataService.readConfigurationData(FOO_PATH);
40         assertNull(tllFoo);
41         TopLevelList tllFooData = createTll(TLL_FOO_KEY);
42
43         DataModificationTransaction transaction = baDataService.beginTransaction();
44         transaction.putConfigurationData(FOO_PATH, tllFooData);
45         Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
46         assertNotNull(commitResult);
47
48         RpcResult<TransactionStatus> result = commitResult.get();
49
50         assertNotNull(result);
51         assertNotNull(result.getResult());
52         assertEquals(TransactionStatus.COMMITED, result.getResult());
53
54         TopLevelList readedData = (TopLevelList) baDataService.readConfigurationData(FOO_PATH);
55         assertNotNull(readedData);
56         assertEquals(tllFooData.getKey(), readedData.getKey());
57
58         TopLevelList nodeBarData = createTll(TLL_BAR_KEY);
59         TopLevelList nodeBazData = createTll(TLL_BAZ_KEY);
60
61         DataModificationTransaction insertMoreTr = baDataService.beginTransaction();
62         insertMoreTr.putConfigurationData(BAR_PATH, nodeBarData);
63         insertMoreTr.putConfigurationData(BAZ_PATH, nodeBazData);
64         RpcResult<TransactionStatus> result2 = insertMoreTr.commit().get();
65
66         assertNotNull(result2);
67         assertNotNull(result2.getResult());
68         assertEquals(TransactionStatus.COMMITED, result.getResult());
69
70         Top top = (Top) baDataService.readConfigurationData(TOP_PATH);
71         assertNotNull(top);
72         assertNotNull(top.getTopLevelList());
73         assertEquals(3, top.getTopLevelList().size());
74
75         /**
76          * We create transaction no 2
77          *
78          */
79         DataModificationTransaction removalTransaction = baDataService.beginTransaction();
80         assertNotNull(transaction);
81
82         /**
83          * We remove node 1
84          *
85          */
86         removalTransaction.removeConfigurationData(BAR_PATH);
87
88         /**
89          * We commit transaction
90          */
91         Future<RpcResult<TransactionStatus>> commitResult2 = removalTransaction.commit();
92         assertNotNull(commitResult2);
93
94         RpcResult<TransactionStatus> result3 = commitResult2.get();
95
96         assertNotNull(result3);
97         assertNotNull(result3.getResult());
98         assertEquals(TransactionStatus.COMMITED, result2.getResult());
99
100         DataObject readedData2 = baDataService.readConfigurationData(BAR_PATH);
101         assertNull(readedData2);
102     }
103
104     private static TopLevelList createTll(final TopLevelListKey key) {
105         TopLevelListBuilder ret = new TopLevelListBuilder();
106         ret.setKey(key);
107         return ret.build();
108     }
109 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.