View Javadoc

1   /*
2    * $Id: IBeansEndpointTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.ibeans;
12  
13  import org.mule.api.endpoint.EndpointURI;
14  import org.mule.api.endpoint.MalformedEndpointException;
15  import org.mule.api.lifecycle.InitialisationException;
16  import org.mule.endpoint.MuleEndpointURI;
17  import org.mule.tck.AbstractMuleTestCase;
18  
19  public class IBeansEndpointTestCase extends AbstractMuleTestCase
20  {
21      public void testValidEndpointURI() throws Exception
22      {
23          EndpointURI uri = new MuleEndpointURI("ibean://hostip.getHostInfo", muleContext);
24          uri.initialise();
25          assertEquals("ibean", uri.getScheme());
26          assertEquals("hostip.getHostInfo", uri.getAddress());
27          assertEquals(0, uri.getParams().size());
28          assertEquals("ibean://hostip.getHostInfo", uri.toString());
29      }
30  
31      public void testValidEndpointURIWithParams() throws Exception
32      {
33          EndpointURI uri = new MuleEndpointURI("ibean://hostip.getHostInfo?param1=value1", muleContext);
34          uri.initialise();
35          assertEquals("ibean", uri.getScheme());
36          assertEquals("hostip.getHostInfo", uri.getAddress());
37          assertEquals(1, uri.getParams().size());
38          assertEquals("value1", uri.getParams().get("param1"));
39          assertEquals("ibean://hostip.getHostInfo?param1=value1", uri.toString());
40  
41      }
42  
43      public void testMissingIBeanEndpointURI() throws Exception
44      {
45          try
46          {
47              EndpointURI uri = new MuleEndpointURI("ibean://foo.getBar", muleContext);
48              uri.initialise();
49              fail("IBean foo is not on the classpath");
50          }
51          catch (InitialisationException e)
52          {
53              //Expected
54              assertTrue(e.getCause() instanceof MalformedEndpointException);
55          }
56      }
57  
58      public void testBanIBeanMethodEndpointURI() throws Exception
59      {
60          try
61          {
62              EndpointURI uri = new MuleEndpointURI("ibean://hostip.getBar", muleContext);
63              uri.initialise();
64              fail("IBean hostip does not have a method called getBar");
65          }
66          catch (InitialisationException e)
67          {
68              //Expected
69              assertTrue(e.getCause() instanceof MalformedEndpointException);
70          }
71      }
72  }