View Javadoc

1   /*
2    * $Id: AuthenticateVmTransportTest.java 22735 2011-08-25 16:02:35Z dfeist $
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  
11  package org.mule.module.spring.security;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertNull;
16  
17  import org.mule.api.MuleMessage;
18  import org.mule.api.security.UnauthorisedException;
19  import org.mule.client.DefaultLocalMuleClient;
20  import org.mule.tck.junit4.FunctionalTestCase;
21  
22  import java.util.HashMap;
23  
24  import org.junit.Test;
25  
26  public class AuthenticateVmTransportTest extends FunctionalTestCase
27  {
28      @Override
29      protected String getConfigResources()
30      {
31          return "auth-vm-transport-config.xml";
32      }
33  
34      @Test
35      public void testExplicitAttributes() throws Exception
36      {
37          testVM("vm://test");
38      }
39  
40      @Test
41      public void testDefaultAttributes() throws Exception
42      {
43          testVM("vm://default-attributes");
44      }
45  
46      protected void testVM(String endpoint) throws Exception
47      {
48          DefaultLocalMuleClient client = new DefaultLocalMuleClient(muleContext);
49  
50          HashMap<String, Object> props = new HashMap<String,Object>();
51          props.put("username", "ross");
52          props.put("password", "ross");
53          MuleMessage result = client.send(endpoint, "hi", props);
54          assertNull(result.getExceptionPayload());
55  
56          props.put("password", "badpass");
57          MuleMessage result2 = client.send(endpoint, "hi", props);
58          assertNotNull(result2);
59          assertNotNull(result2.getExceptionPayload());
60          assertEquals(UnauthorisedException.class, result2.getExceptionPayload().getException().getClass());
61  
62      }
63  }