forked from qos-ch/slf4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added unit tests verifying that the slf4j artifacts can actually be
used by other osgi bundles within a real osgi framework. The tests depend on Felix.
- Loading branch information
Showing
11 changed files
with
465 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
target | ||
.classpath | ||
.project | ||
*~ | ||
*~ | ||
integration/bundle/ | ||
integration/felix-cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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ülcü | ||
* | ||
*/ | ||
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
35
integration/src/test/java/org/slf4j/test_osgi/BundleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
integration/src/test/java/org/slf4j/test_osgi/CheckingBundleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.