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