PurgeEndpointAction extends AbstractTestAction { public ReferenceResolver getReferenceResolver() { return referenceResolver; } PurgeEndpointAction(Builder builder); @Override void doExecute(TestContext context); ReferenceResolver getReferenceResolver(); List<String> getEndpointNames(); List<Endpoint> getEndpoints(); Map<String, Object> getMessageSelectorMap(); String getMessageSelector(); long getReceiveTimeout(); long getSleepTime();  }
@Test public void testPurgeWithEndpointNames() { reset(mockEndpoint, consumer, selectiveConsumer); when(mockEndpoint.getName()).thenReturn("mockEndpoint"); when(mockEndpoint.createConsumer()).thenReturn(consumer); when(consumer.receive(context, 100L)).thenReturn(new DefaultMessage()); doThrow(new ActionTimeoutException()).when(consumer).receive(context, 100L); PurgeEndpointAction purgeEndpointAction = new PurgeEndpointAction.Builder() .referenceResolver(context.getReferenceResolver()) .endpointNames("mockEndpoint") .build(); purgeEndpointAction.execute(context); }
@SuppressWarnings("unchecked") @Test public void testPurgeWithEndpointObjects() { reset(mockEndpoint, emptyEndpoint, consumer, selectiveConsumer); when(mockEndpoint.getName()).thenReturn("mockEndpoint"); when(emptyEndpoint.getName()).thenReturn("emptyEndpoint"); when(mockEndpoint.createConsumer()).thenReturn(consumer); when(emptyEndpoint.createConsumer()).thenReturn(consumer); when(consumer.receive(context, 100L)).thenReturn(new DefaultMessage()); doThrow(new ActionTimeoutException()).when(consumer).receive(context, 100L); doThrow(new ActionTimeoutException()).when(consumer).receive(context, 100L); PurgeEndpointAction purgeEndpointAction = new PurgeEndpointAction.Builder() .referenceResolver(context.getReferenceResolver()) .endpoints(mockEndpoint, emptyEndpoint) .build(); purgeEndpointAction.execute(context); }
@Test public void testPurgeWithMessageSelector() throws Exception { reset(mockEndpoint, consumer, selectiveConsumer); when(mockEndpoint.getName()).thenReturn("mockEndpoint"); when(mockEndpoint.createConsumer()).thenReturn(selectiveConsumer); when(selectiveConsumer.receive("operation = 'sayHello'", context, 100L)).thenReturn(new DefaultMessage()); doThrow(new ActionTimeoutException()).when(selectiveConsumer).receive("operation = 'sayHello'", context, 100L); PurgeEndpointAction purgeEndpointAction = new PurgeEndpointAction.Builder() .referenceResolver(context.getReferenceResolver()) .endpoints(mockEndpoint) .selector("operation = 'sayHello'") .build(); purgeEndpointAction.execute(context); }
@Test public void testPurgeWithMessageSelectorMap() throws Exception { reset(mockEndpoint, consumer, selectiveConsumer); when(mockEndpoint.getName()).thenReturn("mockEndpoint"); when(mockEndpoint.createConsumer()).thenReturn(selectiveConsumer); when(selectiveConsumer.receive("operation = 'sayHello'", context, 100L)).thenReturn(new DefaultMessage()); doThrow(new ActionTimeoutException()).when(selectiveConsumer).receive("operation = 'sayHello'", context, 100L); PurgeEndpointAction purgeEndpointAction = new PurgeEndpointAction.Builder() .referenceResolver(context.getReferenceResolver()) .endpoints(mockEndpoint) .selector(Collections.singletonMap("operation", "sayHello")) .build(); purgeEndpointAction.execute(context); }