Allow programmatic module sharding configuration
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / connect / dom / DOMRpcServiceTestBugfix560.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.assertTrue;
12 import static org.junit.Assert.fail;
13
14 import com.google.common.base.Optional;
15 import com.google.common.util.concurrent.CheckedFuture;
16 import com.google.common.util.concurrent.Futures;
17 import com.google.common.util.concurrent.ListenableFuture;
18 import com.google.common.util.concurrent.MoreExecutors;
19 import java.util.concurrent.ExecutionException;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
24 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
25 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
26 import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
27 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
28 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
29 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
30 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
31 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
32 import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory;
33 import org.opendaylight.controller.sal.binding.test.util.BindingTestContext;
34 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
41 import org.opendaylight.yangtools.concepts.ListenerRegistration;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
44 import org.opendaylight.yangtools.yang.common.QName;
45 import org.opendaylight.yangtools.yang.common.RpcResult;
46 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
47 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
48 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
49 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
50 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
51 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
52 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
53
54 /**
55  * Test case for reported bug 560.
56  *
57  * @author Lukas Sedlak
58  * @see <a
59  *      href="https://bugs.opendaylight.org/show_bug.cgi?id=560">https://bugs.opendaylight.org/show_bug.cgi?id=560</a>
60  */
61 public class DOMRpcServiceTestBugfix560 {
62
63     private static final String RPC_SERVICE_NAMESPACE =
64             "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:bi:ba:rpcservice";
65     private static final String REVISION_DATE = "2014-07-01";
66     private static final QName RPC_NAME = QName.create(RPC_SERVICE_NAMESPACE, REVISION_DATE, "rock-the-house");
67
68     private static final String TLL_NAME = "id";
69     private static final QName TLL_NAME_QNAME = QName.create(TopLevelList.QNAME, "name");
70
71     private static final InstanceIdentifier<TopLevelList> BA_MOUNT_ID = createBATllIdentifier(TLL_NAME);
72     private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier BI_MOUNT_ID =
73             createBITllIdentifier(TLL_NAME);
74
75     private BindingTestContext testContext;
76     private DOMMountPointService domMountPointService;
77     private MountPointService bindingMountPointService;
78     private SchemaContext schemaContext;
79
80     @Before
81     public void setUp() throws Exception {
82         final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
83         testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
84         testFactory.setStartWithParsedSchema(true);
85         testContext = testFactory.getTestContext();
86
87         testContext.start();
88         domMountPointService = testContext.getDomMountProviderService();
89         bindingMountPointService = testContext.getBindingMountPointService();
90         assertNotNull(domMountPointService);
91
92         final YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(OpendaylightTestRpcServiceService.class);
93         assertNotNull(moduleInfo);
94
95         schemaContext = YangParserTestUtils.parseYangSources(StatementParserMode.DEFAULT_MODE, null,
96             YangTextSchemaSource.delegateForByteSource(RevisionSourceIdentifier.create(
97                     moduleInfo.getName().getLocalName(), moduleInfo.getName().getRevision()),
98                 moduleInfo.getYangTextByteSource()));
99     }
100
101     private static org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier createBITllIdentifier(
102             final String mount) {
103         return org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
104                 .builder().node(Top.QNAME)
105                 .node(TopLevelList.QNAME)
106                 .nodeWithKey(TopLevelList.QNAME, TLL_NAME_QNAME, mount)
107                 .build();
108     }
109
110     private static InstanceIdentifier<TopLevelList> createBATllIdentifier(
111             final String mount) {
112         return InstanceIdentifier.builder(Top.class)
113                 .child(TopLevelList.class, new TopLevelListKey(mount)).build();
114     }
115
116     @Test
117     public void test() throws ExecutionException, InterruptedException {
118         // FIXME: This is made to only make sure instance identifier codec for path is instantiated.
119         domMountPointService.createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {
120             @Override
121             public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
122                 // TODO Auto-generated method stub
123                 return null;
124             }
125
126             @Override
127             public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0,
128                     final NormalizedNode<?, ?> arg1) {
129                 return Futures.immediateCheckedFuture(new DefaultDOMRpcResult((NormalizedNode<?, ?>) null));
130             }
131         }).register();
132
133         final Optional<MountPoint> mountInstance = bindingMountPointService.getMountPoint(BA_MOUNT_ID);
134         assertTrue(mountInstance.isPresent());
135
136         final Optional<RpcConsumerRegistry> rpcRegistry = mountInstance.get().getService(RpcConsumerRegistry.class);
137         assertTrue(rpcRegistry.isPresent());
138         final OpendaylightTestRpcServiceService rpcService = rpcRegistry.get()
139                 .getRpcService(OpendaylightTestRpcServiceService.class);
140         assertNotNull(rpcService);
141
142         try {
143             final ListenableFuture<RpcResult<RockTheHouseOutput>> result = rpcService
144                     .rockTheHouse(new RockTheHouseInputBuilder().build());
145             assertTrue(result.get().isSuccessful());
146         } catch (final IllegalStateException ex) {
147             fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
148         }
149     }
150
151     @After
152     public void teardown() {
153         testContext.close();
154     }
155 }

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