1
2
3
4
5
6
7 package org.mule.module.ibeans;
8
9 import org.mule.ibeans.flickr.FlickrIBean;
10 import org.mule.ibeans.flickr.FlickrSearchIBean;
11 import org.mule.module.json.JsonData;
12 import org.mule.tck.junit4.AbstractMuleContextTestCase;
13
14 import org.codehaus.jackson.node.ArrayNode;
15 import org.ibeans.annotation.IntegrationBean;
16 import org.ibeans.api.CallException;
17 import org.junit.Test;
18 import org.w3c.dom.Document;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22
23
24
25
26
27 public class FlickrSearchTestCase extends AbstractMuleContextTestCase
28 {
29 public static final String SEARCH_TERM = "food";
30 public static final String BAD_SEARCH_TERM = "bad";
31
32 @IntegrationBean
33 private FlickrSearchIBean flickr;
34
35 public FlickrSearchTestCase()
36 {
37 setStartContext(true);
38 }
39
40 @Override
41 protected void doSetUp() throws Exception
42 {
43
44 muleContext.getRegistry().registerObject("test", this);
45
46 getFlickr().init("3a690a103c6eabf55de5b10623021a34", FlickrIBean.FORMAT.JSON, JsonData.class);
47
48 }
49
50 protected FlickrSearchIBean getFlickr()
51 {
52 return flickr;
53 }
54
55 @Test
56 public void testFlickrSearch() throws Exception
57 {
58 JsonData doc = getFlickr().search(SEARCH_TERM);
59 assertNotNull(doc);
60 assertEquals(10, ((ArrayNode) doc.get("/photos/photo")).size());
61 }
62
63
64 @Test
65 public void testFlickrError() throws Exception
66 {
67 getFlickr().init("badkey", FlickrIBean.FORMAT.XML, Document.class);
68
69 try
70 {
71 getFlickr().search(BAD_SEARCH_TERM);
72 }
73 catch (CallException e)
74 {
75
76 assertEquals("100", e.getErrorCode());
77 }
78 }
79 }