<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

    <parent>
		<groupId>edu.si.trippi</groupId>
		<artifactId>trippi</artifactId>
		<version>0.4.4</version>
	</parent>
	<artifactId>trippi-sparql-integration-tests</artifactId>

	<properties>
		<servlet.port>8080</servlet.port>
		<fedora.home>${project.build.directory}/fedora-home</fedora.home>
		<fuseki.base>${project.build.directory}/fuseki-base</fuseki.base>
	</properties>

	<dependencies>
		<dependency>
			<groupId>edu.si</groupId>
			<artifactId>trippi-sparql</artifactId>
			<version>0.4.4</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>edu.si</groupId>
			<artifactId>trippi-sparql-fcrepo-webapp</artifactId>
			<version>0.4.4</version>
			<type>war</type>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.apache.jena</groupId>
			<artifactId>jena-fuseki-war</artifactId>
			<version>2.3.0</version>
			<type>war</type>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<artifactId>slf4j-log4j12</artifactId>
					<groupId>org.slf4j</groupId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- logging -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<testResources>
			<testResource>
				<directory>${basedir}/src/test/resources/fedora-home</directory>
				<targetPath>${fedora.home}</targetPath>
				<!-- we filter in order to insert the appropriate container port into 
					the Trippi :: SPARQL configuration in fedora.fcfg -->
				<filtering>true</filtering>
			</testResource>

			<testResource>
				<directory>${basedir}/src/test/resources/fuseki-base</directory>
				<targetPath>${fuseki.base}</targetPath>
			</testResource>
		</testResources>

		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<version>1.9.1</version>
				<configuration>
					<portNames>
						<portName>dynamic.test.port</portName>
					</portNames>
				</configuration>
				<executions>
					<execution>
						<!-- we choose this phase to ensure that the chosen port number is 
							available for test resource filtering, specifically into fedora.fcfg -->
						<phase>process-test-sources</phase>
						<goals>
							<goal>reserve-network-port</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<artifactId>maven-failsafe-plugin</artifactId>
				<version>2.18.1</version>
				<configuration>
					<systemPropertyVariables>
						<dynamic.test.port>${dynamic.test.port}</dynamic.test.port>
					</systemPropertyVariables>
				</configuration>
				<executions>
					<execution>
						<id>integration-test</id>
						<goals>
							<goal>integration-test</goal>
							<goal>verify</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.codehaus.cargo</groupId>
				<artifactId>cargo-maven2-plugin</artifactId>
				<version>1.4.15</version>
				<configuration>
					<container>
						<containerId>tomcat8x</containerId>
						<type>embedded</type>
						<systemProperties>
							<FUSEKI_BASE>${fuseki.base}</FUSEKI_BASE>
							<fedora.home>${fedora.home}</fedora.home>
						</systemProperties>
					</container>
					<configuration>
						<properties>
							<cargo.servlet.uriencoding>UTF-8</cargo.servlet.uriencoding>
							<cargo.jvmargs>-Xmx512m</cargo.jvmargs>
							<cargo.logging>low</cargo.logging>
							<cargo.servlet.port>${dynamic.test.port}</cargo.servlet.port>
						</properties>
					</configuration>
					<deployables>
						<deployable>
							<groupId>org.apache.jena</groupId>
							<artifactId>jena-fuseki-war</artifactId>
							<type>war</type>
						</deployable>

						<deployable>
							<groupId>edu.si</groupId>
							<artifactId>trippi-sparql-fcrepo-webapp</artifactId>
							<type>war</type>
						</deployable>
					</deployables>
				</configuration>
				<executions>
					<execution>
						<id>start</id>
						<phase>pre-integration-test</phase>
						<goals>
							<goal>start</goal>
						</goals>
					</execution>

					<execution>
						<id>stop</id>
						<phase>post-integration-test</phase>
						<goals>
							<goal>stop</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>