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.cxf.wssec;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleException;
11  import org.mule.api.MuleMessage;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.junit4.rule.DynamicPort;
15  
16  import java.io.InputStream;
17  
18  import org.junit.Ignore;
19  import org.junit.Rule;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertFalse;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertTrue;
25  
26  public class UsernameTokenProxyTestCase extends FunctionalTestCase 
27  {
28  
29      @Rule
30      public DynamicPort dynamicPort = new DynamicPort("port1");
31      
32      @Override
33      protected String getConfigResources() 
34      {
35          return "org/mule/module/cxf/wssec/cxf-secure-proxy.xml, org/mule/module/cxf/wssec/username-token-conf.xml";
36      }
37  
38      @Override
39      protected void doSetUp() throws Exception
40      {
41          ClientPasswordCallback.setPassword("secret");        
42          super.doSetUp();
43      }
44  
45      @Ignore("MULE-6926: Flaky Test")
46      @Test
47      public void testProxyEnvelope() throws Exception 
48      {
49          MuleMessage result = sendRequest("http://localhost:" + dynamicPort.getNumber() + "/proxy-envelope");
50          System.out.println(result.getPayloadAsString());
51          assertFalse(result.getPayloadAsString().contains("Fault"));
52          assertTrue(result.getPayloadAsString().contains("joe"));
53      }
54  
55      @Test
56      public void testProxyBody() throws Exception
57      {
58          MuleMessage result = sendRequest("http://localhost:" + dynamicPort.getNumber() + "/proxy-body");
59  
60          System.out.println(result.getPayloadAsString());
61          assertFalse(result.getPayloadAsString().contains("Fault"));
62          assertFalse(result.getPayloadAsString().contains("joe"));
63      }
64  
65      protected MuleMessage sendRequest(String url) throws MuleException
66      {
67          MuleClient client = new MuleClient(muleContext);
68  
69          InputStream stream = getClass().getResourceAsStream(getMessageResource());
70          assertNotNull(stream);
71  
72          MuleMessage result = client.send(url, new DefaultMuleMessage(stream, muleContext));
73          return result;
74      }
75  
76      protected String getMessageResource()
77      {
78          return "/org/mule/module/cxf/wssec/in-message.xml";
79      }
80  
81  }