2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.rpc;
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assert.fail;
23 import java.util.concurrent.ExecutionException;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.ArgumentMatchers;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
30 import org.opendaylight.yangtools.yang.binding.DataObject;
31 import org.opendaylight.yangtools.yang.common.QName;
32 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
34 public class RpcRegistryBuilderTest {
36 private RpcRegistry registry;
38 private RpcService service1;
40 private RpcService service2;
42 private static final URI namespace = URI.create("urn:foo");
43 private static final SchemaPath ID1 = SchemaPath.ROOT.createChild(QName.create(namespace, "a"));
44 private static final SchemaPath ID2 = SchemaPath.ROOT.createChild(QName.create(namespace, "b"));
48 service1 = Mockito.mock(RpcService.class);
49 Mockito.when(service1.getManagedNode()).thenReturn(ID1);
51 service2 = Mockito.mock(RpcService.class);
52 Mockito.when(service2.getManagedNode()).thenReturn(ID2);
54 final RpcRegistryBuilder builder = new RpcRegistryBuilder();
55 builder.addService(service1);
56 builder.addService(service2);
57 registry = builder.build();
61 public void testInvokeService() {
62 final DataObject request = Mockito.mock(DataObject.class);
64 registry.invoke(ID2, request);
66 Mockito.verify(service2).invoke(request);
67 Mockito.verify(service1, Mockito.never()).invoke(ArgumentMatchers.any());
71 public void testServiceNotFound() throws ExecutionException, InterruptedException {
72 final SchemaPath id = SchemaPath.ROOT.createChild(QName.create(namespace, "c"));
73 final DataObject request = Mockito.mock(DataObject.class);
76 registry.invoke(id, request).toCompletableFuture().get();
77 } catch (Exception e) {
78 assertTrue(e.getCause() instanceof DOMRpcImplementationNotAvailableException);
81 fail("Exception expected");