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