Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added basic tests to image service #65

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions camel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<commons-io.version>2.4</commons-io.version>
<fcrepo.camel.version>4.3.0</fcrepo.camel.version>
<slf4j.version>1.7.12</slf4j.version>
<scriptengines-javascript.version>1.1.1</scriptengines-javascript.version>
<log4j.version>1.2.17</log4j.version>
<!-- plugins -->
<compiler.plugin.version>2.5.1</compiler.plugin.version>
Expand Down Expand Up @@ -51,16 +52,62 @@
<artifactId>camel-blueprint</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mustache</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http4</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cache</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-base64</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-exec</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>${activemq.version}</version>
</dependency>
<dependency>
<groupId>org.fcrepo.camel</groupId>
<artifactId>fcrepo-camel</artifactId>
<version>${fcrepo.camel.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.scriptengines</groupId>
<artifactId>scriptengines-javascript</artifactId>
<version>${scriptengines-javascript.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty9</artifactId>
<version>${camel.version}</version>
</dependency>

<!-- logging -->
<dependency>
Expand Down
46 changes: 45 additions & 1 deletion camel/services/basic-image-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,48 @@

<name>Islandora Basic Image Service</name>

<properties>
<scriptengines-javascript.version>1.1.1</scriptengines-javascript.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mustache</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty9</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
</dependency>
<dependency>
<groupId>org.fcrepo.camel</groupId>
<artifactId>fcrepo-camel</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.scriptengines</groupId>
<artifactId>scriptengines-javascript</artifactId>
</dependency>
<dependency>
<groupId>ca.islandora.camel.component</groupId>
<artifactId>islandora-camel-component</artifactId>
<version>${project.version}</version>
</dependency>

<!-- logging -->
<dependency>
Expand All @@ -46,6 +78,12 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-blueprint</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -84,6 +122,12 @@
<artifactId>maven-bundle-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<!-- Load Configuration File -->
<cm:property-placeholder id="properties" persistent-id="ca.islandora.services.basic.image" update-strategy="reload">

<cm:default-properties>
<cm:property name="islandora.drupal.baseurl" value="localhost/islandora"/>
<cm:property name="islandora.drupal.username" value=""/>
Expand All @@ -32,7 +33,7 @@
<routeContextRef ref="put"/>
<routeContextRef ref="delete"/>

<route>
<route id="changeme3">
<from uri="jetty:http://0.0.0.0:8888/islandora/rest/basic-image/"/>
<choice>
<when><simple>${headers.CamelHttpMethod} == 'GET'</simple>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sparql="http://www.w3.org/2005/sparql-results#"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

Expand All @@ -21,19 +21,19 @@
<transform><javaScript>encodeURI(request.body)</javaScript></transform>
<removeHeaders pattern="*"/>
<setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader>
<setHeader headerName="CamelHttpQuery"><simple>format=json&amp;query=${bodyAs(String)}</simple></setHeader>
<setHeader headerName="CamelHttpQuery"><simple>format=xml&amp;query=${bodyAs(String)}</simple></setHeader>
<setBody><simple>${null}</simple></setBody>
<to uri="http:{{islandora.triplestore.baseurl}}"/>
<to uri="direct:getObjectExtractUri"/>
</route>

<route id="getObjectExtractUri">
<description>Uses JSONPath and Javascript to parse SPARQL query results and set collection URI as an exchange property</description>
<description>Uses XPath and Javascript to parse SPARQL query results and set collection URI as an exchange property</description>
<from uri="direct:getObjectExtractUri"/>
<doTry>
<transform><jsonpath>$['results']['bindings'][0]['s']['value']</jsonpath></transform>
<transform><xpath resultType="java.lang.String">//sparql:results/sparql:result[1]/sparql:binding[@name='s']/sparql:uri/text()</xpath></transform>
<transform><javaScript>request.body.substr(request.body.indexOf('://') + 3)</javaScript></transform>
<setProperty propertyName="uri"><simple>${bodyAs(String)}</simple></setProperty>
<setProperty propertyName="uri"><simple>${body}</simple></setProperty>
<doCatch>
<exception>java.lang.Exception</exception>
<to uri="direct:getObjectExtractUriError"/>
Expand Down Expand Up @@ -65,19 +65,19 @@
<transform><javaScript>encodeURI(request.body)</javaScript></transform>
<removeHeaders pattern="*"/>
<setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader>
<setHeader headerName="CamelHttpQuery"><simple>format=json&amp;query=${bodyAs(String)}</simple></setHeader>
<setHeader headerName="CamelHttpQuery"><simple>format=xml&amp;query=${bodyAs(String)}</simple></setHeader>
<setBody><simple>${null}</simple></setBody>
<to uri="http:{{islandora.triplestore.baseurl}}"/>
<to uri="direct:getCollectionExtractUri"/>
</route>

<route id="getCollectionExtractUri">
<description>Uses JSONPath and Javascript to parse SPARQL query results and set collection URI as an exchange property</description>
<description>Uses XPath and Javascript to parse SPARQL query results and set collection URI as an exchange property</description>
<from uri="direct:getCollectionExtractUri"/>
<doTry>
<transform><jsonpath>$['results']['bindings'][0]['s']['value']</jsonpath></transform>
<transform><xpath resultType="java.lang.String">//sparql:results/sparql:result[1]/sparql:binding[@name='s']/sparql:uri/text()</xpath></transform>
<transform><javaScript>request.body.substr(request.body.indexOf('://') + 3)</javaScript></transform>
<setProperty propertyName="uri"><simple>${bodyAs(String)}</simple></setProperty>
<setProperty propertyName="uri"><simple>${body}</simple></setProperty>
<doCatch>
<exception>java.lang.Exception</exception>
<to uri="direct:getCollectionExtractUriError"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package ca.islandora.services.basic.image;

import static java.util.UUID.randomUUID;
import static org.apache.camel.Exchange.HTTP_METHOD;
import static org.apache.camel.Exchange.HTTP_QUERY;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.activation.DataHandler;

import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.impl.DefaultMessage;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.apache.camel.util.ObjectHelper;

import org.junit.Test;

/**
* Test the route workflow.
*
* @author Aaron Coburn
* @since 2015-10-07
*/
public class GetRoutesTest extends CamelBlueprintTestSupport {

@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;

@Produce(uri = "direct:start")
protected ProducerTemplate template;

@Override
public boolean isUseAdviceWith() {
return true;
}

@Override
public boolean isUseRouteBuilder() {
return false;
}

@Override
protected String getBlueprintDescriptor() {
return "/OSGI-INF/blueprint/*.xml";
}

@Test
public void getObjectUri() throws Exception {
context.getRouteDefinition("getObjectUri").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:start");
mockEndpointsAndSkip("direct:*");
mockEndpointsAndSkip("http:*");
weaveAddLast().to("mock:result");
}
});

context.start();

final String uuid = randomUUID().toString();

resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedPropertyReceived("uuid", uuid);
resultEndpoint.message(0).header(HTTP_METHOD).equals("POST");
resultEndpoint.message(0).header(HTTP_QUERY).equals(
"format=xml&query=" +
"PREFIX%20nfo:%20%3chttp://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/%3e%0a" +
"PREFIX%20rdf:%20%3chttp://www.w3.org/1999/02/22-rdf-syntax-ns#%3e%0a" +
"PREFIX%20pcdm:%20%3chttp://pcdm.org/models#%3e%0a" +
"SELECT%20?s%20WHERE%20%7b%0a" +
"%20%20?s%20nfo:uuid%20%22" + uuid + "%22%5e%5e%3chttp://www.w3.org/2001/XMLSchema#string%3e%20.%0a" +
"%20%20?s%20rdf:type%20pcdm:Object%20.%0a%7d%0a");

final Exchange exchange = new DefaultExchange(context);
exchange.setProperty("uuid", uuid);

template.send(exchange);

assertMockEndpointsSatisfied();
}

@Test
public void getCollectionUri() throws Exception {
context.getRouteDefinition("getCollectionUri").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:start");
mockEndpointsAndSkip("direct:*");
mockEndpointsAndSkip("http:*");
weaveAddLast().to("mock:result");
}
});

context.start();

final String uuid = randomUUID().toString();

resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedPropertyReceived("uuid", uuid);
resultEndpoint.message(0).header(HTTP_METHOD).equals("POST");
resultEndpoint.message(0).header(HTTP_QUERY).equals(
"format=xml&query=" +
"PREFIX%20nfo:%20%3chttp://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.2/%3e%0a" +
"PREFIX%20rdf:%20%3chttp://www.w3.org/1999/02/22-rdf-syntax-ns#%3e%0a" +
"PREFIX%20pcdm:%20%3chttp://pcdm.org/models#%3e%0a" +
"SELECT%20?s%20WHERE%20%7b%0a" +
"%20%20?s%20nfo:uuid%20%22" + uuid + "%22%5e%5e%3chttp://www.w3.org/2001/XMLSchema#string%3e%20.%0a" +
"%20%20?s%20rdf:type%20pcdm:Collection%20.%0a%7d%0a");

final Exchange exchange = new DefaultExchange(context);
exchange.setProperty("uuid", uuid);

template.send(exchange);

assertMockEndpointsSatisfied();
}
}
Loading