1
2
3
4
5
6
7 package org.mule.module.ibeans.annotations;
8
9
10 import org.mule.module.ibeans.HostIpIBean;
11 import org.mule.module.xml.util.XMLUtils;
12
13 import org.ibeans.annotation.MockIntegrationBean;
14 import org.ibeans.api.CallException;
15 import org.junit.Test;
16 import org.w3c.dom.Document;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.fail;
20 import static org.mockito.Mockito.when;
21
22 public class MockIBeanTestCase extends AbstractIBeansTestCase
23 {
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
57
58 hostip.init(String.class);
59 when(hostip.getHostInfo(BAD_IP)).thenAnswer(withXmlData("mock/hostip-not-found-response.xml", hostip));
60
61 hostip.getHostInfo(BAD_IP);
62 }
63
64 @Test
65 public void testTemplateMethod() throws Exception
66 {
67 String result = hostip.dummyTemplateMethod("three");
68 assertEquals("one two three", result);
69 }
70 }