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.translate.vpp.util;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22 import static org.mockito.Matchers.anyLong;
23 import static org.mockito.Matchers.eq;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
27 import java.util.concurrent.Future;
28 import java.util.concurrent.TimeUnit;
29 import java.util.concurrent.TimeoutException;
30 import org.junit.Test;
31 import org.opendaylight.yangtools.yang.binding.DataContainer;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import io.fd.vpp.jvpp.dto.JVppReply;
36 public class JvppReplyConsumerTest implements JvppReplyConsumer {
38 private static class AnDataObject implements DataObject {
40 public Class<? extends DataContainer> getImplementedInterface() {
46 public void testGetReplyForWriteTimeout() throws Exception {
47 final Future<JVppReply<?>> future = mock(Future.class);
48 when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class);
49 final InstanceIdentifier<AnDataObject>
50 replyType = InstanceIdentifier.create(AnDataObject.class);
52 getReplyForWrite(future, replyType);
53 } catch (WriteTimeoutException e) {
54 assertTrue(e.getCause() instanceof TimeoutException);
55 assertEquals(replyType, e.getFailedId());
58 fail("WriteTimeoutException was expected");
62 public void testGetReplyForReadTimeout() throws Exception {
63 final Future<JVppReply<?>> future = mock(Future.class);
64 final InstanceIdentifier<AnDataObject> replyType =
65 InstanceIdentifier.create(AnDataObject.class);
66 when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class);
68 getReplyForRead(future, replyType);
69 } catch (ReadTimeoutException e) {
70 assertTrue(e.getCause() instanceof TimeoutException);
71 assertEquals(replyType, e.getFailedId());
74 fail("ReadTimeoutException was expected");