1   /*
2    * $Id: XfireWsSecurityOnOutboundTestCase.java 10165 2007-12-28 11:34:33Z marie.rizzo $ 
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
11  package org.mule.extras.wssecurity.testcases;
12  
13  import org.mule.extras.client.MuleClient;
14  import org.mule.tck.FunctionalTestCase;
15  import org.mule.umo.UMOMessage;
16  
17  import java.util.Properties;
18  
19  import org.apache.ws.security.handler.WSHandlerConstants;
20  
21  public class XfireWsSecurityOnOutboundTestCase extends FunctionalTestCase
22  {
23      public void testGoodUserNameTokenAuthentication () throws Exception
24      {
25          MuleClient client = new MuleClient();
26          Properties props = new Properties();
27  
28          // User name to send
29          props.setProperty(WSHandlerConstants.USER, "gooduser");
30  
31          UMOMessage m = client.send("vm://testin", "Test", props);
32          assertNotNull(m);
33          assertTrue(m.getPayload() instanceof String);
34          assertTrue(m.getPayload().equals("Test"));
35      }
36  
37      public void testBadUserNameTokenAuthentication () throws Exception
38      {
39          MuleClient client = new MuleClient();
40          Properties props = new Properties();
41  
42          // User name to send
43          props.setProperty(WSHandlerConstants.USER, "baduser");
44  
45          UMOMessage m = null;
46          try
47          {
48              m = client.send("vm://testin", "Test", props);
49          }
50          catch (Exception e)
51          {
52              assertNotNull(e);
53          }
54          assertNull(m);
55      }
56  
57      public void testGoodUserNameEncrypted () throws Exception
58      {
59          MuleClient client = new MuleClient();
60          Properties props = new Properties();
61  
62          // User name to send
63          props.setProperty(WSHandlerConstants.USER, "mulealias");
64  
65          UMOMessage m = client.send("vm://testin2", "Test", props);
66          assertNotNull(m);
67          assertTrue(m.getPayload() instanceof String);
68          assertTrue(m.getPayload().equals("Test"));
69      }
70  
71      public void testBadUserNameEncrypted () throws Exception
72      {
73          MuleClient client = new MuleClient();
74          Properties props = new Properties();
75  
76          // User name to send
77          props.setProperty(WSHandlerConstants.USER, "myBadAlias");
78  
79          UMOMessage m = null;
80          try
81          {
82              m = client.send("vm://testin2", "Test", props);
83          }
84          catch (Exception e)
85          {
86              assertNotNull(e);
87          }
88          assertNull(m);
89      }
90  
91      public void testSignedSoapMessage () throws Exception
92      {
93          MuleClient client = new MuleClient();
94          Properties props = new Properties();
95  
96          // User in keystore
97          props.setProperty(WSHandlerConstants.USER, "mulealias");
98  
99          UMOMessage m = client.send("vm://testin3", "Test", props);
100         assertNotNull(m);
101         assertTrue(m.getPayload() instanceof String);
102         assertTrue(m.getPayload().equals("Test"));
103     }
104 
105     protected String getConfigResources ()
106     {
107         return "wssecurity-mule-config-for-outbound.xml";
108     }
109 }