From a4b65a2de72906e53c94de3beb098744d6fc14ae Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 27 Sep 2016 14:24:06 +0200 Subject: HONEYCOMB-206: change package name to match groupId Change-Id: I74f769c09e86f08b1753e685a134d20e801bd7da Signed-off-by: Marek Gradzki --- .../translate/vpp/util/JvppReplyConsumerTest.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/JvppReplyConsumerTest.java (limited to 'vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/JvppReplyConsumerTest.java') diff --git a/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/JvppReplyConsumerTest.java b/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/JvppReplyConsumerTest.java new file mode 100644 index 000000000..af05ffd8f --- /dev/null +++ b/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/vpp/util/JvppReplyConsumerTest.java @@ -0,0 +1,60 @@ +package io.fd.honeycomb.translate.vpp.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.anyLong; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.Test; +import org.opendaylight.yangtools.yang.binding.DataContainer; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.jvpp.dto.JVppReply; + +public class JvppReplyConsumerTest implements JvppReplyConsumer { + + private static class AnDataObject implements DataObject { + @Override + public Class getImplementedInterface() { + return null; + } + } + + @Test + public void testGetReplyForWriteTimeout() throws Exception { + final Future> future = mock(Future.class); + when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class); + final InstanceIdentifier + replyType = InstanceIdentifier.create(AnDataObject.class); + try { + getReplyForWrite(future, replyType); + } catch (WriteTimeoutException e) { + assertTrue(e.getCause() instanceof TimeoutException); + assertEquals(replyType, e.getFailedId()); + return; + } + fail("WriteTimeoutException was expected"); + } + + @Test + public void testGetReplyForReadTimeout() throws Exception { + final Future> future = mock(Future.class); + final InstanceIdentifier replyType = + InstanceIdentifier.create(AnDataObject.class); + when(future.get(anyLong(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class); + try { + getReplyForRead(future, replyType); + } catch (ReadTimeoutException e) { + assertTrue(e.getCause() instanceof TimeoutException); + assertEquals(replyType, e.getFailedId()); + return; + } + fail("ReadTimeoutException was expected"); + } +} \ No newline at end of file -- cgit 1.2.3-korg