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.Ignore;
19 import org.junit.Test;
20 import org.w3c.dom.Document;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.Mockito.when;
25
26 public class MockIBeanTestCase extends AbstractIBeansTestCase
27 {
28
29 public static final String GOOD_IP = "12.215.42.19";
30 public static final String BAD_IP = "12.215.42.";
31
32 @MockIntegrationBean
33 private HostIpIBean hostip;
34
35 @Test
36 public void testSuccessfulHostipLookup() throws Exception
37 {
38 hostip.init(Document.class);
39 when(hostip.getHostInfo(GOOD_IP)).thenAnswer(withXmlData("mock/hostip-found-response.xml", hostip));
40
41 Document result = hostip.getHostInfo(GOOD_IP);
42 String loc = XMLUtils.selectValue("//*[local-name()='coordinates']", result);
43 assertEquals("-88.4588,41.7696", loc);
44 }
45
46 @Ignore
47 @Test
48 public void testSuccessfulHostipLookupWithReturn() throws Exception
49 {
50 hostip.init(Document.class);
51 when(hostip.hasIp(GOOD_IP)).thenAnswer(withXmlData("mock/hostip-found-response.xml", hostip));
52 when(hostip.hasIp(GOOD_IP)).thenAnswer(withXmlData("mock/hostip-found-response.xml", hostip));
53
54 assertTrue(hostip.hasIp(GOOD_IP));
55 }
56
57 @Test(expected = CallException.class)
58 public void testUnsuccessfulHostipLookup() throws Exception
59 {
60
61
62 hostip.init(String.class);
63 when(hostip.getHostInfo(BAD_IP)).thenAnswer(withXmlData("mock/hostip-not-found-response.xml", hostip));
64
65 hostip.getHostInfo(BAD_IP);
66 }
67
68 @Test
69 public void testTemplateMethod() throws Exception
70 {
71 String result = hostip.dummyTemplateMethod("three");
72 assertEquals("one two three", result);
73 }
74 }