@Test public void testHandleErrorMessage_CurrentMicroserviceIsTheFirstOneInRoute() { Message message = mock(Message.class); when(message.getContextValue(ContextImpl.MS_API_ROUTING_PLAN_HEADER)).thenReturn( "microservice1,microservice2,microservice3"); when(message.getUnderlyingMessageObject()).thenReturn(Mockito.mock(Object.class)); HashMap<String, String> messageHeaders = new HashMap(); messageHeaders.put(MessagingConstants.FAILED_HEADER, "true"); messageHeaders.put( MessagingConstants.ERROR_HEADER, "[{\"microservice_uri\":\"microservice-uri\",\"timestamp\":1456417079688,\"error_code\":500,\"error_message\":null}]"); when(message.getMessageHeaders()).thenReturn(messageHeaders); HashMap<String, String> messageContext = new HashMap(); messageContext.put(ContextImpl.MS_API_ROUTING_PLAN_HEADER, "microservice1,microservice2,microservice3"); when(message.getMessageContext()).thenReturn(messageContext); when(context.getMicroServiceBaseURI()).thenReturn("microservice1"); ResourceManager resourceManager = mock(ResourceManager.class); ManagedDependency managedResource = mock(ManagedDependency.class); MessageSender messageSender = Mockito.mock(MessageSender.class); when(managedResource.getMessageSender()).thenReturn(messageSender); when(resourceManager.getManagedResourceByName(eq("microservice3"))).thenReturn(managedResource); when(context.getDependencyManager()).thenReturn(resourceManager); managedMessageListener.onErrorMessage(message, context); verify(messageListener, Mockito.never()).onErrorMessage(eq(message), eq(context)); verify(messageSender).sendMessage(any(Class.class), anyObject(), eq(messageHeaders), eq(messageContext)); }
@Override public void onErrorMessage(Message message, Context context) { logger.error("Error message received {}", message.getMessageHeader(ERROR_HEADER)); handleMessage(message, context, true); }
ManagedMessageListenerImpl implements ManagedMessageListener { @Override public void onErrorMessage(Message message, Context context) { logger.error("Error message received {}", message.getMessageHeader(ERROR_HEADER)); handleMessage(message, context, true); } }
ManagedMessageListenerImpl implements ManagedMessageListener { @Override public void onErrorMessage(Message message, Context context) { logger.error("Error message received {}", message.getMessageHeader(ERROR_HEADER)); handleMessage(message, context, true); } ManagedMessageListenerImpl(
            Context context,
            MessageListener messageListener,
            ManagedInputQueue managedQueue,
            int threadOrdinal); }
ManagedMessageListenerImpl implements ManagedMessageListener { @Override public void onErrorMessage(Message message, Context context) { logger.error("Error message received {}", message.getMessageHeader(ERROR_HEADER)); handleMessage(message, context, true); } ManagedMessageListenerImpl(
            Context context,
            MessageListener messageListener,
            ManagedInputQueue managedQueue,
            int threadOrdinal); @Override void onMessage(Message message, Context context); @Override void onErrorMessage(Message message, Context context); QueueExecutionState getQueueExecutionState(); }
ManagedMessageListenerImpl implements ManagedMessageListener { @Override public void onErrorMessage(Message message, Context context) { logger.error("Error message received {}", message.getMessageHeader(ERROR_HEADER)); handleMessage(message, context, true); } ManagedMessageListenerImpl(
            Context context,
            MessageListener messageListener,
            ManagedInputQueue managedQueue,
            int threadOrdinal); @Override void onMessage(Message message, Context context); @Override void onErrorMessage(Message message, Context context); QueueExecutionState getQueueExecutionState();  }