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

a quick, simple IT using PAX to validate OSGi config #159

Open
wants to merge 4 commits into
base: v-1.4.x
Choose a base branch
from
Open
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
71 changes: 71 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
<module>xstream</module>
<module>xstream-hibernate</module>
<module>xstream-benchmark</module>
<module>xstream-its</module>
</modules>

<licenses>
Expand Down Expand Up @@ -617,6 +618,70 @@
<scope>test</scope>
</dependency>

<!-- Pax Exam Dependencies -->
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<version>${version.pax.exam}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-invoker-junit</artifactId>
<version>${version.pax.exam}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>${version.pax.exam}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-inject</artifactId>
<version>${version.pax.exam}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-extender-service</artifactId>
<version>${version.pax.exam}</version>
<scope>test</scope>
</dependency>

<!-- Preferred link because it does not require an mvn url handler implicitely. -->
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<version>${version.pax.exam}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-assembly</artifactId>
<version>${version.pax.exam}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>${version.felix}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -887,6 +952,10 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.plugin.jacoco}</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down Expand Up @@ -978,6 +1047,7 @@
<version.commons.io>1.4</version.commons.io>
<version.commons.lang>2.4</version.commons.lang>
<version.dom4j>1.6.1</version.dom4j>
<version.felix>4.4.1</version.felix>
<version.hsqldb>2.2.8</version.hsqldb>
<version.javaassist>3.12.1.GA</version.javaassist>
<version.javax.activation>1.1.1</version.javax.activation>
Expand All @@ -996,6 +1066,7 @@
<version.org.json>20080701</version.org.json>
<version.org.openjdk.jmh>1.21</version.org.openjdk.jmh>
<version.org.slf4j>1.6.1</version.org.slf4j>
<version.pax.exam>4.4.0</version.pax.exam>
<version.stax>1.2.0</version.stax>
<version.stax.api>1.0.1</version.stax.api>
<version.xerces.impl>2.8.1</version.xerces.impl>
Expand Down
150 changes: 150 additions & 0 deletions xstream-its/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>xstream-parent</artifactId>
<groupId>com.thoughtworks.xstream</groupId>
<version>1.4.12-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>xstream-its</artifactId>
<name>XStream ITs</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-invoker-junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-inject</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-extender-service</artifactId>
<scope>test</scope>
</dependency>

<!-- Preferred link because it does not require an mvn url handler implicitely. -->
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-assembly</artifactId>
<version>${version.pax.exam}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/test-resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>failsafe</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
1 change: 1 addition & 0 deletions xstream-its/src/test-resources/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.version=${project.version}
77 changes: 77 additions & 0 deletions xstream-its/src/test/com/thoughtworks/xstream/XStreamIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Created on 26. September 2003 by Joe Walnes
*/
package com.thoughtworks.xstream;

import java.io.InputStream;
import java.util.Properties;

import javax.inject.Inject;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;

@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class XStreamIT
{
@Inject
BundleContext bundleContext;

@Configuration
public Option[] config() throws Exception {
Properties properties = new Properties();
try (InputStream is = getClass().getResourceAsStream("/project.properties")) {
properties.load(is);
}
String xstreamVersion = properties.getProperty("project.version");

return options(
junitBundles(),
mavenBundle().groupId("com.thoughtworks.xstream").artifactId("xstream").version(xstreamVersion)
);
}

@Test
public void smokeTest() {
assertNotNull("BundleContext was not injected", bundleContext);

boolean xstreamBundleFound = false;
int xstreamBundleState = -1;
for (Bundle bundle : bundleContext.getBundles()) {
if ("xstream".equals(bundle.getSymbolicName())) {
xstreamBundleFound = true;
xstreamBundleState = bundle.getState();
}
}

assertTrue("XStream bundle was not loaded", xstreamBundleFound);
assertEquals(
format("XStream bundle was not active (was: %d)", xstreamBundleState),
xstreamBundleState, Bundle.ACTIVE
);
}
}