import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.opendaylight.mdsal.dom.broker.TestUtils.TEST_CHILD;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
import org.opendaylight.mdsal.dom.broker.DOMRpcRouter.OperationInvocation;
import org.opendaylight.mdsal.dom.broker.util.TestModel;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class RoutedDOMRpcRoutingTableEntryTest {
- @Test
- public void basicTest() {
- final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
+ @Mock
+ public RpcDefinition rpcDefinition;
+
+ private RoutedDOMRpcRoutingTableEntry entry;
+
+ @Before
+ public void before() {
doReturn(TestModel.TEST2_QNAME).when(rpcDefinition).getQName();
+ // Note: ImmutableMap.of() allows get(null), Map.of() does not
+ entry = new RoutedDOMRpcRoutingTableEntry(rpcDefinition, TestModel.TEST_PATH, ImmutableMap.of());
+ }
- final RoutedDOMRpcRoutingTableEntry routedDOMRpcRoutingTableEntry =
- new RoutedDOMRpcRoutingTableEntry(rpcDefinition, TestModel.TEST_PATH, new HashMap<>());
- assertNotNull(routedDOMRpcRoutingTableEntry.newInstance(new HashMap<>()));
+ @Test
+ public void testNewInstance() {
+ final RoutedDOMRpcRoutingTableEntry instance = entry.newInstance(Map.of());
+ assertEquals(TestModel.TEST2_QNAME, entry.getType());
+ assertEquals(Map.of(), instance.getImplementations());
+ }
- final ListenableFuture<?> future = OperationInvocation.invoke(routedDOMRpcRoutingTableEntry, TEST_CHILD);
- final ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get(5, TimeUnit.SECONDS));
- assertThat(ex.getCause(), instanceOf(DOMRpcImplementationNotAvailableException.class));
+ @Test
+ public void testUnregistered() {
+ final ListenableFuture<?> future = OperationInvocation.invoke(entry, TEST_CHILD);
+ final Throwable cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
+ assertThat(cause, instanceOf(DOMRpcImplementationNotAvailableException.class));
+ assertEquals("No implementation of RPC "
+ + "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test2 "
+ + "available",
+ cause.getMessage());
}
}