Skip to content

Commit

Permalink
Sanity check, added tests for an external ibean (Flickr), removed the…
Browse files Browse the repository at this point in the history
… 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
rossmason committed Sep 8, 2010
1 parent 4177792 commit 5abf946
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 1 deletion.
18 changes: 18 additions & 0 deletions modules/ibeans/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<artifactId>mule-module-xml</artifactId>
<version>${version}</version>
</dependency>

<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-json</artifactId>
Expand All @@ -78,6 +79,23 @@
<version>${version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mule.ibeans</groupId>
<artifactId>flickr-ibean</artifactId>
<version>1.0-beta-10-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<!-- this is an ibeans dependency for ibeans core, but for some reason doesn't get
carried through -->
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-xannotations</artifactId>
<version>3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>mockobjects</groupId>
<artifactId>mockobjects-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ message.factory=org.mule.transport.DefaultMuleMessageFactory
dispatcher.factory=org.mule.transport.ibean.IBeansMessageDispatcherFactory

# The standard message receiver used to consume events from the underlying technology
message.receiver=org.mule.transport.ibean.IBeansMessageReceiver
#Inbound not supported for iBeans yet
message.receiver=

endpoint.builder=org.mule.transport.ibean.IBeansEndpointURIBuilder

Expand Down
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());
}
}
}
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);
// }
}

0 comments on commit 5abf946

Please sign in to comment.