forked from genjosanzo/mule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sanity check, added tests for an external ibean (Flickr), removed the…
… IBean message.receiver since it hasn't been tested and will need some work git-svn-id: https://svn.codehaus.org/mule/branches/mule-3.x@19461 bf997673-6b11-0410-b953-e057580c5b09
- Loading branch information
Showing
4 changed files
with
228 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
modules/ibeans/src/test/java/org/mule/module/ibeans/FlickrSearchTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* $Id: FlickrSearchTestCase.java 148 2010-02-17 07:59:42Z ross $ | ||
* -------------------------------------------------------------------------------------- | ||
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | ||
* | ||
* The software in this package is published under the terms of the CPAL v1.0 | ||
* license, a copy of which has been included with this distribution in the | ||
* LICENSE.txt file. | ||
*/ | ||
package org.mule.module.ibeans; | ||
|
||
import org.mule.ibeans.flickr.FlickrIBean; | ||
import org.mule.ibeans.flickr.FlickrSearchIBean; | ||
import org.mule.module.json.JsonData; | ||
import org.mule.tck.AbstractMuleTestCase; | ||
|
||
import org.codehaus.jackson.node.ArrayNode; | ||
import org.ibeans.annotation.IntegrationBean; | ||
import org.ibeans.api.CallException; | ||
import org.w3c.dom.Document; | ||
|
||
/** | ||
* This tests that we can use the FlickrSearch iBean without needing a 'secret_key' which is required for other | ||
* parts of the Flickr API | ||
*/ | ||
public class FlickrSearchTestCase extends AbstractMuleTestCase | ||
{ | ||
public static final String SEARCH_TERM = "food"; | ||
public static final String BAD_SEARCH_TERM = "bad"; | ||
|
||
@IntegrationBean | ||
private FlickrSearchIBean flickr; | ||
|
||
public FlickrSearchTestCase() | ||
{ | ||
setStartContext(true); | ||
} | ||
|
||
@Override | ||
protected void doSetUp() throws Exception | ||
{ | ||
//Add the test case so that the IntegrationBean DI will be processed | ||
muleContext.getRegistry().registerObject("test", this); | ||
//getFlickr().init("${flickr.api.key}","${flickr.secret.key}", FlickrIBean.FORMAT.XML, Document.class); | ||
getFlickr().init("3a690a103c6eabf55de5b10623021a34", FlickrIBean.FORMAT.JSON, JsonData.class); | ||
|
||
} | ||
|
||
protected FlickrSearchIBean getFlickr() | ||
{ | ||
return flickr; | ||
} | ||
|
||
public void testFlickrSearch() throws Exception | ||
{ | ||
JsonData doc = getFlickr().search(SEARCH_TERM); | ||
assertNotNull(doc); | ||
assertEquals(10, ((ArrayNode) doc.get("/photos/photo")).size()); | ||
} | ||
|
||
//This will fail since "badkey" is not a recognised key | ||
public void testFlickrError() throws Exception | ||
{ | ||
getFlickr().init("badkey", FlickrIBean.FORMAT.XML, Document.class); | ||
|
||
try | ||
{ | ||
getFlickr().search(BAD_SEARCH_TERM); | ||
} | ||
catch (CallException e) | ||
{ | ||
//Flickr error code | ||
assertEquals("100", e.getErrorCode()); | ||
} | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
modules/ibeans/src/test/java/org/mule/module/ibeans/FlickrTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* $Id: FlickrTestCase.java 148 2010-02-17 07:59:42Z ross $ | ||
* -------------------------------------------------------------------------------------- | ||
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | ||
* | ||
* The software in this package is published under the terms of the CPAL v1.0 | ||
* license, a copy of which has been included with this distribution in the | ||
* LICENSE.txt file. | ||
*/ | ||
package org.mule.module.ibeans; | ||
|
||
import org.mule.ibeans.flickr.FlickrIBean; | ||
import org.mule.ibeans.flickr.FlickrTransformers; | ||
import org.mule.tck.AbstractMuleTestCase; | ||
|
||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.ibeans.annotation.IntegrationBean; | ||
import org.ibeans.api.CallException; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
|
||
import static org.mule.ibeans.IBeansSupport.prettyPrintXml; | ||
import static org.mule.ibeans.IBeansSupport.select; | ||
|
||
public class FlickrTestCase extends AbstractMuleTestCase | ||
{ | ||
public static final String SEARCH_TERM = "food"; | ||
public static final String BAD_SEARCH_TERM = "bad"; | ||
|
||
@IntegrationBean | ||
private FlickrIBean flickr; | ||
|
||
public FlickrTestCase() | ||
{ | ||
setStartContext(true); | ||
} | ||
|
||
@Override | ||
protected void doSetUp() throws Exception | ||
{ | ||
//Add the test case so that the IntegrationBean DI will be processed | ||
muleContext.getRegistry().registerObject("test", this); | ||
//No classpath scanning is during for tests so we have to register the Flickr Transformers manually | ||
muleContext.getRegistry().registerObject("flickrTransformers", new FlickrTransformers()); | ||
//getFlickr().init("${flickr.api.key}","${flickr.secret.key}", FlickrIBean.FORMAT.XML, Document.class); | ||
getFlickr().init("3a690a103c6eabf55de5b10623021a34","1d3d4a305cc369fc", FlickrIBean.FORMAT.XML, Document.class); | ||
} | ||
|
||
protected FlickrIBean getFlickr() | ||
{ | ||
return flickr; | ||
} | ||
|
||
public void testFlickrSearch() throws Exception | ||
{ | ||
Document doc = getFlickr().search(SEARCH_TERM); | ||
assertNotNull(doc); | ||
List<URL> photoUrls = new ArrayList<URL>(); | ||
|
||
for (Node n : select("//photo", doc)) | ||
{ | ||
photoUrls.add(getFlickr().getPhotoURL(n)); | ||
} | ||
|
||
assertEquals(10, photoUrls.size()); | ||
} | ||
|
||
//This will fail since "badkey" is not a recognised key | ||
public void testFlickrError() throws Exception | ||
{ | ||
getFlickr().init("badkey", FlickrIBean.FORMAT.XML, Document.class); | ||
|
||
try | ||
{ | ||
getFlickr().search(BAD_SEARCH_TERM); | ||
} | ||
catch (CallException e) | ||
{ | ||
//Flickr error code | ||
assertEquals("100", e.getErrorCode()); | ||
} | ||
} | ||
|
||
public void testSizeEnum() throws Exception | ||
{ | ||
assertEquals("o", FlickrIBean.IMAGE_SIZE.Original.toString()); | ||
assertEquals("m", FlickrIBean.DEFAULT_IMAGE_SIZE.toString()); | ||
assertEquals(FlickrIBean.IMAGE_SIZE.Original, Enum.valueOf(FlickrIBean.IMAGE_SIZE.class, "Original")); | ||
|
||
Document doc = getFlickr().search(SEARCH_TERM); | ||
|
||
assertNotNull(doc); | ||
List<URL> photoUrls = new ArrayList<URL>(); | ||
|
||
System.out.println(prettyPrintXml(doc)); | ||
for (Node n : select("//photo", doc)) | ||
{ | ||
photoUrls.add(getFlickr().getPhotoURL(n, FlickrIBean.IMAGE_SIZE.SmallSquare, FlickrIBean.IMAGE_TYPE.Jpeg)); | ||
} | ||
assertEquals(10, photoUrls.size()); | ||
assertTrue(photoUrls.get(0).toString().endsWith("_s.jpg")); | ||
} | ||
|
||
//TODO | ||
// @Test | ||
// public void testAuth() throws Exception | ||
// { | ||
// String frob = getFlickr().getFrob(); | ||
// assertNotNull(frob); | ||
// URL url = getFlickr().buildAuthenticationURL(frob, "delete"); | ||
// //Just make sure it works | ||
// assertNotNull(url); | ||
// //We can't generate a an authToken automatically as it requries the account owner to give iBeans access | ||
// //but we can check the validity of an existing auth token | ||
// //TODO URGENT can't use a placeholder value here for some reason | ||
// AuthToken auth = getFlickr().checkAuthToken((String)iBeansContext.getConfig().get("flickr.auth.token")); | ||
// assertNotNull(auth); | ||
// assertEquals("delete", auth.getPerms()); | ||
// assertEquals("rossmason", auth.getUser().getUsername()); | ||
// } | ||
|
||
//TODO upload not working yet, suspect it has something to do with the way form-data is handled | ||
// public void testUpload() throws Exception | ||
// { | ||
// URL url = new URL("file:///projects/ibeans-contrib/twitter/src/test/resources/profile.png"); | ||
// String result = getFlickr().upload(url, get("flickr.auth.token"), "Test 1", null, null, null, null, null); | ||
// System.out.println(result); | ||
// } | ||
} |