1
2
3
4
5
6
7
8
9
10 package org.mule.module.ibeans.annotations;
11
12
13 import org.mule.module.ibeans.HostIpIBean;
14 import org.mule.module.xml.util.XMLUtils;
15
16 import org.ibeans.annotation.MockIntegrationBean;
17 import org.ibeans.api.CallException;
18 import org.junit.Test;
19 import org.w3c.dom.Document;
20
21 import static org.mockito.Mockito.when;
22
23 public class MockIBeanTestCase extends AbstractIBeansTestCase
24 {
25 public static final String GOOD_IP = "12.215.42.19";
26 public static final String BAD_IP = "12.215.42.";
27
28 @SuppressWarnings("unused")
29 @MockIntegrationBean
30 private HostIpIBean hostip;
31
32 @Test
33 public void testSuccessfulHostipLookup() throws Exception
34 {
35 hostip.init(Document.class);
36 when(hostip.getHostInfo(GOOD_IP)).thenAnswer(withXmlData("mock/hostip-found-response.xml", hostip));
37
38 Document result = hostip.getHostInfo(GOOD_IP);
39 String loc = XMLUtils.selectValue("//*[local-name()='coordinates']", result);
40 assertEquals("-88.4588,41.7696", loc);
41 }
42
43
44
45
46
47
48
49
50
51
52
53 @Test(expected = CallException.class)
54 public void testUnsuccessfulHostipLookup() throws Exception
55 {
56 try
57 {
58
59
60 hostip.init(String.class);
61 when(hostip.getHostInfo(BAD_IP)).thenAnswer(withXmlData("mock/hostip-not-found-response.xml", hostip));
62
63 hostip.getHostInfo(BAD_IP);
64 fail("The iBean should have recognised a Bad ip");
65 }
66 catch (CallException e)
67 {
68
69 }
70 }
71
72 @Test
73 public void testTemplateMethod() throws Exception
74 {
75 String result = hostip.dummyTemplateMethod("three");
76 assertEquals("one two three", result);
77 }
78 }