Commit 05174d74 authored by acoburn's avatar acoburn
Browse files

add integration tests for the template service

parent 3e5cced5
......@@ -179,6 +179,7 @@
<portName>fcrepo.dynamic.jms.port</portName>
<portName>fcrepo.dynamic.stomp.port</portName>
<portName>karaf.jsonld.port</portName>
<portName>karaf.template.port</portName>
<portName>karaf.rmiRegistry.port</portName>
<portName>karaf.rmiServer.port</portName>
<portName>karaf.ssh.port</portName>
......@@ -209,6 +210,7 @@
<fcrepo.dynamic.jms.port>${fcrepo.dynamic.jms.port}</fcrepo.dynamic.jms.port>
<project.build.outputDirectory>${project.build.outputDirectory}</project.build.outputDirectory>
<karaf.jsonld.port>${karaf.jsonld.port}</karaf.jsonld.port>
<karaf.template.port>${karaf.template.port}</karaf.template.port>
<karaf.ssh.port>${karaf.ssh.port}</karaf.ssh.port>
<karaf.rmiRegistry.port>${karaf.rmiRegistry.port}</karaf.rmiRegistry.port>
<karaf.rmiServer.port>${karaf.rmiServer.port}</karaf.rmiServer.port>
......
......@@ -16,6 +16,7 @@
package edu.amherst.acdc.itests;
import static org.apache.http.HttpStatus.SC_CREATED;
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
import static org.apache.http.HttpStatus.SC_OK;
import static org.apache.http.impl.client.HttpClients.createDefault;
import static org.junit.Assert.assertEquals;
......@@ -29,7 +30,9 @@ import javax.inject.Inject;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.karaf.features.FeaturesService;
......@@ -68,6 +71,21 @@ public abstract class AbstractOSGiIT {
}
}
protected boolean patch(final String url, final String sparql) {
final CloseableHttpClient httpclient = createDefault();
try {
final HttpPatch req = new HttpPatch(url);
req.addHeader("Content-Type", "application/sparql-update");
req.setEntity(new StringEntity(sparql));
final HttpResponse response = httpclient.execute(req);
assertEquals(SC_NO_CONTENT, response.getStatusLine().getStatusCode());
return true;
} catch (final IOException ex) {
LOGGER.warn("Error patching to {}: {}", url, ex.getMessage());
}
return false;
}
protected String get(final String url) {
final CloseableHttpClient httpclient = createDefault();
try {
......
/*
* Copyright 2016 Amherst College
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.itests;
import static java.util.stream.IntStream.range;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.File;
import org.apache.camel.CamelContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.ConfigurationManager;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
import org.slf4j.Logger;
/**
* @author Aaron Coburn
* @since May 2, 2016
*/
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class AcrepoTemplateIT extends AbstractOSGiIT {
private static Logger LOGGER = getLogger(AcrepoTemplateIT.class);
@Configuration
public Option[] config() {
final ConfigurationManager cm = new ConfigurationManager();
final String fcrepoPort = cm.getProperty("fcrepo.dynamic.test.port");
final String templateServicePort = cm.getProperty("karaf.template.port");
final String rmiRegistryPort = cm.getProperty("karaf.rmiRegistry.port");
final String rmiServerPort = cm.getProperty("karaf.rmiServer.port");
final String fcrepoBaseUrl = "localhost:" + fcrepoPort + "/fcrepo/rest";
final String sshPort = cm.getProperty("karaf.ssh.port");
return new Option[] {
karafDistributionConfiguration()
.frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf")
.versionAsInProject().type("zip"))
.unpackDirectory(new File("target", "exam"))
.useDeployFolder(false),
logLevel(LogLevel.WARN),
keepRuntimeFolder(),
configureConsole().ignoreLocalConsole(),
features(maven().groupId("org.apache.karaf.features").artifactId("standard")
.versionAsInProject().classifier("features").type("xml"), "scr"),
features(maven().groupId("edu.amherst.acdc").artifactId("acrepo-karaf")
.type("xml").classifier("features").versionAsInProject(),
"acrepo-template-mustache", "acrepo-jsonld-osgi"),
systemProperty("karaf.template.port").value(templateServicePort),
systemProperty("fcrepo.port").value(fcrepoPort),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", rmiRegistryPort),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort),
editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort),
editConfigurationFilePut("etc/edu.amherst.acdc.template.mustache.cfg", "fcrepo.baseUrl", fcrepoBaseUrl),
editConfigurationFilePut("etc/edu.amherst.acdc.template.mustache.cfg", "rest.port", templateServicePort)
};
}
@Test
public void testInstallation() throws Exception {
assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-core")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-camel")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-template-mustache")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-jsonld-osgi")));
}
@Test
public void testJsonLdService() throws Exception {
// make sure that the camel context has started up.
final CamelContext ctx = getOsgiService(CamelContext.class, "(camel.context.name=AcrepoTemplateService)",
10000);
assertNotNull(ctx);
final String baseUrl = "http://localhost:" + System.getProperty("fcrepo.port") + "/fcrepo/rest";
final String baseSvcUrl = "http://localhost:" + System.getProperty("karaf.template.port") + "/template";
range(1, 2).mapToObj(x -> post(baseUrl)).forEach(url -> {
patch(url, "PREFIX dcterms: <http://purl.org/dc/terms/>\n" +
"INSERT { <> dcterms:title \"Title\" ; dcterms:description \"A description: " + url + "\" } " +
"WHERE {}");
final String id = url.replace(baseUrl, "");
final String html = get(baseSvcUrl + id);
assertTrue(html.contains("<title>Title</title>"));
assertTrue(html.contains("<h1>Fedora Template Service: Title</h1>"));
assertTrue(html.contains("<p>A description: " + url + "</p>"));
});
}
}
......@@ -102,7 +102,7 @@
<feature version="${camel.version}">camel-jackson</feature>
<feature version="${camel.version}">camel-http4</feature>
<feature version="${fcrepo-camel.version}">fcrepo-camel</feature>
<feature version="${project.version}">acrepo-jsonld-service</feature>
<feature version="${project.version}">acrepo-jsonld-osgi</feature>
<bundle>mvn:edu.amherst.acdc/acrepo-template-mustache/${project.version}</bundle>
......
......@@ -2,7 +2,9 @@
error.maxRedeliveries=10
# The port on which the service is made available
rest.host=localhost
rest.port=13433
rest.prefix=/template
# The fedora baseUrl
fcrepo.baseUrl=localhost:8080/fcrepo/rest
......@@ -14,8 +16,4 @@ mustache.contentType=text/html
mustache.contentType=edu/amherst/acdc/template/mustache/template.mustache
# The json+ld context file
jsonld.context=https://acdc.amherst.edu/jsonld/context.json
# The host and prefix of the riak cluster
riak.host=localhost:8098
riak.bucket=fcrepo
jsonld.context=https://acdc.amherst.edu/jsonld/models.json
......@@ -11,17 +11,19 @@
<cm:property-placeholder persistent-id="edu.amherst.acdc.template.mustache" update-strategy="reload">
<cm:default-properties>
<cm:property name="error.maxRedeliveries" value="10"/>
<cm:property name="rest.host" value="localhost"/>
<cm:property name="rest.port" value="13433"/>
<cm:property name="rest.prefix" value="/template"/>
<cm:property name="mustache.template" value="edu/amherst/acdc/template/mustache/template.mustache"/>
<cm:property name="mustache.contentType" value="text/html"/>
<cm:property name="jsonld.context" value="https://acdc.amherst.edu/jsonld/context.json"/>
<cm:property name="jsonld.context" value="https://acdc.amherst.edu/jsonld/models.json"/>
<cm:property name="fcrepo.baseUrl" value="localhost:8080/fcrepo/rest"/>
</cm:default-properties>
</cm:property-placeholder>
<reference id="jsonldService" interface="edu.amherst.acdc.jsonld.JsonLdService" filter="(osgi.jndi.service.name=jsonld)" />
<camelContext xmlns="http://camel.apache.org/schema/blueprint" streamCache="false">
<camelContext id="AcrepoTemplateService" xmlns="http://camel.apache.org/schema/blueprint" streamCache="false">
<package>edu.amherst.acdc.template.mustache</package>
<route id="JsonLdCompaction">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment