View Javadoc

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