HONEYCOMB-145 - Utility Class Refactoring
[honeycomb.git] / vpp-common / vpp-translate-utils / src / test / java / io / fd / honeycomb / translate / v3po / util / JvppReplyConsumerTest.java
1 package io.fd.honeycomb.translate.v3po.util;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.fail;
6 import static org.mockito.Matchers.anyLong;
7 import static org.mockito.Matchers.eq;
8 import static org.mockito.Mockito.mock;
9 import static org.mockito.Mockito.when;
10
11 import java.util.concurrent.Future;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.binding.DataContainer;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.openvpp.jvpp.dto.JVppReply;
19
20 public class JvppReplyConsumerTest implements JvppReplyConsumer {
21
22     private static class AnDataObject implements DataObject {
23         @Override
24         public Class<? extends DataContainer> getImplementedInterface() {
25             return null;
26         }
27     }
28
29     @Test
30     public void testGetReplyForWriteTimeout() throws Exception {
31         final Future<JVppReply<?>> future = mock(Future.class);
32         when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class);
33         final InstanceIdentifier<AnDataObject>
34                 replyType = InstanceIdentifier.create(AnDataObject.class);
35         try {
36             getReplyForWrite(future, replyType);
37         } catch (WriteTimeoutException e) {
38             assertTrue(e.getCause() instanceof TimeoutException);
39             assertEquals(replyType, e.getFailedId());
40             return;
41         }
42         fail("WriteTimeoutException was expected");
43     }
44
45     @Test
46     public void testGetReplyForReadTimeout() throws Exception {
47         final Future<JVppReply<?>> future = mock(Future.class);
48         final InstanceIdentifier<AnDataObject> replyType =
49                 InstanceIdentifier.create(AnDataObject.class);
50         when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class);
51         try {
52             getReplyForRead(future, replyType);
53         } catch (ReadTimeoutException e) {
54             assertTrue(e.getCause() instanceof TimeoutException);
55             assertEquals(replyType, e.getFailedId());
56             return;
57         }
58         fail("ReadTimeoutException was expected");
59     }
60 }