View Javadoc

1   /*
2    * $Id: EjbFunctionalTestCase.java 20385 2010-11-29 20:25:26Z 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.transport.ejb;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.endpoint.EndpointBuilder;
15  import org.mule.api.endpoint.OutboundEndpoint;
16  import org.mule.api.transport.DispatchException;
17  import org.mule.endpoint.EndpointURIEndpointBuilder;
18  import org.mule.module.client.MuleClient;
19  import org.mule.transport.AbstractFunctionalTestCase;
20  import org.mule.transport.rmi.RmiConnector;
21  
22  import java.util.Properties;
23  
24  /**
25   * test EJB object invocations
26   */
27  public class EjbFunctionalTestCase extends AbstractFunctionalTestCase
28  {
29      public EjbFunctionalTestCase()
30      {
31          super("ejb", "ejb-functional-test.xml");
32      }
33  
34      public void testCase() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37          MuleMessage result = client.send("vm://in", "1234567890", null);
38          assertNotNull(result);
39          assertEquals("0987654321", result.getPayloadAsString());
40      }
41      
42      @Override
43      public void testBadMethodType() throws Exception
44      {
45          // moving this to xml config requires endpoint properties
46          // MULE-1790
47          EndpointBuilder builder = new EndpointURIEndpointBuilder("ejb://localhost/TestService?method=reverseString",
48              muleContext);
49          Properties props = new Properties();
50          props.put(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES, StringBuffer.class.getName());
51          builder.setProperties(props);
52  
53          OutboundEndpoint ep = muleContext.getEndpointFactory().getOutboundEndpoint(
54              builder);
55          try
56          {
57              ep.process(getTestEvent("hello", ep));
58          }
59          catch (Exception e)
60          {
61              assertTrue(e instanceof DispatchException);
62              assertTrue(e.getCause() instanceof NoSuchMethodException);
63          }
64      }
65  
66      @Override
67      public void testCorrectMethodType() throws Exception
68      {
69          // moving this to xml config requires endpoint properties
70          // MULE-1790
71          EndpointBuilder builder = new EndpointURIEndpointBuilder("ejb://localhost/TestService?method=reverseString",
72              muleContext);
73          Properties props = new Properties();
74          props.put(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES, String.class.getName());
75          builder.setProperties(props);
76          
77          OutboundEndpoint ep = muleContext.getEndpointFactory().getOutboundEndpoint(
78              builder);
79          
80          try
81          {
82              ep.process(getTestEvent("hello", ep));
83          }
84          catch (Exception e)
85          {
86              assertTrue(e instanceof DispatchException);
87              assertTrue(e.getCause() instanceof NoSuchMethodException);
88          }
89      }
90  
91  }