Merge "Bug 2731: Discard changes only when transaction exist."
[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
13 import java.util.Collections;
14 import java.util.Map;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
19 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
20 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
21 import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory;
22 import org.opendaylight.controller.sal.binding.test.util.BindingTestContext;
23 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
24 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.List11SimpleAugment;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Key;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Key;
31 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;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 import org.opendaylight.yangtools.yang.common.QName;
37 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
38 import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
39
40 import com.google.common.util.concurrent.MoreExecutors;
41
42 @SuppressWarnings("deprecation")
43 public class CrossBrokerMountPointTest {
44
45     private static final QName TLL_NAME_QNAME = QName.create(TopLevelList.QNAME, "name");
46     private static final String TLL_NAME = "foo:1";
47
48     private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
49
50     private static final Map<QName, Object> TLL_KEY_BI = Collections.<QName, Object> singletonMap(TLL_NAME_QNAME,
51             TLL_NAME);
52
53     private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) //
54             .child(TopLevelList.class, TLL_KEY).build();
55
56     private static final List1Key LIST1_KEY = new List1Key("foo");
57     private static final List11Key LIST11_KEY = new List11Key(1);
58
59     private static final InstanceIdentifier<Cont> AUG_CONT_ID_BA = TLL_INSTANCE_ID_BA
60             .builder().augmentation(TllComplexAugment.class) //
61             .child(List1.class, LIST1_KEY) //
62             .child(List11.class, LIST11_KEY) //
63             .augmentation(List11SimpleAugment.class) //
64             .child(Cont.class) //
65             .build();
66
67     private static final QName AUG_CONT = QName.create(List11.QNAME,
68             Cont.QNAME.getLocalName());
69
70     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier TLL_INSTANCE_ID_BI = //
71     org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder() //
72             .node(Top.QNAME) //
73             .nodeWithKey(TopLevelList.QNAME, TLL_KEY_BI) //
74             .build();
75
76     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier GROUP_STATISTICS_ID_BI = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
77             //
78             .builder(TLL_INSTANCE_ID_BI)
79             .nodeWithKey(QName.create(TllComplexAugment.QNAME, "list1"), QName.create(TllComplexAugment.QNAME, "attr-str"),
80                     LIST1_KEY.getAttrStr())
81             .nodeWithKey(QName.create(TllComplexAugment.QNAME, "list1-1"), QName.create(TllComplexAugment.QNAME, "attr-int"),
82                     LIST11_KEY.getAttrInt())
83             .node(AUG_CONT).build();
84
85     private BindingTestContext testContext;
86     private MountProviderService bindingMountPointService;
87     private MountProvisionService domMountPointService;
88
89     @Before
90     public void setup() {
91         BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
92         testFactory.setExecutor(MoreExecutors.sameThreadExecutor());
93         testFactory.setStartWithParsedSchema(true);
94         testContext = testFactory.getTestContext();
95
96         testContext.start();
97         bindingMountPointService = testContext.getBindingMountProviderService();
98         domMountPointService = testContext.getDomMountProviderService();
99
100         // biRpcInvoker = testContext.getDomRpcInvoker();
101         assertNotNull(bindingMountPointService);
102         assertNotNull(domMountPointService);
103
104         // flowService = MessageCapturingFlowService.create(baRpcRegistry);
105     }
106
107     @Test
108     public void testMountPoint() {
109
110         testContext.getBindingDataBroker().readOperationalData(TLL_INSTANCE_ID_BA);
111
112         MountProvisionInstance domMountPoint = domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI);
113         assertNotNull(domMountPoint);
114         MountProviderInstance bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
115         assertNotNull(bindingMountPoint);
116
117         final Integer attrIntalue = 500;
118
119
120         DataReader<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode> simpleReader = new DataReader<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode>() {
121
122             @Override
123             public CompositeNode readConfigurationData(final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier arg0) {
124                 return null;
125             }
126
127
128             @Override
129             public CompositeNode readOperationalData(final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier arg0) {
130                 if (arg0.equals(GROUP_STATISTICS_ID_BI)) {
131                     ImmutableCompositeNode data = ImmutableCompositeNode
132                             .builder()
133                             .setQName(AUG_CONT)
134                             .addLeaf(QName.create(AUG_CONT, "attr-int"), attrIntalue) //
135                             .build();
136
137                     return data;
138                 }
139                 return null;
140             }
141
142         };
143         domMountPoint.registerOperationalReader(TLL_INSTANCE_ID_BI, simpleReader);
144
145         Cont data = (Cont) bindingMountPoint.readOperationalData(AUG_CONT_ID_BA);
146         assertNotNull(data);
147         assertEquals(attrIntalue ,data.getAttrInt());
148     }
149 }