protected void assertSync(MuleMessage result) { assertNotNull(result); String receiverThread = result.getInboundProperty("receiver-thread"); String flowThread = result.getInboundProperty("processor-thread"); String dispatcherThread = result.getInboundProperty("dispatcher-thread"); assertEquals(receiverThread, flowThread); assertEquals(flowThread, dispatcherThread); }
@Test public void testHttpResponseMove() throws Exception { MuleClient client = new MuleClient(muleContext); DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, muleContext); MuleMessage response = client.send("http://localhost:" + dynamicPort.getNumber() + "/resources/move", muleMessage); assertEquals(HTTP_BODY, response.getPayloadAsString()); assertEquals( "" + HttpConstants.SC_MOVED_PERMANENTLY, response.getInboundProperty("http.status")); assertEquals( "http://localhost:9090/resources/moved", response.<Object>getInboundProperty("Location")); }
protected void assertAllProcessingAsync(MuleMessage result) { assertNotNull(result); String receiverThread = result.getInboundProperty("receiver-thread"); String flowThread = result.getInboundProperty("processor-thread"); String dispatcherThread = result.getInboundProperty("dispatcher-thread"); assertTrue(receiverThread.startsWith("vm.receiver")); assertFalse(receiverThread.equals(flowThread)); assertFalse(flowThread.equals(dispatcherThread)); assertFalse(receiverThread.equals(dispatcherThread)); }
@Override public Object transformMessage(final MuleMessage message, final String outputEncoding) throws TransformerException { BaseNodeRq nodeRq = null; // create the context. TransformContext context = new TransformContext(); message.setProperty("txContext", context, PropertyScope.SESSION); String contentType = message.getInboundProperty("Content-Type"); if (contentType != null && contentType.contains("multipart/form-data")) { // transform the multipart request to node Node node = httpMultipartTransformer.transformMessage(message); // run the transform. nodeRq = this.httpRqToNodeRq.transform(context, node); } else if (message.getProperty("http.request", PropertyScope.INBOUND) != null) { // adapt the http request String muleQueryString = (String) message.getProperty("http.request", PropertyScope.INBOUND); HttpRequestAdapter httpRequest = new HttpRequestAdapter(muleQueryString); // run the transform. nodeRq = this.httpRqToNodeRq.transform(context, httpRequest); } return nodeRq; }
@Test public void mapsToHelloWorldException() throws Exception { LocalMuleClient client = muleContext.getClient(); MuleMessage result = client.send( "http://localhost:" + port.getNumber() + "/helloworld/throwException", getTestMuleMessage(), getHttpOptions()); assertEquals( (Integer) HttpConstants.SC_SERVICE_UNAVAILABLE, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0)); }
@Test public void testHttpResponseError() throws Exception { MuleClient client = new MuleClient(muleContext); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("errorMessage", "ERROR !!!! "); DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, properties, muleContext); MuleMessage response = client.send( "http://localhost:" + dynamicPort.getNumber() + "/resources/error", muleMessage, properties); assertTrue(response.getPayloadAsString().contains("ERROR !!!!")); assertEquals( "" + HttpConstants.SC_INTERNAL_SERVER_ERROR, response.getInboundProperty("http.status")); }
@Test public void testHttpResponseAll() throws Exception { MuleClient client = new MuleClient(muleContext); DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, muleContext); MuleMessage response = client.send("http://localhost:" + dynamicPort.getNumber() + "/resources/all", muleMessage); assertEquals("Custom body", response.getPayloadAsString()); assertEquals("" + HttpConstants.SC_NOT_FOUND, response.getInboundProperty("http.status")); assertEquals( "public,no-cache,must-revalidate,max-age=3600,no-transform", response.getInboundProperty("Cache-Control")); assertEquals("Thu, 01 Dec 2014 16:00:00 GMT", response.getInboundProperty("Expires")); assertEquals("http://localhost:9090", response.getInboundProperty("Location")); assertEquals("value1", response.getInboundProperty("header1")); Cookie[] cookies = (Cookie[]) response.getInboundProperty("Set-Cookie"); assertEquals(2, cookies.length); validateCookie(cookies[0]); validateCookie(cookies[1]); }
@Test public void testHttpResponseAllWithExpressions() throws Exception { MuleClient client = new MuleClient(muleContext); Map<String, Object> properties = populateProperties(); DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, properties, muleContext); MuleMessage response = client.send( "http://localhost:" + dynamicPort.getNumber() + "/resources/allExpressions", muleMessage, properties); assertEquals("" + HttpConstants.SC_NOT_FOUND, response.getInboundProperty("http.status")); assertEquals("max-age=3600", response.getInboundProperty("Cache-Control")); assertEquals("Thu, 01 Dec 2014 16:00:00 GMT", response.getInboundProperty("Expires")); assertEquals("http://localhost:9090", response.getInboundProperty("Location")); assertEquals("value1", response.getInboundProperty("header1")); Cookie[] cookies = (Cookie[]) response.getInboundProperty("Set-Cookie"); assertEquals(2, cookies.length); validateCookie(cookies[0]); validateCookie(cookies[1]); }
protected void assertAllProcessingInClientThread(MuleMessage result) { assertSync(result); assertEquals(Thread.currentThread().getName(), result.getInboundProperty("receiver-thread")); }
protected void assertAllProcessingInRecieverThread(MuleMessage result) { assertSync(result); assertTrue(((String) result.getInboundProperty("receiver-thread")).startsWith("vm.receiver")); }