Remove deprecation suppression
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / connect / dom / CrossBrokerMountPointTest.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 com.google.common.base.Optional;
13 import com.google.common.util.concurrent.CheckedFuture;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.MoreExecutors;
17 import java.util.Collections;
18 import java.util.Map;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
24 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
25 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
26 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
27 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
28 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
29 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
30 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
31 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
32 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
33 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
34 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
35 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
36 import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory;
37 import org.opendaylight.controller.sal.binding.test.util.BindingTestContext;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.List11SimpleAugment;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Key;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Key;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.top.top.level.list.list1.list1._1.Cont;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
48 import org.opendaylight.yangtools.concepts.ListenerRegistration;
49 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
50 import org.opendaylight.yangtools.yang.common.QName;
51 import org.opendaylight.yangtools.yang.common.RpcResult;
52 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
53 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
54 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
55 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
56 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
57 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
58
59 public class CrossBrokerMountPointTest {
60
61     private static final QName TLL_NAME_QNAME = QName.create(TopLevelList.QNAME, "name");
62     private static final String TLL_NAME = "foo:1";
63
64     private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
65
66     private static final Map<QName, Object> TLL_KEY_BI = Collections.<QName, Object> singletonMap(TLL_NAME_QNAME,
67             TLL_NAME);
68
69     private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) //
70             .child(TopLevelList.class, TLL_KEY).build();
71
72     private static final List1Key LIST1_KEY = new List1Key("foo");
73     private static final List11Key LIST11_KEY = new List11Key(1);
74
75     private static final InstanceIdentifier<Cont> AUG_CONT_ID_BA = TLL_INSTANCE_ID_BA
76             .builder().augmentation(TllComplexAugment.class) //
77             .child(List1.class, LIST1_KEY) //
78             .child(List11.class, LIST11_KEY) //
79             .augmentation(List11SimpleAugment.class) //
80             .child(Cont.class) //
81             .build();
82
83     private static final QName AUG_CONT = QName.create(List11.QNAME,
84             Cont.QNAME.getLocalName());
85
86     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier TLL_INSTANCE_ID_BI = //
87     org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder() //
88             .node(Top.QNAME) //
89             .node(TopLevelList.QNAME) //
90             .nodeWithKey(TopLevelList.QNAME, TLL_KEY_BI) //
91             .build();
92
93     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier GROUP_STATISTICS_ID_BI = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
94             //
95             .builder(TLL_INSTANCE_ID_BI)
96             .nodeWithKey(QName.create(TllComplexAugment.QNAME, "list1"), QName.create(TllComplexAugment.QNAME, "attr-str"),
97                     LIST1_KEY.getAttrStr())
98             .nodeWithKey(QName.create(TllComplexAugment.QNAME, "list1-1"), QName.create(TllComplexAugment.QNAME, "attr-int"),
99                     LIST11_KEY.getAttrInt())
100             .node(AUG_CONT).build();
101
102     private BindingTestContext testContext;
103     private MountProviderService bindingMountPointService;
104     private DOMMountPointService domMountPointService;
105
106     @Before
107     public void setup() {
108         final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
109         testFactory.setExecutor(MoreExecutors.sameThreadExecutor());
110         testFactory.setStartWithParsedSchema(true);
111         testContext = testFactory.getTestContext();
112
113         testContext.start();
114         bindingMountPointService = testContext.getBindingMountProviderService();
115         domMountPointService = testContext.getDomMountProviderService();
116
117         // biRpcInvoker = testContext.getDomRpcInvoker();
118         assertNotNull(bindingMountPointService);
119         assertNotNull(domMountPointService);
120
121         // flowService = MessageCapturingFlowService.create(baRpcRegistry);
122     }
123
124     @Test
125     public void testMountPoint() {
126         final Integer attrIntValue = 500;
127         domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI)
128             .addService(DOMDataBroker.class, new DOMDataBroker() {
129
130                 @Override
131                 public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store,
132                         final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
133                     throw new UnsupportedOperationException();
134                 }
135
136                 @Override
137                 public DOMDataWriteTransaction newWriteOnlyTransaction() {
138                     throw new UnsupportedOperationException();
139                 }
140
141                 @Override
142                 public DOMDataReadWriteTransaction newReadWriteTransaction() {
143                     return  new DOMDataReadWriteTransaction() {
144
145                         @Override
146                         public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
147                                 final LogicalDatastoreType store, final YangInstanceIdentifier path) {
148                             if(store == LogicalDatastoreType.OPERATIONAL && path.getLastPathArgument().equals(GROUP_STATISTICS_ID_BI.getLastPathArgument())) {
149
150                                 final ContainerNode data = Builders.containerBuilder()
151                                         .withNodeIdentifier(new NodeIdentifier(AUG_CONT))
152                                         .withChild(ImmutableNodes.leafNode(QName.create(AUG_CONT, "attr-int"), attrIntValue))
153                                         .build();
154
155                                 return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?,?>>of(data));
156                             }
157                             return Futures.immediateFailedCheckedFuture(new ReadFailedException(TLL_NAME, new Exception()));
158                         }
159
160                         @Override
161                         public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
162                                 final YangInstanceIdentifier path) {
163                             throw new UnsupportedOperationException();
164                         }
165
166                         @Override
167                         public Object getIdentifier() {
168                             return this;
169                         }
170
171                         @Override
172                         public boolean cancel() {
173                             return false;
174                         }
175
176                         @Override
177                         public ListenableFuture<RpcResult<TransactionStatus>> commit() {
178                             return null;
179                         }
180
181                         @Override
182                         public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
183                             throw new UnsupportedOperationException();
184                         }
185
186                         @Override
187                         public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
188                                 final NormalizedNode<?, ?> data) {
189                             throw new UnsupportedOperationException();
190                         }
191
192                         @Override
193                         public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
194                                 final NormalizedNode<?, ?> data) {
195                             throw new UnsupportedOperationException();
196                         }
197
198                         @Override
199                         public CheckedFuture<Void, TransactionCommitFailedException> submit() {
200                             throw new UnsupportedOperationException();
201                         }
202
203                     };
204                 }
205
206                 @Override
207                 public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
208                     throw new UnsupportedOperationException();
209                 }
210
211                 @Override
212                 public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
213                     throw new UnsupportedOperationException();
214                 }
215
216                 @Override
217                 public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
218                     return Collections.emptyMap();
219                 }
220             }).register();
221
222
223
224         final MountProviderInstance bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
225         assertNotNull(bindingMountPoint);
226
227         final Cont data = (Cont) bindingMountPoint.readOperationalData(AUG_CONT_ID_BA);
228         assertNotNull(data);
229         assertEquals(attrIntValue ,data.getAttrInt());
230     }
231 }

©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.