1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.ejb;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.mule.api.MuleMessage;
18 import org.mule.api.endpoint.EndpointBuilder;
19 import org.mule.api.endpoint.OutboundEndpoint;
20 import org.mule.api.transport.DispatchException;
21 import org.mule.endpoint.EndpointURIEndpointBuilder;
22 import org.mule.module.client.MuleClient;
23 import org.mule.transport.AbstractFunctionalTestCase;
24 import org.mule.transport.rmi.RmiConnector;
25
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.Properties;
29
30 import org.junit.runners.Parameterized.Parameters;
31
32
33
34
35 public class EjbFunctionalTestCase extends AbstractFunctionalTestCase
36 {
37 public EjbFunctionalTestCase(ConfigVariant variant, String configResources)
38 {
39 super(variant, configResources);
40 this.prefix = "ejb";
41 }
42
43 @Parameters
44 public static Collection<Object[]> parameters()
45 {
46 return Arrays.asList(new Object[][]{
47 {ConfigVariant.SERVICE, "ejb-functional-test-service.xml"},
48 {ConfigVariant.FLOW, "ejb-functional-test-flow.xml"}
49 });
50 }
51
52 @Override
53 public void testCase() throws Exception
54 {
55 MuleClient client = new MuleClient(muleContext);
56 MuleMessage result = client.send("vm://in", "1234567890", null);
57 assertNotNull(result);
58 assertEquals("0987654321", result.getPayloadAsString());
59 }
60
61 @Override
62 public void testBadMethodType() throws Exception
63 {
64
65
66 EndpointBuilder builder = new EndpointURIEndpointBuilder("ejb://localhost/TestService?method=reverseString",
67 muleContext);
68 Properties props = new Properties();
69 props.put(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES, StringBuffer.class.getName());
70 builder.setProperties(props);
71
72 OutboundEndpoint ep = muleContext.getEndpointFactory().getOutboundEndpoint(
73 builder);
74 try
75 {
76 ep.process(getTestEvent("hello"));
77 }
78 catch (Exception e)
79 {
80 assertTrue(e instanceof DispatchException);
81 assertTrue(e.getCause() instanceof NoSuchMethodException);
82 }
83 }
84
85 @Override
86 public void testCorrectMethodType() throws Exception
87 {
88
89
90 EndpointBuilder builder = new EndpointURIEndpointBuilder("ejb://localhost/TestService?method=reverseString",
91 muleContext);
92 Properties props = new Properties();
93 props.put(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES, String.class.getName());
94 builder.setProperties(props);
95
96 OutboundEndpoint ep = muleContext.getEndpointFactory().getOutboundEndpoint(
97 builder);
98
99 try
100 {
101 ep.process(getTestEvent("hello"));
102 }
103 catch (Exception e)
104 {
105 assertTrue(e instanceof DispatchException);
106 assertTrue(e.getCause() instanceof NoSuchMethodException);
107 }
108 }
109
110 }