d87470a5e97c19496b1e65beaa97eefd81ad45b4
[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.assertNotNull;
11 import static org.junit.Assert.assertEquals;
12
13 import java.math.BigInteger;
14 import java.util.Collections;
15 import java.util.Map;
16
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
20 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
21 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
22 import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory;
23 import org.opendaylight.controller.sal.binding.test.util.BindingTestContext;
24 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
25 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.opendaylight.yangtools.yang.common.QName;
38 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
39 import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
40
41 import com.google.common.util.concurrent.MoreExecutors;
42
43 @SuppressWarnings("deprecation")
44 public class CrossBrokerMountPointTest {
45
46     private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "id");
47     private static final String NODE_ID = "node:1";
48
49     private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID));
50
51     private static final Map<QName, Object> NODE_KEY_BI = Collections.<QName, Object> singletonMap(NODE_ID_QNAME,
52             NODE_ID);
53
54     private static final InstanceIdentifier<Node> NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
55             .child(Node.class, NODE_KEY).toInstance();
56     private static GroupKey GROUP_KEY = new GroupKey(new GroupId(0L));
57
58     private static final InstanceIdentifier<GroupStatistics> GROUP_STATISTICS_ID_BA = NODE_INSTANCE_ID_BA
59             .builder().augmentation(FlowCapableNode.class) //
60             .child(Group.class, GROUP_KEY) //
61             .augmentation(NodeGroupStatistics.class) //
62             .child(GroupStatistics.class) //
63             .toInstance();
64
65     private static final QName AUGMENTED_GROUP_STATISTICS = QName.create(NodeGroupStatistics.QNAME,
66             GroupStatistics.QNAME.getLocalName());
67
68     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier NODE_INSTANCE_ID_BI = //
69     org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder() //
70             .node(Nodes.QNAME) //
71             .nodeWithKey(Node.QNAME, NODE_KEY_BI) //
72             .toInstance();
73
74     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier GROUP_STATISTICS_ID_BI = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
75             //
76             .builder(NODE_INSTANCE_ID_BI)
77             .nodeWithKey(QName.create(FlowCapableNode.QNAME, "group"), QName.create(FlowCapableNode.QNAME, "group-id"),
78                     0L).node(AUGMENTED_GROUP_STATISTICS).toInstance();
79
80     private BindingTestContext testContext;
81     private MountProviderService bindingMountPointService;
82     private MountProvisionService domMountPointService;
83
84     @Before
85     public void setup() {
86         BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
87         testFactory.setExecutor(MoreExecutors.sameThreadExecutor());
88         testFactory.setStartWithParsedSchema(true);
89         testContext = testFactory.getTestContext();
90
91         testContext.start();
92         bindingMountPointService = testContext.getBindingMountProviderService();
93         domMountPointService = testContext.getDomMountProviderService();
94
95         // biRpcInvoker = testContext.getDomRpcInvoker();
96         assertNotNull(bindingMountPointService);
97         assertNotNull(domMountPointService);
98
99         // flowService = MessageCapturingFlowService.create(baRpcRegistry);
100     }
101
102     @Test
103     public void testMountPoint() {
104
105         testContext.getBindingDataBroker().readOperationalData(NODE_INSTANCE_ID_BA);
106
107         MountProvisionInstance domMountPoint = domMountPointService.createMountPoint(NODE_INSTANCE_ID_BI);
108         assertNotNull(domMountPoint);
109         MountProviderInstance bindingMountPoint = bindingMountPointService.getMountPoint(NODE_INSTANCE_ID_BA);
110         assertNotNull(bindingMountPoint);
111
112         final BigInteger packetCount = BigInteger.valueOf(500L);
113
114
115         DataReader<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode> simpleReader = new DataReader<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode>() {
116
117             @Override
118             public CompositeNode readConfigurationData(final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier arg0) {
119                 return null;
120             }
121
122
123             @Override
124             public CompositeNode readOperationalData(final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier arg0) {
125                 if (arg0.equals(GROUP_STATISTICS_ID_BI)) {
126                     ImmutableCompositeNode data = ImmutableCompositeNode
127                             .builder()
128                             .setQName(AUGMENTED_GROUP_STATISTICS)
129                             .addLeaf(QName.create(AUGMENTED_GROUP_STATISTICS, "packet-count"), packetCount) //
130                             .toInstance();
131
132                     return data;
133                 }
134                 return null;
135             }
136
137         };
138         domMountPoint.registerOperationalReader(NODE_INSTANCE_ID_BI, simpleReader);
139
140         GroupStatistics data = (GroupStatistics) bindingMountPoint.readOperationalData(GROUP_STATISTICS_ID_BA);
141         assertNotNull(data);
142         assertEquals(packetCount,data.getPacketCount().getValue());
143     }
144 }

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