1be550f82fc6b9672202c8741fce33ec870e5a1a
[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 @SuppressWarnings("deprecation")
60 public class CrossBrokerMountPointTest {
61
62     private static final QName TLL_NAME_QNAME = QName.create(TopLevelList.QNAME, "name");
63     private static final String TLL_NAME = "foo:1";
64
65     private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
66
67     private static final Map<QName, Object> TLL_KEY_BI = Collections.<QName, Object> singletonMap(TLL_NAME_QNAME,
68             TLL_NAME);
69
70     private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) //
71             .child(TopLevelList.class, TLL_KEY).build();
72
73     private static final List1Key LIST1_KEY = new List1Key("foo");
74     private static final List11Key LIST11_KEY = new List11Key(1);
75
76     private static final InstanceIdentifier<Cont> AUG_CONT_ID_BA = TLL_INSTANCE_ID_BA
77             .builder().augmentation(TllComplexAugment.class) //
78             .child(List1.class, LIST1_KEY) //
79             .child(List11.class, LIST11_KEY) //
80             .augmentation(List11SimpleAugment.class) //
81             .child(Cont.class) //
82             .build();
83
84     private static final QName AUG_CONT = QName.create(List11.QNAME,
85             Cont.QNAME.getLocalName());
86
87     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier TLL_INSTANCE_ID_BI = //
88     org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder() //
89             .node(Top.QNAME) //
90             .node(TopLevelList.QNAME) //
91             .nodeWithKey(TopLevelList.QNAME, TLL_KEY_BI) //
92             .build();
93
94     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier GROUP_STATISTICS_ID_BI = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
95             //
96             .builder(TLL_INSTANCE_ID_BI)
97             .nodeWithKey(QName.create(TllComplexAugment.QNAME, "list1"), QName.create(TllComplexAugment.QNAME, "attr-str"),
98                     LIST1_KEY.getAttrStr())
99             .nodeWithKey(QName.create(TllComplexAugment.QNAME, "list1-1"), QName.create(TllComplexAugment.QNAME, "attr-int"),
100                     LIST11_KEY.getAttrInt())
101             .node(AUG_CONT).build();
102
103     private BindingTestContext testContext;
104     private MountProviderService bindingMountPointService;
105     private DOMMountPointService domMountPointService;
106
107     @Before
108     public void setup() {
109         final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
110         testFactory.setExecutor(MoreExecutors.sameThreadExecutor());
111         testFactory.setStartWithParsedSchema(true);
112         testContext = testFactory.getTestContext();
113
114         testContext.start();
115         bindingMountPointService = testContext.getBindingMountProviderService();
116         domMountPointService = testContext.getDomMountProviderService();
117
118         // biRpcInvoker = testContext.getDomRpcInvoker();
119         assertNotNull(bindingMountPointService);
120         assertNotNull(domMountPointService);
121
122         // flowService = MessageCapturingFlowService.create(baRpcRegistry);
123     }
124
125     @Test
126     public void testMountPoint() {
127         final Integer attrIntValue = 500;
128         domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI)
129             .addService(DOMDataBroker.class, new DOMDataBroker() {
130
131                 @Override
132                 public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store,
133                         final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
134                     throw new UnsupportedOperationException();
135                 }
136
137                 @Override
138                 public DOMDataWriteTransaction newWriteOnlyTransaction() {
139                     throw new UnsupportedOperationException();
140                 }
141
142                 @Override
143                 public DOMDataReadWriteTransaction newReadWriteTransaction() {
144                     return  new DOMDataReadWriteTransaction() {
145
146                         @Override
147                         public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
148                                 final LogicalDatastoreType store, final YangInstanceIdentifier path) {
149                             if(store == LogicalDatastoreType.OPERATIONAL && path.getLastPathArgument().equals(GROUP_STATISTICS_ID_BI.getLastPathArgument())) {
150
151                                 final ContainerNode data = Builders.containerBuilder()
152                                         .withNodeIdentifier(new NodeIdentifier(AUG_CONT))
153                                         .withChild(ImmutableNodes.leafNode(QName.create(AUG_CONT, "attr-int"), attrIntValue))
154                                         .build();
155
156                                 return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?,?>>of(data));
157                             }
158                             return Futures.immediateFailedCheckedFuture(new ReadFailedException(TLL_NAME, new Exception()));
159                         }
160
161                         @Override
162                         public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
163                                 final YangInstanceIdentifier path) {
164                             throw new UnsupportedOperationException();
165                         }
166
167                         @Override
168                         public Object getIdentifier() {
169                             return this;
170                         }
171
172                         @Override
173                         public boolean cancel() {
174                             return false;
175                         }
176
177                         @Override
178                         public ListenableFuture<RpcResult<TransactionStatus>> commit() {
179                             return null;
180                         }
181
182                         @Override
183                         public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
184                             throw new UnsupportedOperationException();
185                         }
186
187                         @Override
188                         public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
189                                 final NormalizedNode<?, ?> data) {
190                             throw new UnsupportedOperationException();
191                         }
192
193                         @Override
194                         public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
195                                 final NormalizedNode<?, ?> data) {
196                             throw new UnsupportedOperationException();
197                         }
198
199                         @Override
200                         public CheckedFuture<Void, TransactionCommitFailedException> submit() {
201                             throw new UnsupportedOperationException();
202                         }
203
204                     };
205                 }
206
207                 @Override
208                 public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
209                     throw new UnsupportedOperationException();
210                 }
211
212                 @Override
213                 public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
214                     throw new UnsupportedOperationException();
215                 }
216
217                 @Override
218                 public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
219                     return Collections.emptyMap();
220                 }
221             }).register();
222
223
224
225         final MountProviderInstance bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
226         assertNotNull(bindingMountPoint);
227
228         final Cont data = (Cont) bindingMountPoint.readOperationalData(AUG_CONT_ID_BA);
229         assertNotNull(data);
230         assertEquals(attrIntValue ,data.getAttrInt());
231     }
232 }

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