Commit 82b5c759 authored by bseeger's avatar bseeger
Browse files

Merge branch 'more-pax-exam' into 'master'

Add more complete pax-exam testing

This _actually_ enables pax-exam for the `acrepo-karaf` module. Furthermore, it adds an optional `acrepo-itests` module that can be enabled via maven profiles to check that the karaf feature artifact is correct.

See merge request !4
parents 572c3bc3 c0ca558a
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>edu.amherst.acdc</groupId>
<artifactId>repository-services</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<artifactId>acrepo-itests</artifactId>
<packaging>bundle</packaging>
<name>Karaf Integration tests for repository services</name>
<properties>
<!-- dependencies -->
<jackson2.version>2.7.3</jackson2.version>
<!-- osgi bundle configuration -->
<osgi.import.packages>*</osgi.import.packages>
</properties>
<dependencies>
<dependency>
<groupId>org.fcrepo.camel</groupId>
<artifactId>fcrepo-camel</artifactId>
<version>${fcrepo-camel.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-idiomatic</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-mint-service</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-jsonld-cache</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-jsonld-service</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-karaf</artifactId>
<version>${project.version}</version>
<type>xml</type>
<classifier>features</classifier>
<scope>test</scope>
</dependency>
<!-- Testing & Camel Plugin -->
<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>javax.inject</artifactId>
<version>${hk2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-karaf</artifactId>
<version>${pax-exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<version>${pax-exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf</groupId>
<artifactId>apache-karaf</artifactId>
<version>${karaf.version}</version>
<type>zip</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.karaf</groupId>
<artifactId>apache-camel</artifactId>
<version>${camel.version}</version>
<type>xml</type>
<classifier>features</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-karaf</artifactId>
<version>${activemq.version}</version>
<type>xml</type>
<classifier>features</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>standard</artifactId>
<version>${karaf.version}</version>
<type>xml</type>
<classifier>features</classifier>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<!-- pax exam -->
<plugin>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>maven-paxexam-plugin</artifactId>
<version>${paxexam.plugin.version}</version>
<executions>
<execution>
<id>generate-config</id>
<goals>
<goal>generate-depends-file</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- reserve network ports for integration testing -->
<!-- add configuration file to artifact set for OSGi deployment -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<configuration>
<portNames>
<portName>fcrepo.dynamic.test.port</portName>
<portName>fcrepo.dynamic.jms.port</portName>
<portName>fcrepo.dynamic.stomp.port</portName>
<portName>fcrepo.dynamic.reindexing.port</portName>
<portName>karaf.rmiRegistry.port</portName>
<portName>karaf.rmiServer.port</portName>
<portName>karaf.ssh.port</portName>
<portName>jetty.dynamic.stop.port</portName>
</portNames>
</configuration>
<executions>
<execution>
<id>reserve-port</id>
<phase>package</phase>
<goals>
<goal>reserve-network-port</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- integration testing -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m</argLine>
<systemPropertyVariables>
<fcrepo.dynamic.reindexing.port>${fcrepo.dynamic.reindexing.port}</fcrepo.dynamic.reindexing.port>
<fcrepo.dynamic.test.port>${fcrepo.dynamic.test.port}</fcrepo.dynamic.test.port>
<fcrepo.dynamic.jms.port>${fcrepo.dynamic.jms.port}</fcrepo.dynamic.jms.port>
<project.build.outputDirectory>${project.build.outputDirectory}</project.build.outputDirectory>
<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>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>filter</id>
<phase>generate-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/fuseki_home</outputDirectory>
<resources>
<resource>
<directory>src/test/resources/fuseki</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Launch jetty for integration testing with fedora -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.plugin.version}</version>
<configuration>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
<systemProperties>
<!-- enable easy JMX connection to JConsole -->
<systemProperty>
<name>com.sun.management.jmxremote</name>
<value />
</systemProperty>
</systemProperties>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopWait>5</stopWait>
<systemProperties>
<force>true</force>
<systemProperty>
<name>fcrepo.home</name>
<value>${project.build.directory}/fcrepo-data</value>
</systemProperty>
<systemProperty>
<name>fcrepo.dynamic.jms.port</name>
<value>${fcrepo.dynamic.jms.port}</value>
</systemProperty>
<systemProperty>
<name>fcrepo.dynamic.stomp.port</name>
<value>${fcrepo.dynamic.stomp.port}</value>
</systemProperty>
<systemProperty>
<name>FUSEKI_BASE</name>
<value>${project.build.directory}/fuseki_home</value>
</systemProperty>
</systemProperties>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>STOP</stopKey>
<stopPort>${jetty.dynamic.stop.port}</stopPort>
<daemon>true</daemon>
</configuration>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
<configuration>
<httpConnector>
<port>${fcrepo.dynamic.test.port}</port>
</httpConnector>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${project.build.directory}/fuseki.war</war>
<contextPath>/fuseki</contextPath>
</contextHandler>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${project.build.directory}/fcrepo.war</war>
<contextPath>/fcrepo</contextPath>
</contextHandler>
</contextHandlers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<!-- to generate the MANIFEST-FILE of the bundle -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
<!--Bring in fcrepo webapp for integration testing-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-webapp</artifactId>
<version>${fcrepo.version}</version>
<type>war</type>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>fcrepo.war</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.apache.jena</groupId>
<artifactId>jena-fuseki-war</artifactId>
<version>${jena.fuseki.version}</version>
<type>war</type>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>fuseki.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*
* 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 org.apache.http.HttpStatus.SC_CREATED;
import static org.apache.http.impl.client.HttpClients.createDefault;
import static org.junit.Assert.assertEquals;
import static org.osgi.framework.Constants.OBJECTCLASS;
import static org.osgi.framework.FrameworkUtil.createFilter;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.IOException;
import javax.inject.Inject;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.karaf.features.FeaturesService;
import org.ops4j.pax.exam.Option;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
/**
* @author Aaron Coburn
* @since May 11, 2016
*/
public abstract class AbstractOSGiIT {
private static Logger LOGGER = getLogger(AbstractOSGiIT.class);
@Inject
protected FeaturesService featuresService;
@Inject
protected BundleContext bundleContext;
public abstract Option[] config();
protected String post(final String url) {
final CloseableHttpClient httpclient = createDefault();
try {
final HttpPost httppost = new HttpPost(url);
final HttpResponse response = httpclient.execute(httppost);
assertEquals(SC_CREATED, response.getStatusLine().getStatusCode());
return EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (IOException ex) {
LOGGER.debug("Unable to extract HttpEntity response into an InputStream: ", ex);
return "";
}
}
protected <T> T getOsgiService(final Class<T> type, final String filter, final long timeout) {
try {
final ServiceTracker tracker = new ServiceTracker(bundleContext,
createFilter("(&(" + OBJECTCLASS + "=" + type.getName() + ")" + filter + ")"), null);
tracker.open(true);
final Object svc = type.cast(tracker.waitForService(timeout));
if (svc == null) {
throw new RuntimeException("Gave up waiting for service " + filter);
}
return type.cast(svc);
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid filter", e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
/*
* 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 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.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 AcrepoServicesIT extends AbstractOSGiIT {
private static Logger LOGGER = getLogger(AcrepoServicesIT.class);
@Configuration
public Option[] config() {
final ConfigurationManager cm = new ConfigurationManager();
final String fcrepoPort = cm.getProperty("fcrepo.dynamic.test.port");
final String jmsPort = cm.getProperty("fcrepo.dynamic.jms.port");
final String reindexingPort = cm.getProperty("fcrepo.dynamic.reindexing.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");
final String emptyTopic = "broker:topic:test";
final String brokerUrl = "tcp://localhost:" + jmsPort;
final String triplestoreBaseUrl = "localhost:" + fcrepoPort + "/fuseki/test/update";
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("org.apache.camel.karaf").artifactId("apache-camel")
.type("xml").classifier("features").versionAsInProject(), "camel-blueprint"),
features(maven().groupId("org.apache.activemq").artifactId("activemq-karaf")
.type("xml").classifier("features").versionAsInProject(), "activemq-camel"),
features(maven().groupId("edu.amherst.acdc").artifactId("acrepo-karaf")
.type("xml").classifier("features").versionAsInProject(), "acrepo-idiomatic",
"acrepo-idiomatic-pgsql", "acrepo-mint-service", "acrepo-xml-metadata",
"acrepo-jsonld-service", "acrepo-jsonld-cache", "acrepo-template-mustache"),
systemProperty("karaf.reindexing.port").value(reindexingPort),
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/org.fcrepo.camel.indexing.triplestore.cfg", "fcrepo.baseUrl", fcrepoBaseUrl),
editConfigurationFilePut("etc/org.fcrepo.camel.indexing.triplestore.cfg", "triplestore.baseUrl",
triplestoreBaseUrl),
editConfigurationFilePut("etc/org.fcrepo.camel.indexing.solr.cfg", "fcrepo.baseUrl", fcrepoBaseUrl),
editConfigurationFilePut("etc/org.fcrepo.camel.indexing.solr.cfg", "input.stream", emptyTopic),
editConfigurationFilePut("etc/org.fcrepo.camel.reindexing.cfg", "fcrepo.baseUrl", fcrepoBaseUrl),
editConfigurationFilePut("etc/org.fcrepo.camel.reindexing.cfg", "rest.port", reindexingPort),
editConfigurationFilePut("etc/org.fcrepo.camel.serialization.cfg", "fcrepo.baseUrl", fcrepoBaseUrl),
editConfigurationFilePut("etc/org.fcrepo.camel.serialization.cfg", "serialization.descriptions",
"data/tmp/descriptions"),
editConfigurationFilePut("etc/org.fcrepo.camel.service.activemq.cfg", "jms.brokerUrl", brokerUrl)
};
}
@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-idiomatic")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-idiomatic-pgsql")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-mint-service")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-xml-metadata")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-jsonld-service")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-jsonld-cache")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-template-mustache")));
}
}
@prefix : <#> .
@prefix fuseki: <http://jena.apache.org/fuseki#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
[] rdf:type fuseki:Server ;
fuseki:services (
<#tdbService>
) .