private void usePath(String listenerPath) throws InitialisationException, RegistrationException { MuleContext mockMuleContext = mock(MuleContext.class); when(mockMuleContext.getRegistry()).thenReturn(mock(MuleRegistry.class)); when(mockMuleContext.getConfiguration()).thenReturn(mock(MuleConfiguration.class)); when(mockMuleContext.getConfiguration().getDefaultEncoding()).thenReturn("UTF-8"); final DefaultHttpListener httpListener = new DefaultHttpListener(); httpListener.setMuleContext(mockMuleContext); httpListener.setFlowConstruct(mockFlowConstruct); httpListener.setConfig(mockHttpListenerConfig); when(mockHttpListenerConfig.getFullListenerPath(anyString())) .thenReturn(new ListenerPath(null, listenerPath)); MessageProcessingManager messageProcessingManager = mock(MessageProcessingManager.class); doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpMessageProcessorTemplate template = (HttpMessageProcessorTemplate) invocation.getArguments()[0]; template.sendResponseToClient(null, null); return null; } }) .when(messageProcessingManager) .processMessage(any(HttpMessageProcessorTemplate.class), any(MessageProcessContext.class)); when(mockMuleContext.getRegistry().lookupObject(MessageProcessingManager.class)) .thenReturn(messageProcessingManager); when(mockMuleContext.getRegistry().get(HTTP_LISTENER_CONNECTION_MANAGER)) .thenReturn(mockHttpListenerConnectionManager); httpListener.setPath(listenerPath); httpListener.initialise(); }
private void useInvalidPath(String listenerPath) throws InitialisationException { final DefaultHttpListener httpListener = new DefaultHttpListener(); httpListener.setMuleContext(mockMuleContext); httpListener.setFlowConstruct(mockFlowConstruct); httpListener.setConfig(mockHttpListenerConfig); when(mockHttpListenerConfig.getFullListenerPath(anyString())) .thenReturn(new ListenerPath(null, listenerPath)); when(mockMuleContext.getRegistry().get(HTTP_LISTENER_CONNECTION_MANAGER)) .thenReturn(mockHttpListenerConnectionManager); httpListener.setPath(listenerPath); expectedException.expect(InitialisationException.class); httpListener.initialise(); }