View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.ibeans.annotations;
8   
9   import org.mule.api.MuleMessage;
10  
11  import org.ibeans.annotation.IntegrationBean;
12  import org.ibeans.api.Response;
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.assertNotNull;
17  
18  public class ParamFactoryTestCase extends AbstractIBeansTestCase
19  {
20      @IntegrationBean
21      private TestParamsFactoryIBean testIBean;
22  
23      @Test
24      public void testUriParamsOnMethod() throws Exception
25      {
26          testIBean.init("shhh".getBytes());
27  
28          String result = testIBean.doMethodUriParam("secret", new FirstParamFactory());
29          assertNotNull(result);
30          assertEquals("The key is shhh for secret. Param2 is: 'shhh secret'", result);
31      }
32  
33      @Test
34      public void testParamsFieldOrdering() throws Exception
35      {
36          testIBean.init("shhh".getBytes());
37  
38          String result = testIBean.doUriParams("secret");
39          assertNotNull(result);
40          assertEquals("The key is shhh for secret. Param2 is: 'shhh secret'", result);
41      }
42  
43      @Test
44      public void testHeaderParams() throws Exception
45      {
46          testIBean.init("shhh".getBytes());
47  
48          MuleMessage result = testIBean.doHeaderParam("secret");
49          assertNotNull(result);
50          assertEquals("Value is: secret", result.getPayloadAsString());
51          //TODO switch inbound/outbound depending on logic in HttpMessageFactory
52          assertEquals("shhh", result.getInboundProperty("header1"));
53          assertEquals("shhh secret", result.getInboundProperty("header2"));
54      }
55  
56      @Test
57      public void testHeaderParamsOnMethod() throws Exception
58      {
59          testIBean.init("shhh".getBytes());
60  
61          MuleMessage result = testIBean.doMethodHeaderParam("secret", new EchoParamFactory());
62          assertNotNull(result);
63          assertEquals("Value is: secret", result.getPayloadAsString());
64          assertEquals("shhh", result.getInboundProperty("header1"));
65          assertEquals("shhh secret", result.getInboundProperty("header2"));
66          assertEquals("echoHeader", result.getInboundProperty("echoHeader"));
67      }
68  
69      @Test
70      public void testPropertyParamsOnMethod() throws Exception
71      {
72          testIBean.init("shhh".getBytes());
73  
74          MuleMessage result = testIBean.doMethodPropertyParam("secret", "hello", new ReversePropertyParamFactory("customProperty"));
75          assertNotNull(result);
76          assertEquals("Value is: secret", result.getPayloadAsString());
77          assertEquals("shhh", result.getInboundProperty("header1"));
78          assertEquals("shhh secret", result.getInboundProperty("header2"));
79          assertEquals("olleh", result.getInboundProperty("propHeader"));
80      }
81  
82      @Test
83      public void testHeadersWithNoParams() throws Exception
84      {
85          testIBean.init("shhh".getBytes());
86          MuleMessage result = testIBean.doTestHeadersWithNoParams();
87          assertNotNull(result);
88          assertEquals("shhh", result.getInboundProperty("header1"));
89      }
90  
91      @Test
92      public void testHeaderParamsAndResponse() throws Exception
93      {
94          testIBean.init("shhh".getBytes());
95  
96          Response result = testIBean.doHeaderParamAndResponse("secret");
97          assertNotNull(result);
98          assertEquals("Value is: secret", result.getPayload());
99          assertEquals("shhh", result.getHeader("header1"));
100         assertEquals("shhh secret", result.getHeader("header2"));
101     }
102 
103     @Test
104     public void testHeaderParamsOnMethodAndResponse() throws Exception
105     {
106         testIBean.init("shhh".getBytes());
107 
108         Response result = testIBean.doMethodHeaderParamAndResponse("secret", new EchoParamFactory());
109         assertNotNull(result);
110         assertEquals("Value is: secret", result.getPayload());
111         assertEquals("shhh", result.getHeader("header1"));
112         assertEquals("shhh secret", result.getHeader("header2"));
113         assertEquals("echoHeader", result.getHeader("echoHeader"));
114     }
115 
116     @Test
117     public void testPropertyParamsOnMethodAndResponse() throws Exception
118     {
119         testIBean.init("shhh".getBytes());
120 
121         Response result = testIBean.doMethodPropertyParamAndResponse("secret", "hello", new ReversePropertyParamFactory("customProperty"));
122         assertNotNull(result);
123         assertEquals("Value is: secret", result.getPayload());
124         assertEquals("shhh", result.getHeader("header1"));
125         assertEquals("shhh secret", result.getHeader("header2"));
126         assertEquals("olleh", result.getHeader("propHeader"));
127     }
128 
129     @Test
130     public void testHeadersWithNoParamsAndResponse() throws Exception
131     {
132         testIBean.init("shhh".getBytes());
133         Response result = testIBean.doTestHeadersWithNoParamsAndResponse();
134         assertNotNull(result);
135         assertEquals("shhh", result.getHeader("header1"));
136     }
137 }