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