Author: jconlon
Date: Wed Feb  7 18:12:17 2007
New Revision: 717

Added:
   
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/jdk/
   
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/jdk/test/
   
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/jdk/test/JdkBundleTest.java
   
slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/jdk/
   
slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/jdk/test/
   
slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/jdk/test/MANIFEST.MF
Modified:
   
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/test/Log4JBundleTest.java
   
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/test/SimpleBundleTest.java

Log:
Added tests for the jdk104 binding bundle.
Refactored more strings to constants.

Modified: 
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/IntegrationTestConstants.java
      (original)
+++ 
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/IntegrationTestConstants.java
      Wed Feb  7 18:12:17 2007
@@ -32,18 +32,42 @@
 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";
+    
+    /**
+     * Versions of this release.
+     */
+    public static final String SLF4J_VERSION_UNDER_TEST = "1.3.0-SNAPSHOT";
+    
+    public static final String SLF4J_GROUP_ID = "org.slf4j";
+    
+    public static final String SPRINGFRAMEWORK_OSGI_GROUP_NAME = 
"org.springframework.osgi";
+    
+
+    public static final String JCL104_ADAPTER_BUNDLE_ARTIFACT_ID = 
"jcl104-over-slf4j";
+
+    public static final String JDK14_BINDING_BUNDLE_ARTIFACT_ID = 
"slf4j-jdk14";
+
+    public static final String SIMPLE_BINDING_BUNDLE_ARTIFACT_ID = 
"slf4j-simple";
+
+    public static final String LOG4J12_BINDING_BUNDLE_ARTIFACT_ID = 
"slf4j-log4j12";
+
+    public static final String NOP_BINDING_BUNDLE_ARTIFACT_ID = "slf4j-nop";
+
+    public static final String TEST_BUNDLE_ARTIFACT_ID = 
"slf4j-osgi-test-bundle";
+
+    
+    public static final String TEST_BUNDLE_SYM_NAME = 
SLF4J_GROUP_ID+'.'+TEST_BUNDLE_ARTIFACT_ID;
+    
+       public static final String NOP_BINDING_BUNDLE_SYM_NAME = 
SLF4J_GROUP_ID+'.'+NOP_BINDING_BUNDLE_ARTIFACT_ID;
+   
+       public static final String LOG4J_BINDING_BUNDLE_SYM_NAME = 
SLF4J_GROUP_ID+'.'+LOG4J12_BINDING_BUNDLE_ARTIFACT_ID;
        
-       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 SIMPLE_BINDING_BUNDLE_SYM_NAME = 
SLF4J_GROUP_ID+'.'+SIMPLE_BINDING_BUNDLE_ARTIFACT_ID;
+    
+    public static final String JDK_BINDING_BUNDLE_SYM_NAME = 
SLF4J_GROUP_ID+'.'+JDK14_BINDING_BUNDLE_ARTIFACT_ID;
        
-       public static final String VERSION = "1.3.0-SNAPSHOT";
+       public static final String JCL_ADAPTER_BUNDLE_SYM_NAME = 
SLF4J_GROUP_ID+'.'+JCL104_ADAPTER_BUNDLE_ARTIFACT_ID;
+   
+    
+    
 }

Added: 
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/jdk/test/JdkBundleTest.java
==============================================================================
--- (empty file)
+++ 
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/jdk/test/JdkBundleTest.java
        Wed Feb  7 18:12:17 2007
@@ -0,0 +1,175 @@
+/* 
+ * 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.jdk.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>JdkBundleTest</code>  starts up an OSGi environment (equinox,
+ * knopflerfish, or felix according to the profile selected) and installs the
+ * slf4j.osgi.test.bundle, the slf4j.jdk 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 JdkBundleTest 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/jdk/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(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
+                                               "aopalliance.osgi", 
"1.0-SNAPSHOT"),
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
+                                               "spring-context", 
"2.1-SNAPSHOT"),
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME, "spring-beans",
+                                               "2.1-SNAPSHOT"),
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
+                                               "spring-osgi-core", 
"1.0-SNAPSHOT"),
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME, "spring-aop",
+                                               "2.1-SNAPSHOT"),
+                                               
localMavenArtifact(SLF4J_GROUP_ID, JDK14_BINDING_BUNDLE_ARTIFACT_ID, 
SLF4J_VERSION_UNDER_TEST),
+                                               
localMavenArtifact(SLF4J_GROUP_ID, TEST_BUNDLE_ARTIFACT_ID,
+                                                               
SLF4J_VERSION_UNDER_TEST) };
+       }
+
+       /**
+        * 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(JdkBundleTest.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(JDK_BINDING_BUNDLE_SYM_NAME));
+               assertTrue(symNames.contains(TEST_BUNDLE_SYM_NAME));
+
+       }
+       
+       public void testProbeService(){
+               Logger log = LoggerFactory.getLogger(JdkBundleTest.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.");
+       }
+
+}

Modified: 
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/log4j/test/Log4JBundleTest.java
    (original)
+++ 
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/log4j/test/Log4JBundleTest.java
    Wed Feb  7 18:12:17 2007
@@ -101,19 +101,19 @@
         */
        protected String[] getBundleLocations() {
                return new String[] {
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "aopalliance.osgi", 
"1.0-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "spring-context", 
"2.1-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi", 
"spring-beans",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME, "spring-beans",
                                                "2.1-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "spring-osgi-core", 
"1.0-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi", 
"spring-aop",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME, "spring-aop",
                                                "2.1-SNAPSHOT"),
-                               localMavenArtifact("org.slf4j", 
"slf4j-log4j12", VERSION),
-                               localMavenArtifact("org.slf4j", 
"slf4j-osgi-test-bundle",
-                                               VERSION) };
+                               localMavenArtifact(SLF4J_GROUP_ID, 
LOG4J12_BINDING_BUNDLE_ARTIFACT_ID, SLF4J_VERSION_UNDER_TEST),
+                               localMavenArtifact(SLF4J_GROUP_ID, 
TEST_BUNDLE_ARTIFACT_ID,
+                                               SLF4J_VERSION_UNDER_TEST) };
        }
 
        /**
@@ -152,8 +152,8 @@
                        }
                }
 
-               assertTrue(symNames.contains(SLF4J_LOG4J));
-               assertTrue(symNames.contains(SLF4J_OSGI_TEST));
+               assertTrue(symNames.contains(LOG4J_BINDING_BUNDLE_SYM_NAME));
+               assertTrue(symNames.contains(TEST_BUNDLE_SYM_NAME));
 
        }
 

Modified: 
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/nop/test/NopBundleTest.java
        (original)
+++ 
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/nop/test/NopBundleTest.java
        Wed Feb  7 18:12:17 2007
@@ -47,7 +47,7 @@
 
 /**
  * 
- * <code>NopBundleTest</code>  starts up an OSGi environment (equinox,
+ * <code>JdkBundleTest</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. 
  * 
@@ -92,19 +92,19 @@
         */
        protected String[] getBundleLocations() {
                return new String[] {
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "aopalliance.osgi", 
"1.0-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "spring-context", 
"2.1-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi", 
"spring-beans",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME, "spring-beans",
                                                "2.1-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "spring-osgi-core", 
"1.0-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi", 
"spring-aop",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME, "spring-aop",
                                                "2.1-SNAPSHOT"),
-                                               localMavenArtifact("org.slf4j", 
"slf4j-nop", VERSION),
-                                               localMavenArtifact("org.slf4j", 
"slf4j-osgi-test-bundle",
-                                                               VERSION) };
+                                               
localMavenArtifact(SLF4J_GROUP_ID, NOP_BINDING_BUNDLE_ARTIFACT_ID, 
SLF4J_VERSION_UNDER_TEST),
+                                               
localMavenArtifact(SLF4J_GROUP_ID, TEST_BUNDLE_ARTIFACT_ID,
+                                                               
SLF4J_VERSION_UNDER_TEST) };
        }
 
        /**
@@ -143,8 +143,8 @@
                        }
                }
 
-               assertTrue(symNames.contains(SLF4J_NOP));
-               assertTrue(symNames.contains(SLF4J_OSGI_TEST));
+               assertTrue(symNames.contains(NOP_BINDING_BUNDLE_SYM_NAME));
+               assertTrue(symNames.contains(TEST_BUNDLE_SYM_NAME));
 
        }
        

Modified: 
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/java/org/slf4j/osgi/integration/simple/test/SimpleBundleTest.java
  (original)
+++ 
slf4j/trunk/slf4j-osgi-integration-test/src/test/java/org/slf4j/osgi/integration/simple/test/SimpleBundleTest.java
  Wed Feb  7 18:12:17 2007
@@ -95,20 +95,20 @@
         */
        protected String[] getBundleLocations() {
                return new String[] {
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "aopalliance.osgi", 
"1.0-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "spring-context", 
"2.1-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi", 
"spring-beans",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME, "spring-beans",
                                                "2.1-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME,
                                                "spring-osgi-core", 
"1.0-SNAPSHOT"),
-                               localMavenArtifact("org.springframework.osgi", 
"spring-aop",
+                               
localMavenArtifact(SPRINGFRAMEWORK_OSGI_GROUP_NAME, "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) };
+                               localMavenArtifact(SLF4J_GROUP_ID, 
SIMPLE_BINDING_BUNDLE_ARTIFACT_ID, SLF4J_VERSION_UNDER_TEST),
+                               localMavenArtifact(SLF4J_GROUP_ID, 
JCL104_ADAPTER_BUNDLE_ARTIFACT_ID, SLF4J_VERSION_UNDER_TEST),
+                               localMavenArtifact(SLF4J_GROUP_ID, 
TEST_BUNDLE_ARTIFACT_ID,
+                                               SLF4J_VERSION_UNDER_TEST) };
        }
 
        /**
@@ -147,9 +147,9 @@
                        }
                }
 
-               assertTrue(symNames.contains(SLF4J_SIMPLE));
-               assertTrue(symNames.contains(SLF4J_OSGI_TEST));
-               assertTrue(symNames.contains(SLF4J_JCL));
+               assertTrue(symNames.contains(SIMPLE_BINDING_BUNDLE_SYM_NAME));
+               assertTrue(symNames.contains(TEST_BUNDLE_SYM_NAME));
+               assertTrue(symNames.contains(JCL_ADAPTER_BUNDLE_SYM_NAME));
 
        }
 

Added: 
slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/jdk/test/MANIFEST.MF
==============================================================================
--- (empty file)
+++ 
slf4j/trunk/slf4j-osgi-integration-test/src/test/resources/org/slf4j/osgi/integration/jdk/test/MANIFEST.MF
  Wed Feb  7 18:12:17 2007
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-Name: simple-service-integration-tests
+Bundle-SymbolicName: org.slf4j.osgi.integration.jdk.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
+ 
+ 
+      
_______________________________________________
dev mailing list
dev@slf4j.org
http://www.slf4j.org/mailman/listinfo/dev

Reply via email to