View Javadoc

1   /*
2    * $Id: ParamFactoryTestCase.java 19026 2010-08-16 07:30:47Z 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  public class ParamFactoryTestCase extends AbstractIBeansTestCase
19  {
20      @SuppressWarnings("unused")
21      @IntegrationBean
22      private TestParamsFactoryIBean testIBean;
23  
24      @Test
25      public void testUriParamsOnMethod() throws Exception
26      {
27          testIBean.init("shhh".getBytes());
28  
29          String result = testIBean.doMethodUriParam("secret", new FirstParamFactory());
30          assertNotNull(result);
31          assertEquals("The key is shhh for secret. Param2 is: 'shhh secret'", result);
32      }
33  
34      @Test
35      public void testParamsFieldOrdering() throws Exception
36      {
37          testIBean.init("shhh".getBytes());
38  
39          String result = testIBean.doUriParams("secret");
40          assertNotNull(result);
41          assertEquals("The key is shhh for secret. Param2 is: 'shhh secret'", result);
42      }
43  
44      @Test
45      public void testHeaderParams() throws Exception
46      {
47          testIBean.init("shhh".getBytes());
48  
49          MuleMessage result = testIBean.doHeaderParam("secret");
50          assertNotNull(result);
51          assertEquals("Value is: secret", result.getPayloadAsString());
52          //TODO switch inbound/outbound depending on logic in HttpMessageFactory
53          assertEquals("shhh", result.getInboundProperty("header1"));
54          assertEquals("shhh secret", result.getInboundProperty("header2"));
55      }
56  
57      @Test
58      public void testHeaderParamsOnMethod() throws Exception
59      {
60          testIBean.init("shhh".getBytes());
61  
62          MuleMessage result = testIBean.doMethodHeaderParam("secret", new EchoParamFactory());
63          assertNotNull(result);
64          assertEquals("Value is: secret", result.getPayloadAsString());
65          assertEquals("shhh", result.getInboundProperty("header1"));
66          assertEquals("shhh secret", result.getInboundProperty("header2"));
67          assertEquals("echoHeader", result.getInboundProperty("echoHeader"));
68      }
69  
70      @Test
71      public void testPropertyParamsOnMethod() throws Exception
72      {
73          testIBean.init("shhh".getBytes());
74  
75          MuleMessage result = testIBean.doMethodPropertyParam("secret", "hello", new ReversePropertyParamFactory("customProperty"));
76          assertNotNull(result);
77          assertEquals("Value is: secret", result.getPayloadAsString());
78          assertEquals("shhh", result.getInboundProperty("header1"));
79          assertEquals("shhh secret", result.getInboundProperty("header2"));
80          assertEquals("olleh", result.getInboundProperty("propHeader"));
81      }
82  
83      @Test
84      public void testHeadersWithNoParams() throws Exception
85      {
86          testIBean.init("shhh".getBytes());
87          MuleMessage result = testIBean.doTestHeadersWithNoParams();
88          assertNotNull(result);
89          assertEquals("shhh", result.getInboundProperty("header1"));
90      }
91  
92      @Test
93      public void testHeaderParamsAndResponse() throws Exception
94      {
95          testIBean.init("shhh".getBytes());
96  
97          Response result = testIBean.doHeaderParamAndResponse("secret");
98          assertNotNull(result);
99          assertEquals("Value is: secret", result.getPayload());
100         assertEquals("shhh", result.getHeader("header1"));
101         assertEquals("shhh secret", result.getHeader("header2"));
102     }
103 
104     @Test
105     public void testHeaderParamsOnMethodAndResponse() throws Exception
106     {
107         testIBean.init("shhh".getBytes());
108 
109         Response result = testIBean.doMethodHeaderParamAndResponse("secret", new EchoParamFactory());
110         assertNotNull(result);
111         assertEquals("Value is: secret", result.getPayload());
112         assertEquals("shhh", result.getHeader("header1"));
113         assertEquals("shhh secret", result.getHeader("header2"));
114         assertEquals("echoHeader", result.getHeader("echoHeader"));
115     }
116 
117     @Test
118     public void testPropertyParamsOnMethodAndResponse() throws Exception
119     {
120         testIBean.init("shhh".getBytes());
121 
122         Response result = testIBean.doMethodPropertyParamAndResponse("secret", "hello", new ReversePropertyParamFactory("customProperty"));
123         assertNotNull(result);
124         assertEquals("Value is: secret", result.getPayload());
125         assertEquals("shhh", result.getHeader("header1"));
126         assertEquals("shhh secret", result.getHeader("header2"));
127         assertEquals("olleh", result.getHeader("propHeader"));
128     }
129 
130     @Test
131     public void testHeadersWithNoParamsAndResponse() throws Exception
132     {
133         testIBean.init("shhh".getBytes());
134         Response result = testIBean.doTestHeadersWithNoParamsAndResponse();
135         assertNotNull(result);
136         assertEquals("shhh", result.getHeader("header1"));
137     }
138 
139 }