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