ReceiveTimeoutAction extends AbstractTestAction { public long getTimeout() { return timeout; } ReceiveTimeoutAction(Builder builder); @Override void doExecute(TestContext context); Endpoint getOrCreateEndpoint(TestContext context); String getMessageSelector(); Map<String, Object> getMessageSelectorMap(); Endpoint getEndpoint(); long getTimeout(); String getEndpointUri();  }
@Test public void testReceiveTimeout() { reset(endpoint, consumer, endpointConfiguration); when(endpoint.createConsumer()).thenReturn(consumer); when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration); when(endpointConfiguration.getTimeout()).thenReturn(5000L); when(consumer.receive(context, 1000L)).thenReturn(null); when(endpoint.getActor()).thenReturn(null); ReceiveTimeoutAction receiveTimeout = new ReceiveTimeoutAction.Builder() .endpoint(endpoint) .build(); receiveTimeout.execute(context); }
@Test public void testReceiveTimeoutCustomTimeout() { reset(endpoint, consumer, endpointConfiguration); when(endpoint.createConsumer()).thenReturn(consumer); when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration); when(endpointConfiguration.getTimeout()).thenReturn(5000L); when(consumer.receive(context, 500L)).thenReturn(null); when(endpoint.getActor()).thenReturn(null); ReceiveTimeoutAction receiveTimeout = new ReceiveTimeoutAction.Builder() .endpoint(endpoint) .timeout(500L) .build(); receiveTimeout.execute(context); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testReceiveTimeoutFail() { Message message = new DefaultMessage("<TestMessage>Hello World!</TestMessage>"); reset(endpoint, consumer, endpointConfiguration); when(endpoint.createConsumer()).thenReturn(consumer); when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration); when(endpointConfiguration.getTimeout()).thenReturn(5000L); when(consumer.receive(context, 1000L)).thenReturn(message); when(endpoint.getActor()).thenReturn(null); ReceiveTimeoutAction receiveTimeout = new ReceiveTimeoutAction.Builder() .endpoint(endpoint) .build(); try { receiveTimeout.execute(context); } catch(CitrusRuntimeException e) { Assert.assertEquals(e.getMessage(), "Message timeout validation failed! Received message while waiting for timeout on destination"); return; } Assert.fail("Missing " + CitrusRuntimeException.class + " because action did receive a message"); }
@Test public void testReceiveTimeoutWithMessageSelector() { reset(endpoint, consumer, endpointConfiguration); when(endpoint.createConsumer()).thenReturn(consumer); when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration); when(endpointConfiguration.getTimeout()).thenReturn(5000L); when(consumer.receive("Operation = 'sayHello'", context, 1000L)).thenReturn(null); when(endpoint.getActor()).thenReturn(null); ReceiveTimeoutAction receiveTimeout = new ReceiveTimeoutAction.Builder() .endpoint(endpoint) .selector("Operation = 'sayHello'") .build(); receiveTimeout.execute(context); }
@Test public void testReceiveTimeoutWithMessageSelectorVariableSupport() { context.setVariable("operation", "sayHello"); reset(endpoint, consumer, endpointConfiguration); when(endpoint.createConsumer()).thenReturn(consumer); when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration); when(endpointConfiguration.getTimeout()).thenReturn(5000L); when(consumer.receive("Operation = 'sayHello'", context, 1000L)).thenReturn(null); when(endpoint.getActor()).thenReturn(null); ReceiveTimeoutAction receiveTimeout = new ReceiveTimeoutAction.Builder() .endpoint(endpoint) .selector("Operation = '${operation}'") .build(); receiveTimeout.execute(context); }