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

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