2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.binding.test.connect.dom;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
14 import com.google.common.util.concurrent.CheckedFuture;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.MoreExecutors;
17 import java.io.InputStream;
18 import java.util.Collections;
19 import java.util.List;
20 import java.util.concurrent.ExecutionException;
21 import java.util.concurrent.Future;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
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.mount.MountProviderInstance;
32 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
33 import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory;
34 import org.opendaylight.controller.sal.binding.test.util.BindingTestContext;
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.list.rev140701.Top;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
40 import org.opendaylight.yangtools.concepts.ListenerRegistration;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
43 import org.opendaylight.yangtools.yang.common.QName;
44 import org.opendaylight.yangtools.yang.common.RpcResult;
45 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
46 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
47 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
48 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
49 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
52 * Test case for reported bug 560
54 * @author Lukas Sedlak
56 * href="https://bugs.opendaylight.org/show_bug.cgi?id=560">https://bugs.opendaylight.org/show_bug.cgi?id=560</a>
58 public class DOMRpcServiceTestBugfix560 {
60 private final static String RPC_SERVICE_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:bi:ba:rpcservice";
61 private final static String REVISION_DATE = "2014-07-01";
62 private final static QName RPC_NAME = QName.create(RPC_SERVICE_NAMESPACE,
63 REVISION_DATE, "rock-the-house");
65 private static final String TLL_NAME = "id";
66 private static final QName TLL_NAME_QNAME = QName.create(TopLevelList.QNAME, "name");
68 private static final InstanceIdentifier<TopLevelList> BA_MOUNT_ID = createBATllIdentifier(TLL_NAME);
69 private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier BI_MOUNT_ID = createBITllIdentifier(TLL_NAME);
71 private BindingTestContext testContext;
72 private DOMMountPointService domMountPointService;
73 private MountProviderService bindingMountPointService;
74 private SchemaContext schemaContext;
77 * @throws java.lang.Exception
80 public void setUp() throws Exception {
81 final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
82 testFactory.setExecutor(MoreExecutors.sameThreadExecutor());
83 testFactory.setStartWithParsedSchema(true);
84 testContext = testFactory.getTestContext();
87 domMountPointService = testContext.getDomMountProviderService();
88 bindingMountPointService = testContext.getBindingMountProviderService();
89 assertNotNull(domMountPointService);
91 final InputStream moduleStream = BindingReflections.getModuleInfo(
92 OpendaylightTestRpcServiceService.class)
93 .getModuleSourceStream();
95 assertNotNull(moduleStream);
96 final List<InputStream> rpcModels = Collections.singletonList(moduleStream);
97 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
98 schemaContext = reactor.buildEffective(rpcModels);
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)
110 private static InstanceIdentifier<TopLevelList> createBATllIdentifier(
111 final String mount) {
112 return InstanceIdentifier.builder(Top.class)
113 .child(TopLevelList.class, new TopLevelListKey(mount)).toInstance();
117 public void test() throws ExecutionException, InterruptedException {
118 // FIXME: This is made to only make sure instance identifier codec for path is instantiated.
120 .createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {
123 public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
124 // TODO Auto-generated method stub
129 public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0, final NormalizedNode<?, ?> arg1) {
130 final DOMRpcResult result = new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
131 return Futures.immediateCheckedFuture(result);
134 final MountProviderInstance mountInstance = bindingMountPointService
135 .getMountPoint(BA_MOUNT_ID);
136 assertNotNull(mountInstance);
137 final OpendaylightTestRpcServiceService rpcService = mountInstance
138 .getRpcService(OpendaylightTestRpcServiceService.class);
139 assertNotNull(rpcService);
142 final Future<RpcResult<Void>> result = rpcService
143 .rockTheHouse(new RockTheHouseInputBuilder().build());
144 assertTrue(result.get().isSuccessful());
145 } catch (final IllegalStateException ex) {
146 fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
151 * @throws java.lang.Exception
154 public void teardown() throws Exception {