You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/09/03 11:19:52 UTC
svn commit: r1519609 - in /felix/trunk/ipojo/handler/temporal:
temporal-dependency-handler-it/
temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/
temporal-dependency-handler/ temporal-dependenc...
Author: clement
Date: Tue Sep 3 09:19:52 2013
New Revision: 1519609
URL: http://svn.apache.org/r1519609
Log:
Migrate temporal dependency handler tests to new IT structure
Modified:
felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/pom.xml
felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/Common.java
felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/pom.xml
felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java
Modified: felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/pom.xml?rev=1519609&r1=1519608&r2=1519609&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/pom.xml (original)
+++ felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/pom.xml Tue Sep 3 09:19:52 2013
@@ -74,7 +74,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo</artifactId>
- <version>1.8.6</version>
+ <version>1.10.1</version>
<scope>test</scope>
</dependency>
@@ -138,7 +138,7 @@
<dependency>
<groupId>org.ow2.chameleon.testing</groupId>
<artifactId>osgi-helpers</artifactId>
- <version>0.6.0</version>
+ <version>0.6.1</version>
</dependency>
<dependency>
Modified: felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/Common.java?rev=1519609&r1=1519608&r2=1519609&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/Common.java (original)
+++ felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/Common.java Tue Sep 3 09:19:52 2013
@@ -19,197 +19,22 @@
package org.apache.felix.ipojo.handler.temporal.test;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import org.ow2.chameleon.testing.helpers.BaseTest;
-import static junit.framework.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
/**
* Bootstrap the test from this project
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
-
- @Inject
- BundleContext bc;
-
- OSGiHelper osgiHelper;
- IPOJOHelper ipojoHelper;
-
- Bundle testedBundle;
-
- @Configuration
- public Option[] config() throws IOException {
- Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
- root.setLevel(Level.DEBUG);
-
- return options(
- cleanCaches(),
- ipojoBundles(),
- junitBundles(),
- testedBundle(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
- );
- }
-
- public static Option junitAndMockitoBundles() {
- return new DefaultCompositeOption(
- // Repository required to load harmcrest (OSGi-fied version).
- repository("http://repository.springsource.com/maven/bundles/external").id(
- "com.springsource.repository.bundles.external"),
-
- // Hamcrest with a version matching the range expected by Mockito
- mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
-
- // Mockito core does not includes Hamcrest
- mavenBundle("org.mockito", "mockito-core", "1.9.5"),
-
- // Objenesis with a version matching the range expected by Mockito
- wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
- .exports("*;version=1.2"),
-
- // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
- // 4.9 which does not match the Mockito import. When deployed after the hamcrest bundles, it gets
- // resolved correctly.
- CoreOptions.junitBundles(),
-
- /*
- * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
- * java.lang.LinkageError: loader constraint violation in interface itable initialization:
- * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
- * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
- * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
- * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
- * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
- * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
- * proxy/Callback used in the signature
- *
- * So we disable the bootdelegation. this property has no effect on the other OSGi implementation.
- */
- frameworkProperty("felix.bootdelegation.implicit").value("false")
- );
- }
-
- @Before
- public void commonSetUp() {
- osgiHelper = new OSGiHelper(bc);
- ipojoHelper = new IPOJOHelper(bc);
-
- testedBundle = osgiHelper.getBundle("test.bundle");
-
- // Dump OSGi Framework information
- String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
- if (vendor == null) {
- vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
- }
- String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
- System.out.println("OSGi Framework : " + vendor + " - " + version);
- }
-
- @After
- public void commonTearDown() {
- ipojoHelper.dispose();
- osgiHelper.dispose();
- }
+public class Common extends BaseTest {
- public static CompositeOption ipojoBundles() {
- return new DefaultCompositeOption(
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
- mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
- // The tested handler
- mavenBundle("org.apache.felix", "org.apache.felix.ipojo.handler.temporal").versionAsInProject()
- );
+ @Override
+ protected Option[] getCustomOptions() {
+ return new Option[]{
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo.handler.temporal")
+ .versionAsInProject()
+ };
}
- public Option testedBundle() throws MalformedURLException {
- File out = new File("target/tested/bundle.jar");
-
- TinyBundle tested = TinyBundles.bundle();
-
- // We look inside target/classes to find the class and resources
- File classes = new File("target/classes");
- Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
- List<File> services = new ArrayList<File>();
- for (File file : files) {
- if (file.isDirectory()) {
- // By convention we export of .services and .service package
- if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
- services.add(file);
- }
- } else {
- // We need to compute the path
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- tested.add(path, file.toURI().toURL());
- System.out.println(file.getName() + " added to " + path);
- }
- }
-
- String export = "";
- for (File file : services) {
- if (export.length() > 0) { export += ", "; }
- String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
- String packageName = path.replace('/', '.');
- export += packageName;
- }
-
- System.out.println("Exported packages : " + export);
-
- InputStream inputStream = tested
- .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
- .set(Constants.EXPORT_PACKAGE, export)
- .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
- try {
- FileUtils.copyInputStreamToFile(inputStream, out);
- return bundle(out.toURI().toURL().toExternalForm());
- } catch (MalformedURLException e) {
- throw new RuntimeException("Cannot compute the url of the manipulated bundle");
- } catch (IOException e) {
- throw new RuntimeException("Cannot write of the manipulated bundle");
- }
- }
-
- public void assertContains(String s, String[] arrays, String object) {
- for (String suspect : arrays) {
- if (object.equals(suspect)) {
- return;
- }
- }
- fail("Assertion failed : " + s);
- }
-
-
}
Modified: felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/pom.xml?rev=1519609&r1=1519608&r2=1519609&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/pom.xml (original)
+++ felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/pom.xml Tue Sep 3 09:19:52 2013
@@ -76,7 +76,7 @@
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>
- org.apache.felix.ipojo;version=1.8.1,
+ org.apache.felix.ipojo;version=1.10.0,
!org.objectweb.asm.tree, *
</Import-Package>
<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
@@ -91,15 +91,12 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-ipojo-plugin</artifactId>
- <version>1.6.0</version>
+ <version>1.10.1</version>
<executions>
<execution>
<goals>
<goal>ipojo-bundle</goal>
</goals>
- <configuration>
- <metadata>metadata.xml</metadata>
- </configuration>
</execution>
</executions>
</plugin>
Modified: felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java?rev=1519609&r1=1519608&r2=1519609&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java (original)
+++ felix/trunk/ipojo/handler/temporal/temporal-dependency-handler/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java Tue Sep 3 09:19:52 2013
@@ -18,37 +18,33 @@
*/
package org.apache.felix.ipojo.handler.temporal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.List;
-
import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.PrimitiveHandler;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.FieldMetadata;
import org.apache.felix.ipojo.parser.MethodMetadata;
import org.apache.felix.ipojo.parser.PojoMetadata;
+import org.apache.felix.ipojo.util.DependencyMetadataHelper;
import org.apache.felix.ipojo.util.DependencyModel;
import org.apache.felix.ipojo.util.DependencyStateListener;
-import org.apache.felix.ipojo.util.DependencyMetadataHelper;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
+import java.util.*;
+
/**
-* Temporal dependency handler.
-* A temporal dependency waits (block) for the availability of the service.
-* If no provider arrives in the specified among of time, a runtime exception is thrown.
-* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
-*/
+ * Temporal dependency handler.
+ * A temporal dependency waits (block) for the availability of the service.
+ * If no provider arrives in the specified among of time, a runtime exception is thrown.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
public class TemporalHandler extends PrimitiveHandler implements DependencyStateListener {
/**
* Default timeout if not specified.
*/
public static final int DEFAULT_TIMEOUT = 3000;
-
/**
* No policy.
*/
@@ -69,12 +65,10 @@ public class TemporalHandler extends Pri
* Uses {@code null}.
*/
public static final int NULL = 4;
-
/**
* The handler namespace.
*/
public static final String NAMESPACE = "org.apache.felix.ipojo.handler.temporal";
-
/**
* The list of managed dependencies.
*/
@@ -82,6 +76,7 @@ public class TemporalHandler extends Pri
/**
* Start method. Starts managed dependencies.
+ *
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
@@ -92,6 +87,7 @@ public class TemporalHandler extends Pri
/**
* Stop method. Stops managed dependencies.
+ *
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
@@ -103,7 +99,8 @@ public class TemporalHandler extends Pri
/**
* Configure method. Creates managed dependencies.
- * @param meta the component type metadata.
+ *
+ * @param meta the component type metadata.
* @param dictionary the instance configuration.
* @throws ConfigurationException if the dependency is not configured correctly
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
@@ -114,20 +111,20 @@ public class TemporalHandler extends Pri
// Also check with temporal is no requires.
if (deps == null || deps.length == 0) {
- deps = meta.getElements("temporal", NAMESPACE);
+ deps = meta.getElements("temporal", NAMESPACE);
}
-
+
// Get instance filters.
Dictionary filtersConfiguration = getRequiresFilters(dictionary.get("temporal.filters"));
- if(filtersConfiguration == null || filtersConfiguration.isEmpty()) {
- // Fall back on the Requires handler configuration, if any
- filtersConfiguration = getRequiresFilters(dictionary.get("requires.filters"));
+ if (filtersConfiguration == null || filtersConfiguration.isEmpty()) {
+ // Fall back on the Requires handler configuration, if any
+ filtersConfiguration = getRequiresFilters(dictionary.get("requires.filters"));
}
// Get from filters if any.
Dictionary fromConfiguration = getRequiresFilters(dictionary.get("temporal.from"));
- if(fromConfiguration == null || fromConfiguration.isEmpty()) {
- // Fall back on the Requires handler configuration, if any
- fromConfiguration = getRequiresFilters(dictionary.get("requires.from"));
+ if (fromConfiguration == null || fromConfiguration.isEmpty()) {
+ // Fall back on the Requires handler configuration, if any
+ fromConfiguration = getRequiresFilters(dictionary.get("requires.from"));
}
@@ -202,16 +199,16 @@ public class TemporalHandler extends Pri
String prox = deps[i].getAttribute("proxy");
// Use proxy by default except for array:
- boolean proxy = prox == null || prox.equals("true");
+ boolean proxy = prox == null || prox.equals("true");
- if (prox == null && proxy) { // Proxy set because of the default.
- if (agg && ! collection) { // Aggregate and array
+ if (prox == null && proxy) { // Proxy set because of the default.
+ if (agg && !collection) { // Aggregate and array
proxy = false;
}
}
if (proxy && agg) {
- if (! collection) {
+ if (!collection) {
error("Proxied aggregate temporal dependencies cannot be an array. Only collections are supported");
}
}
@@ -219,7 +216,7 @@ public class TemporalHandler extends Pri
long timeout = DEFAULT_TIMEOUT;
if (deps[i].containsAttribute("timeout")) {
String to = deps[i].getAttribute("timeout");
- if (to.equalsIgnoreCase("infinite") || to.equalsIgnoreCase("-1")) {
+ if (to.equalsIgnoreCase("infinite") || to.equalsIgnoreCase("-1")) {
timeout = Long.MAX_VALUE; // Infinite wait time ...
} else {
timeout = new Long(deps[i].getAttribute("timeout")).longValue();
@@ -232,9 +229,9 @@ public class TemporalHandler extends Pri
if (onTimeout != null) {
if (onTimeout.equalsIgnoreCase("nullable")) {
policy = NULLABLE;
- } else if (onTimeout.equalsIgnoreCase("empty-array") || onTimeout.equalsIgnoreCase("empty")) {
+ } else if (onTimeout.equalsIgnoreCase("empty-array") || onTimeout.equalsIgnoreCase("empty")) {
policy = EMPTY;
- if (! agg) {
+ if (!agg) {
// The empty array policy can only be used on aggregate dependencies
error("Cannot use the empty array policy for " + field + " : non aggregate dependency.");
}
@@ -250,7 +247,7 @@ public class TemporalHandler extends Pri
TemporalDependency dep = new TemporalDependency(specification, agg, collection, proxy, filter, getInstanceManager().getContext(), timeout, policy, di, this);
m_dependencies.add(dep);
- if (! proxy) { // Register method interceptor only if are not a proxy
+ if (!proxy) { // Register method interceptor only if are not a proxy
MethodMetadata[] methods = manipulation.getMethods();
for (int k = 0; k < methods.length; k++) {
getInstanceManager().register(methods[k], dep);
@@ -260,57 +257,61 @@ public class TemporalHandler extends Pri
getInstanceManager().register(fieldmeta, dep);
}
}
-
+
/**
- * Gets the requires filter configuration from the given object.
- * The given object must come from the instance configuration.
- * This method was made to fix FELIX-2688. It supports filter configuration using
- * an array:
- * <code>{"myFirstDep", "(property1=value1)", "mySecondDep", "(property2=value2)"});</code>
- *
- * Copied from DependencyHandler#getRequiresFilters(Object)
- *
- * @param requiresFiltersValue the value contained in the instance
- * configuration.
- * @return the dictionary. If the object in already a dictionary, just returns it,
- * if it's an array, builds the dictionary.
- * @throws ConfigurationException the dictionary cannot be built
- */
- private Dictionary getRequiresFilters(Object requiresFiltersValue)
- throws ConfigurationException {
- if (requiresFiltersValue != null
- && requiresFiltersValue.getClass().isArray()) {
- String[] filtersArray = (String[]) requiresFiltersValue;
- if (filtersArray.length % 2 != 0) {
- throw new ConfigurationException(
- "A requirement filter is invalid : "
- + requiresFiltersValue);
- }
- Dictionary requiresFilters = new Hashtable();
- for (int i = 0; i < filtersArray.length; i += 2) {
- requiresFilters.put(filtersArray[i], filtersArray[i + 1]);
- }
- return requiresFilters;
- }
+ * Gets the requires filter configuration from the given object.
+ * The given object must come from the instance configuration.
+ * This method was made to fix FELIX-2688. It supports filter configuration using
+ * an array:
+ * <code>{"myFirstDep", "(property1=value1)", "mySecondDep", "(property2=value2)"});</code>
+ * <p/>
+ * Copied from DependencyHandler#getRequiresFilters(Object)
+ *
+ * @param requiresFiltersValue the value contained in the instance
+ * configuration.
+ * @return the dictionary. If the object in already a dictionary, just returns it,
+ * if it's an array, builds the dictionary.
+ * @throws ConfigurationException the dictionary cannot be built
+ */
+ private Dictionary getRequiresFilters(Object requiresFiltersValue)
+ throws ConfigurationException {
+ if (requiresFiltersValue != null
+ && requiresFiltersValue.getClass().isArray()) {
+ String[] filtersArray = (String[]) requiresFiltersValue;
+ if (filtersArray.length % 2 != 0) {
+ throw new ConfigurationException(
+ "A requirement filter is invalid : "
+ + requiresFiltersValue);
+ }
+ Dictionary requiresFilters = new Hashtable();
+ for (int i = 0; i < filtersArray.length; i += 2) {
+ requiresFilters.put(filtersArray[i], filtersArray[i + 1]);
+ }
+ return requiresFilters;
+ }
- return (Dictionary) requiresFiltersValue;
- }
+ return (Dictionary) requiresFiltersValue;
+ }
/**
* Nothing to do.
* A temporal dependency is always valid.
+ *
* @param dependencymodel dependency.
* @see org.apache.felix.ipojo.util.DependencyStateListener#invalidate(org.apache.felix.ipojo.util.DependencyModel)
*/
- public void invalidate(DependencyModel dependencymodel) { }
+ public void invalidate(DependencyModel dependencymodel) {
+ }
/**
* Nothing to do.
* A temporal dependency is always valid.
+ *
* @param dependencymodel dependency.
* @see org.apache.felix.ipojo.util.DependencyStateListener#validate(org.apache.felix.ipojo.util.DependencyModel)
*/
- public void validate(DependencyModel dependencymodel) { }
+ public void validate(DependencyModel dependencymodel) {
+ }
}