Skip to content

Commit

Permalink
- added unit tests verifying that the slf4j artifacts can actually be
Browse files Browse the repository at this point in the history
used by other osgi bundles within a real osgi framework. The tests
depend on Felix.
  • Loading branch information
ceki committed Nov 28, 2009
1 parent bd6f4a9 commit 19fc29d
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
target
.classpath
.project
*~
*~
integration/bundle/
integration/felix-cache/
3 changes: 2 additions & 1 deletion integration/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
<!-- this is really very ugly, but it's the only way to circumvent
http://jira.codehaus.org/browse/MANTRUN-95
-->
<taskdef name="junit" classpath="${plugin_classpath};${compile_classpath}" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />
<taskdef name="junit" classpath="${plugin_classpath};${compile_classpath}"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />

<target name="init">
<mkdir dir="target/unit-reports" />
Expand Down
92 changes: 92 additions & 0 deletions integration/osgi-build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<project name="osgi-test" default="testAll">

<!--
This build file is usually run indirectly via Maven.
When running this build file through Ant directly, you must
define the currentVersion property on the command line, e.g.:
ant -DcurrentVersion=1.5.4-SNAPSHOT
-->

<echo message="compile classpath: ${currentVersion}" />
<echo message="test classpath: ${test_classpath}" />
<echo message="basedir: ${basedir}" />

<property name="iBundleJar" value="target/iBundle.jar"/>
<property name="bundlesDir" value="bundle"/>


<!-- this is really very ugly, but it's the only way to circumvent
http://jira.codehaus.org/browse/MANTRUN-95
-->
<taskdef name="junit" classpath="${test_classpath}"
classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />

<path id="minimal">
<pathelement location="target/test-classes/" />
</path >

<target name="init">
<mkdir dir="target/unit-reports" />
</target>

<target name="createIBundle">
<mkdir dir="${bundlesDir}"/>
<jar destFile="${iBundleJar}"
manifest="src/IBUNDLE-META-INF/MANIFEST.MF"
basedir="target/test-classes/"
includes="integrator/**.class"/>

</target>

<target name="testAll" depends="init, createIBundle, nop, simple, jdk14">
</target>


<macrodef name="prepareOSGiHarness">
<attribute name="binding"/>
<sequential>
<delete>
<fileset dir="${bundlesDir}" includes="*.jar"/>
</delete>
<copy file="${iBundleJar}" todir="${bundlesDir}"/>
<copy file="../slf4j-api/target/slf4j-api-${currentVersion}.jar" todir="${bundlesDir}"/>
<copy file="../slf4j-@{binding}/target/slf4j-@{binding}-${currentVersion}.jar" todir="${bundlesDir}"/>
<echo>value of t = @{t}</echo>
</sequential>
</macrodef>


<!-- for some reason if mvn is invoked from the parent directory, junit gets
invoked from the parent dir, which messes up theses tests. Hence, the
fork="yes" dir="${basedir}" -->

<target name="nop">
<prepareOSGiHarness binding="nop"/>
<junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes">
<classpath path="${test_classpath}"/>
<formatter type="plain" />
<test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" />
</junit>
</target>

<target name="simple">
<prepareOSGiHarness binding="simple"/>
<junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes">
<classpath path="${test_classpath}"/>
<formatter type="plain" />
<test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" />
</junit>
</target>

<target name="jdk14">
<prepareOSGiHarness binding="jdk14"/>
<junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes">
<classpath path="${test_classpath}"/>
<formatter type="plain" />
<test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" />
</junit>
</target>

</project>
23 changes: 23 additions & 0 deletions integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
<version>1.6.5</version>
</dependency>


<!-- some test run Felix in hosted mode -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -75,6 +82,22 @@
<goal>run</goal>
</goals>
</execution>
<execution>
<id>ant-osgi-test</id>
<phase>package</phase>
<configuration>
<tasks>
<property name="currentVersion" value="${version}" />
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="basedir" value="${basedir}"/>
<ant antfile="${basedir}/osgi-build.xml"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>

</executions>
</plugin>

Expand Down
15 changes: 15 additions & 0 deletions integration/src/IBUNDLE-META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: ceki
Build-Jdk: 1.6.0_16
Bundle-Description: iBundle
Bundle-Version: 0.1
Bundle-Activator: integrator.Activator
Implementation-Title: iBundle
Bundle-ManifestVersion: 2
Bundle-SymbolicName: iBundle
Bundle-Name: abundle
Bundle-RequiredExecutionEnvironment: J2SE-1.3
Export-Package: apack
Import-Package: org.osgi.framework, org.slf4j;version=1.5
57 changes: 57 additions & 0 deletions integration/src/test/java/integrator/Activator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2004-2009 QOS.ch All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package integrator;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A BundleActivator which invokes slf4j loggers
* @author Ceki G&uuml;lc&uuml;
*
*/
public class Activator implements BundleActivator {

private BundleContext m_context = null;

public void start(BundleContext context) {
Logger logger = LoggerFactory.getLogger(this.getClass());
logger.info("Activator.start()");
m_context = context;
}

public void stop(BundleContext context) {
m_context = null;
Logger logger = LoggerFactory.getLogger(this.getClass());
logger.info("Activator.stop");
}

public Bundle[] getBundles() {
if (m_context != null) {
return m_context.getBundles();
}
return null;
}
}
35 changes: 35 additions & 0 deletions integration/src/test/java/org/slf4j/test_osgi/BundleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.slf4j.test_osgi;

import java.io.File;

import junit.framework.TestCase;

public class BundleTest extends TestCase {

FrameworkErrorListener fel = new FrameworkErrorListener();
CheckingBundleListener mbl = new CheckingBundleListener();

FelixHost felixHost = new FelixHost(fel, mbl);

protected void setUp() throws Exception {
super.setUp();
felixHost.doLaunch();
}

protected void tearDown() throws Exception {
super.tearDown();
felixHost.stop();
}

public void testSmoke() {
System.out.println("==========="+new File(".").getAbsolutePath());
mbl.dumpAll();
// check that the bundle was installed
assertTrue(mbl.exists("iBundle"));
if(fel.errorList.size() != 0) {
fel.dumpAll();
}
// check that no errors occured
assertEquals(0, fel.errorList.size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.slf4j.test_osgi;

import java.util.ArrayList;
import java.util.List;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;

public class CheckingBundleListener implements BundleListener {

List eventList = new ArrayList();

public void bundleChanged(BundleEvent be) {
eventList.add(be);
}

private void dump(BundleEvent be) {
System.out.println("BE:" + ", source " + be.getSource() + ", bundle="
+ be.getBundle() + ", type=" + be.getType());

}

public void dumpAll() {
for (int i = 0; i < eventList.size(); i++) {
BundleEvent fe = (BundleEvent) eventList.get(i);
dump(fe);
}
}

boolean exists(String bundleName) {
for (int i = 0; i < eventList.size(); i++) {
BundleEvent fe = (BundleEvent) eventList.get(i);
Bundle b = fe.getBundle();
System.out.println("===["+b+"]");
if (bundleName.equals(b.getSymbolicName())) {
return true;
}
}
return false;
}

}
Loading

0 comments on commit 19fc29d

Please sign in to comment.