You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/04/16 05:22:38 UTC
svn commit: r1587790 - in
/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi:
AbstractLoadBundleTest.java OSGiRule.java
equinox/AbstractEquinoxLoadBundleTest.java
felix/AbstractFelixLoadBundleTest.java
Author: mattsicker
Date: Wed Apr 16 03:22:37 2014
New Revision: 1587790
URL: http://svn.apache.org/r1587790
Log:
Refactor OSGi tests using new test rule.
Added:
logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/OSGiRule.java (with props)
Modified:
logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/AbstractLoadBundleTest.java
logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/equinox/AbstractEquinoxLoadBundleTest.java
logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/felix/AbstractFelixLoadBundleTest.java
Modified: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/AbstractLoadBundleTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/AbstractLoadBundleTest.java?rev=1587790&r1=1587789&r2=1587790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/AbstractLoadBundleTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/AbstractLoadBundleTest.java Wed Apr 16 03:22:37 2014
@@ -18,15 +18,16 @@ package org.apache.logging.log4j.osgi;
import java.io.File;
-import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
/**
* Tests loading a bundle into an OSGi container.
@@ -39,20 +40,10 @@ import org.osgi.framework.launch.Framewo
*/
public abstract class AbstractLoadBundleTest {
- protected static Framework OsgiFramework;
+ protected abstract FrameworkFactory getFactory();
- /**
- * Uninstalls the OSGi framework.
- *
- * @throws BundleException
- */
- @AfterClass
- public static void afterClass() throws BundleException {
- if (OsgiFramework != null) {
- OsgiFramework.stop();
- OsgiFramework = null;
- }
- }
+ @Rule
+ public OSGiRule osgi = new OSGiRule(getFactory());
private final BundleTestInfo bundleTestInfo;
@@ -96,9 +87,11 @@ public abstract class AbstractLoadBundle
*/
@Test
public void testLoadStartStop() throws BundleException {
- final BundleContext bundleContext = OsgiFramework.getBundleContext();
+ final BundleContext bundleContext = osgi.getFramework().getBundleContext();
final Bundle bundle = bundleContext.installBundle("file:" + getBundlePath());
Assert.assertNotNull("Error loading bundle: null returned", bundle);
+ Assert.assertEquals("Error loading bundle: symbolic name mismatch", getExpectedBundleSymbolicName(),
+ bundle.getSymbolicName());
Assert.assertEquals("Bundle is not in INSTALLED state", Bundle.INSTALLED, bundle.getState());
// sanity check: start and stop bundle
Added: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/OSGiRule.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/OSGiRule.java?rev=1587790&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/OSGiRule.java (added)
+++ logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/OSGiRule.java Wed Apr 16 03:22:37 2014
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.osgi;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.rules.ExternalResource;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * @author msicker
+ * @version 1.0.0
+ */
+public class OSGiRule extends ExternalResource {
+
+ private final FrameworkFactory factory;
+ private Framework framework;
+
+ public OSGiRule(final FrameworkFactory factory) {
+ this.factory = factory;
+ }
+
+ public Framework getFramework() {
+ return framework;
+ }
+
+ @Override
+ protected void before() throws Throwable {
+ final Map<String, String> configMap = new HashMap<String, String>(2);
+ // Cleans framework before first init. Subsequent init invocations do not clean framework.
+ configMap.put("org.osgi.framework.storage.clean", "onFirstInit");
+ // Delegates loading of endorsed libraries to JVM classloader
+ // config.put("org.osgi.framework.bootdelegation", "javax.*,org.w3c.*,org.xml.*");
+ framework = factory.newFramework(configMap);
+ framework.init();
+ framework.start();
+ }
+
+ @Override
+ protected void after() {
+ if (framework != null) {
+ try {
+ framework.stop();
+ } catch (BundleException e) {
+ throw new RuntimeException(e);
+ } finally {
+ framework = null;
+ }
+ }
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/OSGiRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/equinox/AbstractEquinoxLoadBundleTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/equinox/AbstractEquinoxLoadBundleTest.java?rev=1587790&r1=1587789&r2=1587790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/equinox/AbstractEquinoxLoadBundleTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/equinox/AbstractEquinoxLoadBundleTest.java Wed Apr 16 03:22:37 2014
@@ -16,13 +16,8 @@
*/
package org.apache.logging.log4j.osgi.equinox;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.logging.log4j.osgi.AbstractLoadBundleTest;
import org.eclipse.osgi.launch.EquinoxFactory;
-import org.junit.BeforeClass;
-import org.osgi.framework.BundleException;
import org.osgi.framework.launch.FrameworkFactory;
/**
@@ -30,22 +25,9 @@ import org.osgi.framework.launch.Framewo
*/
public abstract class AbstractEquinoxLoadBundleTest extends AbstractLoadBundleTest {
- /**
- * Initializes the OSGi framework.
- *
- * @throws BundleException
- */
- @BeforeClass
- public static void initOsgiFramework() throws BundleException {
- final FrameworkFactory factory = new EquinoxFactory();
- final Map<String, String> configMap = new HashMap<String, String>(2);
- // Cleans framework before first init. Subsequent init invocations do not clean framework.
- configMap.put("org.osgi.framework.storage.clean", "onFirstInit");
- // Delegates loading of endorsed libraries to JVM classloader
- // config.put("org.osgi.framework.bootdelegation", "javax.*,org.w3c.*,org.xml.*");
- OsgiFramework = factory.newFramework(configMap);
- OsgiFramework.init();
- OsgiFramework.start();
+ @Override
+ protected FrameworkFactory getFactory() {
+ return new EquinoxFactory();
}
}
Modified: logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/felix/AbstractFelixLoadBundleTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/felix/AbstractFelixLoadBundleTest.java?rev=1587790&r1=1587789&r2=1587790&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/felix/AbstractFelixLoadBundleTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/test/java/org/apache/logging/log4j/osgi/felix/AbstractFelixLoadBundleTest.java Wed Apr 16 03:22:37 2014
@@ -16,13 +16,8 @@
*/
package org.apache.logging.log4j.osgi.felix;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.logging.log4j.osgi.AbstractLoadBundleTest;
import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.osgi.framework.BundleException;
import org.osgi.framework.launch.FrameworkFactory;
/**
@@ -36,22 +31,9 @@ import org.osgi.framework.launch.Framewo
*/
public abstract class AbstractFelixLoadBundleTest extends AbstractLoadBundleTest {
- /**
- * Initializes the OSGi framework.
- *
- * @throws BundleException
- */
- @BeforeClass
- public static void initOsgiFramework() throws BundleException {
- final FrameworkFactory factory = new org.apache.felix.framework.FrameworkFactory();
- final Map<String, String> configMap = new HashMap<String, String>(2);
- // Cleans framework before first init. Subsequent init invocations do not clean framework.
- configMap.put("org.osgi.framework.storage.clean", "onFirstInit");
- // Delegates loading of endorsed libraries to JVM classloader
- // config.put("org.osgi.framework.bootdelegation", "javax.*,org.w3c.*,org.xml.*");
- OsgiFramework = factory.newFramework(configMap);
- OsgiFramework.init();
- OsgiFramework.start();
+ @Override
+ protected FrameworkFactory getFactory() {
+ return new org.apache.felix.framework.FrameworkFactory();
}
}