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