[slf4j-dev] svn commit: r715 - in slf4j/trunk/slf4j-osgi-integration-test: . src src/main src/main/java src/main/resources src/test src/test/java src/test/java/org src/test/java/org/slf4j src/test/java/org/slf4j/osgi src/test/java/org/slf4j/osgi/integration src/test/java/org/slf4j/osgi/integration/log4j src/test/java/org/slf4j/osgi/integration/log4j/test src/test/java/org/slf4j/osgi/integration/nop src/test/java/org/slf4j/osgi/integration/nop/test src/test/java/org/slf4j/osgi/integration/simple src/test/java/org/slf4j/osgi/integration/simple/test src/test/resources src/test/resources/org src/test/resources/org/slf4j src/test/resources/org/slf4j/osgi src/test/resources/org/slf4j/osgi/integration src/test/resources/org/slf4j/osgi/integration/log4j src/test/resources/org/slf4j/osgi/integration/log4j/test src/test/resources/org/slf4j/osgi/integration/nop src/test/resources/org/slf4j/osgi/integration/nop/test src/test/resources/org/slf4j/osgi/integration/simple src/test/resources/org/slf4j/osgi/integration/simple/test

jconlon at slf4j.org jconlon at slf4j.org
Wed Feb 7 17:07:48 CET 2007


Author: jconlon
Date: Wed Feb  7 17:07:47 2007
New Revision: 715

Added:
   slf4j/trunk/slf4j-osgi-integration-test/
   slf4j/trunk/slf4j-osgi-integration-test/pom.xml
   slf4j/trunk/slf4j-osgi-integration-test/src/
   slf4j/trunk/slf4j-osgi-integration-test/src/main/
   slf4j/trunk/slf4j-osgi-integration-test/src/main/java/
   slf4j/trunk/slf4j-osgi-integration-test/src/main/resources/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/IntegrationTestConstants.java
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/log4j/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/log4j/test/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/log4j/test/Log4JBundleTest.java
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/nop/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/nop/test/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/nop/test/NopBundleTest.java
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/simple/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/simple/test/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/simple/test/SimpleBundleTest.java
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/log4j.properties
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/log4j/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/log4j/test/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/log4j/test/MANIFEST.MF
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/nop/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/nop/test/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/nop/test/MANIFEST.MF
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/simple/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/simple/test/
   slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/simple/test/MANIFEST.MF

Log:
Spring-OSGi based OSGi integration test project.

Added: slf4j/trunk/slf4j-osgi-integration-test/pom.xml
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/pom.xml	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,220 @@
+<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">
+	
+	<parent>
+		<groupId>org.slf4j</groupId>
+		<artifactId>slf4j-parent</artifactId>
+		<version>1.3.0-SNAPSHOT</version>
+	</parent>
+	
+	<modelVersion>4.0.0</modelVersion>
+	
+	<groupId>org.slf4j</groupId>
+	<artifactId>slf4j-osgi-integration-test</artifactId>
+	<version>${parent.version}</version>
+	<packaging>jar</packaging>
+	<name>SLF4J OSGi Integration Test</name>
+	
+	<url>http://www.slf4j.org</url>
+	<description>
+        OSGi integration tests for the slf4j. 
+        </description>
+    <!-- These dependencies are deceptive they are only for the springframework testing env.  
+    bundles being tested are specified in the  -->
+    
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-osgi-test-bundle</artifactId>
+			<version>${parent.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.osgi</groupId>
+			<artifactId>org.springframework.osgi.test</artifactId>
+			<version>1.0-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.osgi</groupId>
+			<artifactId>spring-core</artifactId>
+			<version>2.1-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.osgi</groupId>
+			<artifactId>spring-context</artifactId>
+			<version>2.1-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.osgi</groupId>
+			<artifactId>spring-beans</artifactId>
+			<version>2.1-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.osgi</groupId>
+			<artifactId>jcl104-over-slf4j.osgi</artifactId>
+			<version>1.1.0</version>
+			<scope>provided</scope>
+		</dependency>
+		
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j-full</artifactId>
+			<version>1.1.0</version>
+			<scope>provided</scope>
+		</dependency>
+		
+		<dependency>
+			<groupId>org.springframework.osgi</groupId>
+			<artifactId>log4j.osgi</artifactId>
+			<version>1.2.13-SNAPSHOT</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.osgi</groupId>
+			<artifactId>backport-util-concurrent</artifactId>
+			<version>3.0-SNAPSHOT</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+	
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+      <!-- run tests during the integration-test phase, not the normal test phase -->
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<configuration>
+					<skip>true</skip>
+					<systemProperties>
+            			<property>
+              				<name>org.springframework.osgi.test.framework</name>
+              				<value>${osgi.test.platform}</value>
+            			</property>
+            			<property>
+              				<name>org.osgi.framework.system.packages</name>
+              				<value>${osgi.test.system.packages}</value>
+            			</property>
+            			<!--
+            			<property>
+              				<name>org.osgi.vendor.framework</name>
+              				<value>${org.osgi.vendor.framework}</value>
+            			</property>
+            			-->
+          			</systemProperties>
+				</configuration>
+				<executions>
+					<execution>
+						<id>default</id>
+						<phase>test</phase>
+						<goals></goals>
+					</execution>
+					<execution>
+						<id>integration-test</id>
+						<phase>integration-test</phase>
+						<goals>
+							<goal>test</goal>
+						</goals>
+						<configuration>
+							<skip>false</skip>
+							<forkMode>pertest</forkMode>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+	<profiles>
+		<profile>
+			<id>equinox</id>
+			<activation>
+				<activeByDefault>true</activeByDefault>
+			</activation>
+			<dependencies>
+				<dependency>
+					<groupId>org.eclipse.equinox</groupId>
+					<artifactId>org.eclipse.osgi</artifactId>
+					<version>3.2.0</version>
+					<type>jar</type>
+					<scope>provided</scope>
+				</dependency>
+			</dependencies>
+			<properties>
+			    <osgi.test.system.packages>org.xml.sax, org.w3c.dom, javax.xml.parsers, javax.naming, javax.management</osgi.test.system.packages>
+				<osgi.test.platform>equinox</osgi.test.platform>
+			</properties>
+		</profile>
+		<profile>
+			<id>knopflerfish</id>
+			<dependencies>
+				<dependency>
+					<groupId>org.knopflerfish</groupId>
+					<artifactId>framework</artifactId>
+					<version>2.0.1</version>
+					<type>jar</type>
+					<scope>provided</scope>
+				</dependency>
+			</dependencies>
+			<properties>
+			    <!-- knopflerfish testing requires that the system property 
+			org.osgi.framework.system.packages be set with a list 
+			system packages that are to be imported on the kf classpath.
+			This property is a placeholder for the list. See the surefire 
+			plugin configuration systemProperties referenced above to see 
+			the mapping to this element. -->
+			    <osgi.test.system.packages>org.xml.sax, org.w3c.dom, javax.xml.parsers, javax.naming, javax.management</osgi.test.system.packages>
+				<osgi.test.platform>knopflerfish</osgi.test.platform>
+			</properties>
+		</profile>
+		<profile>
+			<id>felix</id>
+			<dependencies>
+				<dependency>
+					<groupId>org.apache.felix</groupId>
+					<artifactId>org.apache.felix.framework</artifactId>
+					<version>0.8.0-SNAPSHOT</version>
+					<type>jar</type>
+					<scope>provided</scope>
+				</dependency>
+				<dependency>
+					<groupId>org.apache.felix</groupId>
+					<artifactId>org.apache.felix.main</artifactId>
+					<version>0.8.0-SNAPSHOT</version>
+					<type>jar</type>
+					<scope>provided</scope>
+				</dependency>
+				<dependency>
+					<groupId>org.apache.felix</groupId>
+					<artifactId>org.osgi.core</artifactId>
+					<version>0.8.0-SNAPSHOT</version>
+					<type>jar</type>
+					<scope>runtime</scope>
+				</dependency>
+			</dependencies>
+			<properties>
+				<osgi.test.platform>felix</osgi.test.platform>
+		<!-- <org.osgi.vendor.framework>org.apache.felix.framework</org.osgi.vendor.framework>  -->
+			</properties>
+		</profile>
+	</profiles>
+</project>
\ No newline at end of file

Added: slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/IntegrationTestConstants.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/IntegrationTestConstants.java	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,49 @@
+/* 
+ * Copyright (c) 2004-2005 SLF4J.ORG
+ * 
+ * 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, and/or sell copies of  the Software, and to permit persons
+ * to whom  the Software is furnished  to do so, provided  that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the  Software and  that both  the above  copyright notice(s)  and this
+ * permission notice appear in supporting documentation.
+ * 
+ * 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
+ * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
+ * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
+ * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as  contained in  this notice, the  name of a  copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+package org.slf4j.osgi.integration;
+
+public interface IntegrationTestConstants {
+
+	public static final String SLF4J_NOP = "org.slf4j.slf4j-nop";
+
+	public static final String SLF4J_OSGI_TEST = "org.slf4j.slf4j-osgi-test-bundle";
+
+	public static final String SLF4J_LOG4J = "org.slf4j.slf4j-log4j12";
+	
+	public static final String SLF4J_SIMPLE = "org.slf4j.slf4j-simple";
+	
+	public static final String SLF4J_JCL = "org.slf4j.jcl104-over-slf4j";
+
+
+	
+	public static final String VERSION = "1.3.0-SNAPSHOT";
+}

Added: slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/log4j/test/Log4JBundleTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/log4j/test/Log4JBundleTest.java	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,180 @@
+/* 
+ * Copyright (c) 2004-2005 SLF4J.ORG
+ * 
+ * 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, and/or sell copies of  the Software, and to permit persons
+ * to whom  the Software is furnished  to do so, provided  that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the  Software and  that both  the above  copyright notice(s)  and this
+ * permission notice appear in supporting documentation.
+ * 
+ * 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
+ * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
+ * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
+ * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as  contained in  this notice, the  name of a  copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+package org.slf4j.osgi.integration.log4j.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.osgi.integration.IntegrationTestConstants;
+import org.slf4j.osgi.test.service.Probe;
+import org.springframework.osgi.test.ConfigurableBundleCreatorTests;
+
+/**
+ * 
+ * <code>Log4JBundleTest</code> starts up an OSGi environment (equinox,
+ * knopflerfish, or felix according to the profile selected) and installs the
+ * slf4j.osgi.test.bundle, the slf4j.log4j12 bundle and the bundles they depend
+ * on.
+ * 
+ * The slf4j.log4j12 will use the log4j bundle associated with the Spring-OSGi
+ * testing framework.
+ * 
+ * The test classes in this project will be turned into a virtual bundle which
+ * is also installed and the tests are then run inside the OSGi runtime.
+ * 
+ * The tests have access to a BundleContext, which we use to test that all
+ * bundles have been started.
+ * 
+ * 
+ * @author John Conlon
+ */
+public class Log4JBundleTest extends ConfigurableBundleCreatorTests implements IntegrationTestConstants {
+
+	
+
+	
+	
+
+	/**
+	 * The manifest to use for the "virtual bundle" created out of the test
+	 * classes and resources in this project
+	 * 
+	 * This is actually the boilerplate manifest with one additional
+	 * import-package added. We should provide a simpler customization point for
+	 * such use cases that doesn't require duplication of the entire manifest...
+	 */
+	protected String getManifestLocation() {
+		return "classpath:org/slf4j/osgi/integration/log4j/test/MANIFEST.MF";
+	}
+
+	/**
+	 * The location of the packaged OSGi bundles to be installed for this test.
+	 * Values are Spring resource paths. The bundles we want to use are part of
+	 * the same multi-project maven build as this project is. Hence we use the
+	 * localMavenArtifact helper method to find the bundles produced by the
+	 * package phase of the maven build (these tests will run after the
+	 * packaging phase, in the integration-test phase).
+	 * 
+	 * JUnit, commons-logging, spring-core and the spring OSGi test bundle are
+	 * automatically included so they do not need to be specified here.
+	 * 
+	 * Except in the case of slf4j.log4j12 using the log4j bundle associated
+	 * with the Spring-OSGi testing framework our test bundles are using package
+	 * import and export versions to keep these other logging bundles from
+	 * getting mixed up with our test bundles.
+	 */
+	protected String[] getBundleLocations() {
+		return new String[] {
+				localMavenArtifact("org.springframework.osgi",
+						"aopalliance.osgi", "1.0-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi",
+						"spring-context", "2.1-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi", "spring-beans",
+						"2.1-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi",
+						"spring-osgi-core", "1.0-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi", "spring-aop",
+						"2.1-SNAPSHOT"),
+				localMavenArtifact("org.slf4j", "slf4j-log4j12", VERSION),
+				localMavenArtifact("org.slf4j", "slf4j-osgi-test-bundle",
+						VERSION) };
+	}
+
+	/**
+	 * The superclass provides us access to the root bundle context via the
+	 * 'getBundleContext' operation. Make sure it is not null.
+	 */
+	public void testOSGiStartedOk() {
+		BundleContext bundleContext = getBundleContext();
+		assertNotNull(bundleContext);
+
+	}
+
+	/**
+	 * Makes sure our bundles are in the OSGi runtime and their state is Active.
+	 * 
+	 */
+	public void testSlf4jLog4j12BundleIntegration() {
+		Logger log = LoggerFactory.getLogger(Log4JBundleTest.class);
+		assertNotNull(log);
+		BundleContext context = getBundleContext();
+		List symNames = new ArrayList();
+
+		Bundle[] bundles = context.getBundles();
+		log.info("Loaded bundles:");
+		for (int i = 0; i < bundles.length; i++) {
+			Bundle bundle = bundles[i];
+			assertEquals("Bundle " + bundle.getSymbolicName()
+					+ " is not active.", Bundle.ACTIVE, bundle.getState());
+			symNames.add(bundle.getSymbolicName());
+			if (bundle.getHeaders().get(Constants.BUNDLE_ACTIVATOR) != null) {
+				log.info("Symbolic Name:" + bundle.getSymbolicName()
+						+ ", Activator:"
+						+ bundle.getHeaders().get(Constants.BUNDLE_ACTIVATOR));
+			} else {
+				log.info("Symbolic Name:" + bundle.getSymbolicName());
+			}
+		}
+
+		assertTrue(symNames.contains(SLF4J_LOG4J));
+		assertTrue(symNames.contains(SLF4J_OSGI_TEST));
+
+	}
+
+	public void testProbeService() {
+		BundleContext context = getBundleContext();
+		ServiceReference ref = context.getServiceReference(Probe.class
+				.getName());
+		assertNotNull("Service Reference is null", ref);
+		Probe probe = null;
+
+		probe = (Probe) context.getService(ref);
+		assertNotNull("Cannot find the probe service", probe);
+
+		try {
+			probe.testCommonslogging();
+			fail("The commons logging package should not be found. Instead an exception should be thrown.");
+		} catch (Throwable t) {
+			// "Expect.",t);
+		}
+
+		context.ungetService(ref);
+
+	}
+}

Added: slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/nop/test/NopBundleTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/nop/test/NopBundleTest.java	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,173 @@
+/* 
+ * Copyright (c) 2004-2005 SLF4J.ORG
+ * 
+ * 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, and/or sell copies of  the Software, and to permit persons
+ * to whom  the Software is furnished  to do so, provided  that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the  Software and  that both  the above  copyright notice(s)  and this
+ * permission notice appear in supporting documentation.
+ * 
+ * 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
+ * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
+ * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
+ * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as  contained in  this notice, the  name of a  copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+package org.slf4j.osgi.integration.nop.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.osgi.integration.IntegrationTestConstants;
+import org.slf4j.osgi.test.service.Probe;
+import org.springframework.osgi.test.ConfigurableBundleCreatorTests;
+
+/**
+ * 
+ * <code>NopBundleTest</code>  starts up an OSGi environment (equinox,
+ * knopflerfish, or felix according to the profile selected) and installs the
+ * slf4j.osgi.test.bundle, the slf4j.nop bundle and the bundles they depend on. 
+ * 
+ * The test classes in this project will be turned into a virtual bundle which is 
+ * also installed and the tests are then run inside the OSGi runtime.
+ * 
+ * The tests have access to a BundleContext, which we use to test that all bundles have
+ * been started.
+ * 
+ * 
+ * @author John Conlon
+ */
+public class NopBundleTest extends ConfigurableBundleCreatorTests implements IntegrationTestConstants{
+
+
+
+	/**
+	 * The manifest to use for the "virtual bundle" created out of the test
+	 * classes and resources in this project
+	 * 
+	 * This is actually the boilerplate manifest with one additional
+	 * import-package added. We should provide a simpler customization point for
+	 * such use cases that doesn't require duplication of the entire manifest...
+	 */
+	protected String getManifestLocation() {
+		return "classpath:org/slf4j/osgi/integration/nop/test/MANIFEST.MF";
+	}
+	
+	/**
+	 * The location of the packaged OSGi bundles to be installed for this test.
+	 * Values are Spring resource paths. The bundles we want to use are part of
+	 * the same multi-project maven build as this project is. Hence we use the
+	 * localMavenArtifact helper method to find the bundles produced by the
+	 * package phase of the maven build (these tests will run after the
+	 * packaging phase, in the integration-test phase).
+	 * 
+	 * JUnit, commons-logging, spring-core and the spring OSGi test bundle are
+	 * automatically included so they do not need to be specified here.
+	 * 
+	 * Our test bundles are using package import and export versions to keep
+	 * these other logging bundles from getting mixed up with our test bundles. 
+	 */
+	protected String[] getBundleLocations() {
+		return new String[] {
+				localMavenArtifact("org.springframework.osgi",
+						"aopalliance.osgi", "1.0-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi",
+						"spring-context", "2.1-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi", "spring-beans",
+						"2.1-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi",
+						"spring-osgi-core", "1.0-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi", "spring-aop",
+						"2.1-SNAPSHOT"),
+						localMavenArtifact("org.slf4j", "slf4j-nop", VERSION),
+						localMavenArtifact("org.slf4j", "slf4j-osgi-test-bundle",
+								VERSION) };
+	}
+
+	/**
+	 * The superclass provides us access to the root bundle context via the
+	 * 'getBundleContext' operation. Make sure it is not null.
+	 */
+	public void testOSGiStartedOk() {
+		BundleContext bundleContext = getBundleContext();
+		assertNotNull(bundleContext);
+
+	}
+
+	/**
+	 * Makes sure our bundles are in the OSGi runtime and their state is Active.
+	 * 
+	 */
+	public void testSlf4jNopBundleIntegration() {
+		Logger log = LoggerFactory.getLogger(NopBundleTest.class);
+		assertNotNull(log);
+		BundleContext context = getBundleContext();
+		List symNames = new ArrayList();
+
+		Bundle[] bundles = context.getBundles();
+		log.info("Loaded bundles:");
+		for (int i = 0; i < bundles.length; i++) {
+			Bundle bundle = bundles[i];
+			assertEquals("Bundle " + bundle.getSymbolicName()
+					+ " is not active.", Bundle.ACTIVE, bundle.getState());
+			symNames.add(bundle.getSymbolicName());
+			if (bundle.getHeaders().get(Constants.BUNDLE_ACTIVATOR) != null) {
+				log.info("Symbolic Name:" + bundle.getSymbolicName()
+						+ ", Activator:"
+						+ bundle.getHeaders().get(Constants.BUNDLE_ACTIVATOR));
+			} else {
+				log.info("Symbolic Name:" + bundle.getSymbolicName());
+			}
+		}
+
+		assertTrue(symNames.contains(SLF4J_NOP));
+		assertTrue(symNames.contains(SLF4J_OSGI_TEST));
+
+	}
+	
+	public void testProbeService(){
+		Logger log = LoggerFactory.getLogger(NopBundleTest.class);
+		log.debug("Testing probe");
+		BundleContext context = getBundleContext();
+		ServiceReference ref = context.getServiceReference( Probe.class.getName() );
+		assertNotNull( "Service Reference is null", ref );
+		Probe probe = ( Probe ) context.getService( ref );
+		assertNotNull( "Cannot find the probe service", probe );
+
+		try {
+			probe.testCommonslogging();
+			fail("Expected exception while testing commons logging.");
+		} catch (Throwable t){
+			log.debug("Failed to execute the probe.testCommonsLogging. "+t);
+
+		}
+
+		context.ungetService( ref );
+
+		log.debug("Tested probe.");
+	}
+
+}

Added: slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/simple/test/SimpleBundleTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/simple/test/SimpleBundleTest.java	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,176 @@
+/* 
+ * Copyright (c) 2004-2005 SLF4J.ORG
+ * 
+ * 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, and/or sell copies of  the Software, and to permit persons
+ * to whom  the Software is furnished  to do so, provided  that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the  Software and  that both  the above  copyright notice(s)  and this
+ * permission notice appear in supporting documentation.
+ * 
+ * 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
+ * OF  THIRD PARTY  RIGHTS. IN  NO EVENT  SHALL THE  COPYRIGHT  HOLDER OR
+ * HOLDERS  INCLUDED IN  THIS  NOTICE BE  LIABLE  FOR ANY  CLAIM, OR  ANY
+ * SPECIAL INDIRECT  OR CONSEQUENTIAL DAMAGES, OR  ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS  OF USE, DATA OR PROFITS, WHETHER  IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE  OR OTHER TORTIOUS  ACTION, ARISING OUT OF  OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as  contained in  this notice, the  name of a  copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+package org.slf4j.osgi.integration.simple.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.osgi.integration.IntegrationTestConstants;
+import org.slf4j.osgi.integration.nop.test.NopBundleTest;
+import org.slf4j.osgi.test.service.Probe;
+import org.springframework.osgi.test.ConfigurableBundleCreatorTests;
+
+/**
+ * 
+ * <code>SimpleBundleTest</code> starts up an OSGi environment (equinox,
+ * knopflerfish, or felix according to the profile selected) and installs the
+ * slf4j.osgi.test.bundle, the slf4j.simple bundle and the bundles they depend
+ * on.
+ * 
+ * The test classes in this project will be turned into a virtual bundle which
+ * is also installed and the tests are then run inside the OSGi runtime.
+ * 
+ * The tests have access to a BundleContext, which we use to test that all
+ * bundles have been started.
+ * 
+ * 
+ * @author John Conlon
+ */
+public class SimpleBundleTest extends ConfigurableBundleCreatorTests implements IntegrationTestConstants{
+
+	
+
+	
+	/**
+	 * The manifest to use for the "virtual bundle" created out of the test
+	 * classes and resources in this project
+	 * 
+	 * This is actually the boilerplate manifest with one additional
+	 * import-package added. We should provide a simpler customization point for
+	 * such use cases that doesn't require duplication of the entire manifest...
+	 */
+	protected String getManifestLocation() {
+		return "classpath:org/slf4j/osgi/integration/simple/test/MANIFEST.MF";
+	}
+
+	/**
+	 * The location of the packaged OSGi bundles to be installed for this test.
+	 * Values are Spring resource paths. The bundles we want to use are part of
+	 * the same multi-project maven build as this project is. Hence we use the
+	 * localMavenArtifact helper method to find the bundles produced by the
+	 * package phase of the maven build (these tests will run after the
+	 * packaging phase, in the integration-test phase).
+	 * 
+	 * JUnit, commons-logging, spring-core and the spring OSGi test bundle are
+	 * automatically included so they do not need to be specified here.
+	 * 
+	 * Our test bundles are using package import and export versions to keep
+	 * these other logging bundles from getting mixed up with our test bundles.
+	 */
+	protected String[] getBundleLocations() {
+		return new String[] {
+				localMavenArtifact("org.springframework.osgi",
+						"aopalliance.osgi", "1.0-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi",
+						"spring-context", "2.1-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi", "spring-beans",
+						"2.1-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi",
+						"spring-osgi-core", "1.0-SNAPSHOT"),
+				localMavenArtifact("org.springframework.osgi", "spring-aop",
+						"2.1-SNAPSHOT"),
+				localMavenArtifact("org.slf4j", "slf4j-simple", VERSION),
+				localMavenArtifact("org.slf4j", "jcl104-over-slf4j", VERSION),
+				localMavenArtifact("org.slf4j", "slf4j-osgi-test-bundle",
+						VERSION) };
+	}
+
+	/**
+	 * The superclass provides us access to the root bundle context via the
+	 * 'getBundleContext' operation. Make sure it is not null.
+	 */
+	public void testOSGiStartedOk() {
+		BundleContext bundleContext = getBundleContext();
+		assertNotNull(bundleContext);
+
+	}
+
+	/**
+	 * Makes sure our bundles are in the OSGi runtime and their state is Active.
+	 * 
+	 */
+	public void testSlf4jNopBundles() {
+		Logger log = LoggerFactory.getLogger(SimpleBundleTest.class);
+		assertNotNull(log);
+		BundleContext context = getBundleContext();
+		List symNames = new ArrayList();
+
+		Bundle[] bundles = context.getBundles();
+		log.info("Loaded bundles:");
+		for (int i = 0; i < bundles.length; i++) {
+			Bundle bundle = bundles[i];
+			assertEquals("Bundle " + bundle.getSymbolicName()
+					+ " is not active.", Bundle.ACTIVE, bundle.getState());
+			symNames.add(bundle.getSymbolicName());
+			if (bundle.getHeaders().get(Constants.BUNDLE_ACTIVATOR) != null) {
+				log.info("Symbolic Name:" + bundle.getSymbolicName()
+						+ ", Activator:"
+						+ bundle.getHeaders().get(Constants.BUNDLE_ACTIVATOR));
+			} else {
+				log.info("Symbolic Name:" + bundle.getSymbolicName());
+			}
+		}
+
+		assertTrue(symNames.contains(SLF4J_SIMPLE));
+		assertTrue(symNames.contains(SLF4J_OSGI_TEST));
+		assertTrue(symNames.contains(SLF4J_JCL));
+
+	}
+
+	public void testProbeService() {
+		Logger log = LoggerFactory.getLogger(NopBundleTest.class);
+		log.debug("Testing probe");
+		BundleContext context = getBundleContext();
+		ServiceReference ref = context.getServiceReference(Probe.class.getName());
+		assertNotNull("Service Reference is null", ref);
+		Probe probe = null;
+
+		probe = (Probe) context.getService(ref);
+		assertNotNull("Cannot find the probe service", probe);
+
+		try {
+			probe.testCommonslogging();
+
+		} catch (Throwable t) {
+			fail("Failed to execute the probe.testCommonsLogging. "+t);
+		}
+		context.ungetService(ref);
+	}
+
+}

Added: slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/log4j.properties
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/log4j.properties	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,9 @@
+log4j.rootCategory=DEBUG,console
+
+# Console Appender
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.target=System.out
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%-5p  %l - %m%n
+
+log4j.logger.org.springframework.osgi=DEBUG
\ No newline at end of file

Added: slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/log4j/test/MANIFEST.MF
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/log4j/test/MANIFEST.MF	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-Name: simple-service-integration-tests
+Bundle-SymbolicName: org.slf4j.osgi.integration.log4j.test
+Bundle-Vendor: SLF4J ORG
+Bundle-Activator: org.springframework.osgi.test.JUnitTestActivator
+Import-Package: junit.framework,
+ org.osgi.framework;specification-version="1.3.0",
+ org.springframework.core.io;specification-version="2.1.0",
+ org.springframework.osgi.test,
+ org.springframework.osgi.test.runner,
+ org.slf4j,
+ org.slf4j.osgi.test.service
+ 
+ 
+      

Added: slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/nop/test/MANIFEST.MF
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/nop/test/MANIFEST.MF	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-Name: simple-service-integration-tests
+Bundle-SymbolicName: org.slf4j.osgi.integration.nop.test
+Bundle-Vendor: SLF4J ORG
+Bundle-Activator: org.springframework.osgi.test.JUnitTestActivator
+Import-Package: junit.framework,
+ org.osgi.framework;specification-version="1.3.0",
+ org.springframework.core.io;specification-version="2.1.0",
+ org.springframework.osgi.test,
+ org.springframework.osgi.test.runner,
+ org.slf4j,
+ org.slf4j.osgi.test.service
+ 
+ 
+      

Added: slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/simple/test/MANIFEST.MF
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/simple/test/MANIFEST.MF	Wed Feb  7 17:07:47 2007
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-Name: simple-service-integration-tests
+Bundle-SymbolicName: org.slf4j.osgi.integration.simple.test
+Bundle-Vendor: SLF4J ORG
+Bundle-Activator: org.springframework.osgi.test.JUnitTestActivator
+Import-Package: junit.framework,
+ org.osgi.framework;specification-version="1.3.0",
+ org.springframework.core.io;specification-version="2.1.0",
+ org.springframework.osgi.test,
+ org.springframework.osgi.test.runner,
+ org.slf4j,
+ org.slf4j.osgi.test.service
+ 
+ 
+      



More information about the slf4j-dev mailing list