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.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.MoreExecutors;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.Future;
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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
39 import org.opendaylight.yangtools.concepts.ListenerRegistration;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
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.model.repo.api.RevisionSourceIdentifier;
49 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
50 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
51 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
54 * Test case for reported bug 560
56 * @author Lukas Sedlak
58 * href="https://bugs.opendaylight.org/show_bug.cgi?id=560">https://bugs.opendaylight.org/show_bug.cgi?id=560</a>
60 public class DOMRpcServiceTestBugfix560 {
62 private final static String RPC_SERVICE_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:bi:ba:rpcservice";
63 private final static String REVISION_DATE = "2014-07-01";
64 private final static QName RPC_NAME = QName.create(RPC_SERVICE_NAMESPACE,
65 REVISION_DATE, "rock-the-house");
67 private static final String TLL_NAME = "id";
68 private static final QName TLL_NAME_QNAME = QName.create(TopLevelList.QNAME, "name");
70 private static final InstanceIdentifier<TopLevelList> BA_MOUNT_ID = createBATllIdentifier(TLL_NAME);
71 private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier BI_MOUNT_ID = createBITllIdentifier(TLL_NAME);
73 private BindingTestContext testContext;
74 private DOMMountPointService domMountPointService;
75 private MountPointService bindingMountPointService;
76 private SchemaContext schemaContext;
79 * @throws java.lang.Exception
82 public void setUp() throws Exception {
83 final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
84 testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
85 testFactory.setStartWithParsedSchema(true);
86 testContext = testFactory.getTestContext();
89 domMountPointService = testContext.getDomMountProviderService();
90 bindingMountPointService = testContext.getBindingMountPointService();
91 assertNotNull(domMountPointService);
93 final YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(OpendaylightTestRpcServiceService.class);
94 assertNotNull(moduleInfo);
96 schemaContext = YangParserTestUtils.parseYangSources(StatementParserMode.DEFAULT_MODE, null,
97 YangTextSchemaSource.delegateForByteSource(RevisionSourceIdentifier.create(
98 moduleInfo.getName().getLocalName(), moduleInfo.getName().getRevision()),
99 moduleInfo.getYangTextByteSource()));
102 private static org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier createBITllIdentifier(
103 final String mount) {
104 return org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
105 .builder().node(Top.QNAME)
106 .node(TopLevelList.QNAME)
107 .nodeWithKey(TopLevelList.QNAME, TLL_NAME_QNAME, mount)
111 private static InstanceIdentifier<TopLevelList> createBATllIdentifier(
112 final String mount) {
113 return InstanceIdentifier.builder(Top.class)
114 .child(TopLevelList.class, new TopLevelListKey(mount)).build();
118 public void test() throws ExecutionException, InterruptedException {
119 // FIXME: This is made to only make sure instance identifier codec for path is instantiated.
121 .createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {
124 public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
125 // TODO Auto-generated method stub
130 public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0, final NormalizedNode<?, ?> arg1) {
131 final DOMRpcResult result = new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
132 return Futures.immediateCheckedFuture(result);
136 final Optional<MountPoint> mountInstance = bindingMountPointService.getMountPoint(BA_MOUNT_ID);
137 assertTrue(mountInstance.isPresent());
139 final Optional<RpcConsumerRegistry> rpcRegistry = mountInstance.get().getService(RpcConsumerRegistry.class);
140 assertTrue(rpcRegistry.isPresent());
141 final OpendaylightTestRpcServiceService rpcService = rpcRegistry.get()
142 .getRpcService(OpendaylightTestRpcServiceService.class);
143 assertNotNull(rpcService);
146 final Future<RpcResult<Void>> result = rpcService
147 .rockTheHouse(new RockTheHouseInputBuilder().build());
148 assertTrue(result.get().isSuccessful());
149 } catch (final IllegalStateException ex) {
150 fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
155 * @throws java.lang.Exception
158 public void teardown() throws Exception {