1
2
3
4
5
6
7
8
9
10 package org.mule.module.ibeans;
11
12 import org.mule.api.MuleMessage;
13 import org.mule.api.client.MuleClient;
14 import org.mule.api.transport.DispatchException;
15 import org.mule.module.xml.util.XMLUtils;
16 import org.mule.tck.FunctionalTestCase;
17
18 import org.w3c.dom.Document;
19
20 public class IBeansHostIpFunctionalTestCase extends FunctionalTestCase
21 {
22 public IBeansHostIpFunctionalTestCase()
23 {
24 setDisposeManagerPerSuite(true);
25 }
26
27 @Override
28 protected String getConfigResources()
29 {
30 return "hostip-functional-test.xml";
31 }
32
33
34 public void testHostIp() throws Exception
35 {
36 if (isOffline(getClass().getName() + ".testHostIp"))
37 {
38 return;
39 }
40
41 String ip = "192.215.42.198";
42 MuleClient client = muleContext.getClient();
43 MuleMessage response = client.send("vm://in", ip, null);
44 assertNotNull(response.getPayload());
45 Document result = response.getPayload(Document.class);
46 assertEquals(ip, XMLUtils.selectValue("//ip", result));
47 assertEquals("-117.136,32.8149", XMLUtils.selectValue("//gml:coordinates", result));
48 }
49
50 public void testHostIpFromClient() throws Exception
51 {
52 if (isOffline(getClass().getName() + ".testHostIpFromClient"))
53 {
54 return;
55 }
56
57 String ip = "192.215.42.198";
58 MuleClient client = muleContext.getClient();
59 MuleMessage response = client.send("ibean://hostip.getHostInfo", ip, null);
60 assertNotNull(response.getPayload());
61 Document result = response.getPayload(Document.class);
62 assertEquals(ip, XMLUtils.selectValue("//ip", result));
63 assertEquals("-117.136,32.8149", XMLUtils.selectValue("//gml:coordinates", result));
64 }
65
66 public void testHostIpWrongNumberOfArguments() throws Exception
67 {
68 Object[] params = new Object[]{"192.215.42.198", new Integer(12)};
69 MuleClient client = muleContext.getClient();
70 MuleMessage response = client.send("vm://in", params, null);
71 assertNotNull(response.getExceptionPayload());
72 assertTrue(response.getExceptionPayload().getException() instanceof DispatchException);
73 assertTrue(response.getExceptionPayload().getRootException() instanceof NoSuchMethodException);
74 }
75
76 public void testHostIpBadArgumentType() throws Exception
77 {
78 MuleClient client = muleContext.getClient();
79 MuleMessage response = client.send("vm://in", new StringBuffer(), null);
80 assertNotNull(response.getExceptionPayload());
81 assertTrue(response.getExceptionPayload().getException() instanceof DispatchException);
82 assertTrue(response.getExceptionPayload().getRootException() instanceof NoSuchMethodException);
83 }
84
85 public void testHostIpWrongNumberOfArgumentsDirectClient() throws Exception
86 {
87 Object[] params = new Object[]{"192.215.42.198", new Integer(12)};
88
89 try
90 {
91 muleContext.getClient().send("ibean://hostip.getHostInfo", params, null);
92 fail("Local call should throw exception since there will be no matching method called getHostInfo(String, Integer)");
93 }
94 catch (DispatchException e)
95 {
96 assertTrue(e.getCause() instanceof NoSuchMethodException);
97 }
98 }
99
100 public void testHostIpBadArgumentTypeDirectClient() throws Exception
101 {
102 try
103 {
104 muleContext.getClient().send("ibean://hostip.getHostInfo", new StringBuffer(), null);
105 fail("Local call should throw exception since there will be no matching method called getHostInfo(StringBuffer)");
106 }
107 catch (DispatchException e)
108 {
109 assertTrue(e.getCause() instanceof NoSuchMethodException);
110 }
111 }
112 }