1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.http.components;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15
16 import org.mule.api.MuleMessage;
17 import org.mule.component.ComponentException;
18 import org.mule.module.client.MuleClient;
19 import org.mule.tck.AbstractServiceAndFlowTestCase;
20 import org.mule.tck.junit4.rule.DynamicPort;
21
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.runners.Parameterized.Parameters;
30
31 public class RestServiceWrapperFunctionalTestCase extends AbstractServiceAndFlowTestCase
32 {
33 protected static String TEST_REQUEST = "Test Http Request";
34
35 @Rule
36 public DynamicPort dynamicPort = new DynamicPort("port1");
37
38 public RestServiceWrapperFunctionalTestCase(ConfigVariant variant, String configResources)
39 {
40 super(variant, configResources);
41 }
42
43 @Parameters
44 public static Collection<Object[]> parameters()
45 {
46 return Arrays.asList(new Object[][]{
47 {ConfigVariant.SERVICE, "http-rest-service-wrapper-functional-test-service.xml"},
48 {ConfigVariant.FLOW, "http-rest-service-wrapper-functional-test-flow.xml"}
49 });
50 }
51
52 @Test
53 public void testErrorExpressionOnRegexFilterFail() throws Exception
54 {
55 MuleMessage result = muleContext.getClient().send("restServiceEndpoint", TEST_REQUEST, null);
56 assertNotNull(result);
57 assertNotNull(result.getExceptionPayload());
58 assertEquals(RestServiceException.class, result.getExceptionPayload().getException().getClass());
59 }
60
61 @Test
62 public void testErrorExpressionOnRegexFilterPass() throws Exception
63 {
64 MuleClient client = new MuleClient(muleContext);
65 MuleMessage result = client.send("restServiceEndpoint2", TEST_REQUEST, null);
66 assertEquals("echo=" + TEST_REQUEST,result.getPayloadAsString());
67 }
68
69 @Test
70 public void testRequiredParameters() throws Exception
71 {
72 MuleClient client = new MuleClient(muleContext);
73 Map<String, Object> props = new HashMap<String, Object>();
74 props.put("baz-header", "baz");
75 props.put("bar-optional-header", "bar");
76 MuleMessage result = client.send("restServiceEndpoint3", null, props);
77 assertEquals("foo=boo&faz=baz&far=bar",result.getPayloadAsString());
78 }
79
80 @Test
81 public void testOptionalParametersMissing() throws Exception
82 {
83 MuleClient client = new MuleClient(muleContext);
84 Map<String, Object> props = new HashMap<String, Object>();
85 props.put("baz-header", "baz");
86 MuleMessage result = client.send("restServiceEndpoint3", null, props);
87 assertEquals("foo=boo&faz=baz",result.getPayloadAsString());
88 }
89
90 @Test
91 public void testRequiredParametersMissing() throws Exception
92 {
93 Map<String, Object> props = new HashMap<String, Object>();
94
95 MuleMessage result = muleContext.getClient().send("restServiceEndpoint3", null, props);
96 assertNotNull(result);
97 assertNotNull(result.getExceptionPayload());
98 assertEquals(ComponentException.class, result.getExceptionPayload().getException().getClass());
99 }
100
101 @Test
102 public void testRestServiceComponentInFlow() throws Exception
103 {
104 MuleClient client = new MuleClient(muleContext);
105
106 MuleMessage result = client.send("vm://toFlow", TEST_REQUEST, null);
107 assertNotNull(result);
108 assertEquals("echo=Test Http Request", result.getPayloadAsString());
109 }
110
111 }