FELIX-3903
Migrate the core logger tests to pax exam 3
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1447501 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/pom.xml b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/pom.xml
new file mode 100644
index 0000000..3753ac9
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/pom.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.runtime.core-it</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-core-logger-test</artifactId>
+
+ <name>${project.artifactId}</name>
+
+</project>
\ No newline at end of file
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyComponent.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyComponent.java
new file mode 100644
index 0000000..788027a
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyComponent.java
@@ -0,0 +1,11 @@
+package org.apache.felix.ipojo.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+
+public class MyComponent implements MyService {
+
+ public void foo() {
+ // Nothing to do.
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyErroneousComponent.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyErroneousComponent.java
new file mode 100644
index 0000000..9f6b79f
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyErroneousComponent.java
@@ -0,0 +1,15 @@
+package org.apache.felix.ipojo.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+
+public class MyErroneousComponent implements MyService {
+
+ public MyErroneousComponent() {
+ throw new NullPointerException("bad");
+ }
+
+ public void foo() {
+ // Nothing to do.
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/MyService.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/MyService.java
new file mode 100644
index 0000000..c490a65
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/MyService.java
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.runtime.core.services;
+
+public interface MyService {
+
+ public void foo();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/resources/component.xml b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/resources/component.xml
new file mode 100644
index 0000000..aef5ac7
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/resources/component.xml
@@ -0,0 +1,6 @@
+<ipojo>
+ <component classname="org.apache.felix.ipojo.runtime.core.components.MyComponent">
+ <provides/>
+ </component>
+ <instance component="org.apache.felix.ipojo.runtime.core.components.MyComponent"/>
+</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/resources/erroneous-component.xml b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/resources/erroneous-component.xml
new file mode 100644
index 0000000..6143c29
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/main/resources/erroneous-component.xml
@@ -0,0 +1,5 @@
+<ipojo>
+ <component immediate="true" classname="org.apache.felix.ipojo.runtime.core.components.MyErroneousComponent">
+ <provides/>
+ </component>
+</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
new file mode 100644
index 0000000..6075ad2
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -0,0 +1,197 @@
+package org.apache.felix.ipojo.runtime.core;
+
+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.exam.spi.reactors.PerMethod;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+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 static junit.framework.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+/**
+ * Bootstrap the test from this project
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class Common {
+
+ @Inject
+ BundleContext bc;
+
+ OSGiHelper osgiHelper;
+ IPOJOHelper ipojoHelper;
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ root.setLevel(Level.INFO);
+
+ return options(
+ ipojoBundles(),
+ junitBundles(),
+ //testedBundle(), // No tested bundle to deploy
+ 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"),
+
+ // Mockito without Hamcrest and Objenesis
+ mavenBundle("org.mockito", "mockito-core", "1.9.5"),
+
+ // Hamcrest with a version matching the range expected by Mockito
+ mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
+
+ // 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.
+ 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.
+ */
+ frameworkProperty("felix.bootdelegation.implicit").value("false")
+ );
+ }
+
+
+ @Before
+ public void commonSetUp() {
+ osgiHelper = new OSGiHelper(bc);
+ ipojoHelper = new IPOJOHelper(bc);
+
+ // 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 CompositeOption ipojoBundles() {
+ return new DefaultCompositeOption(
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+ mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
+ // harmcrest-all
+ //mavenBundle("de.twentyeleven.skysail", "org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
+ // configuration admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
+ );
+ }
+
+ public Option testedBundle() throws MalformedURLException {
+ File out = new File("target/tested/bundle.jar");
+ if (out.exists()) {
+ return bundle(out.toURI().toURL().toExternalForm());
+ }
+
+ 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.IMPORT_PACKAGE, "*")
+ .set(Constants.EXPORT_PACKAGE, export)
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
+
+ try {
+ org.apache.commons.io.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);
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/SystemLoggerWarningTest.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/SystemLoggerWarningTest.java
new file mode 100644
index 0000000..99b49ee
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/SystemLoggerWarningTest.java
@@ -0,0 +1,83 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.runtime.core.components.MyComponent;
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+
+public class SystemLoggerWarningTest extends Common {
+
+ private LogReaderService log;
+
+ @Before
+ public void init() {
+ log = (LogReaderService) osgiHelper.getServiceObject(LogReaderService.class.getName(), null);
+ if (log == null) {
+ throw new RuntimeException("No Log Service !");
+ }
+
+ LogService logs = (LogService) osgiHelper.getServiceObject(LogService.class.getName(), null);
+ logs.log(LogService.LOG_WARNING, "Ready");
+ }
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ return OptionUtils.combine(options,
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version(asInProject()),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyService.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceInterface")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.services")
+ .build(TinyBundles.withBnd())
+ ),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyComponent.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "MyComponent")
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources/component.xml")))
+ ),
+ systemProperty("ipojo.log.level").value("warning")
+ );
+ }
+
+ @Test
+ public void testMessages() throws InterruptedException {
+ List<String> messages = getMessages(log.getLog());
+ Assert.assertTrue(messages.contains("Ready"));
+ // Not logged.
+ Assert.assertFalse(messages.contains("[INFO] org.apache.felix.ipojo.runtime.core.components.MyComponent : Instance org.apache.felix.ipojo.runtime.core.components.MyComponent-0 from factory org.apache.felix.ipojo.runtime.core.components.MyComponent created"));
+ Assert.assertFalse(messages.contains("[INFO] org.apache.felix.ipojo.runtime.core.components.MyComponent : New factory created : org.apache.felix.ipojo.runtime.core.components.MyComponent"));
+ }
+
+ private List<String> getMessages(Enumeration<LogEntry> log2) {
+ List<String> list = new ArrayList<String>();
+ while (log2.hasMoreElements()) {
+ LogEntry entry = (LogEntry) log2.nextElement();
+ list.add(entry.getMessage());
+ }
+ return list;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestBNDManifestLoggerInfo.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestBNDManifestLoggerInfo.java
new file mode 100644
index 0000000..5c5b054
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestBNDManifestLoggerInfo.java
@@ -0,0 +1,86 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.runtime.core.components.MyComponent;
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
+public class TestBNDManifestLoggerInfo extends Common {
+
+ private LogReaderService log;
+
+ @Before
+ public void init() {
+ log = (LogReaderService) osgiHelper.getServiceObject(LogReaderService.class.getName(), null);
+ if (log == null) {
+ throw new RuntimeException("No Log Service !");
+ }
+
+ LogService logs = (LogService) osgiHelper.getServiceObject(LogService.class.getName(), null);
+ logs.log(LogService.LOG_WARNING, "Ready");
+ }
+
+ @Configuration
+ public Option[] config() throws IOException {
+
+ Option[] options = super.config();
+
+ return OptionUtils.combine(options,
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version(asInProject()),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyService.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceInterface")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.services")
+ .build(withBnd())
+ ),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyComponent.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "MyComponent")
+ .set("IPOJO-log-level", "info")
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources/component.xml")))
+ )
+ );
+ }
+
+ @Test
+ public void testMessages() throws InterruptedException {
+ List<String> messages = getMessages(log.getLog());
+ Assert.assertTrue(messages.contains("Ready"));
+ Assert.assertTrue(messages.contains("[INFO] org.apache.felix.ipojo.runtime.core.components.MyComponent : Instance org.apache.felix.ipojo.runtime.core.components.MyComponent-0 from factory org.apache.felix.ipojo.runtime.core.components.MyComponent created"));
+ Assert.assertTrue(messages.contains("[INFO] org.apache.felix.ipojo.runtime.core.components.MyComponent : New factory created : org.apache.felix.ipojo.runtime.core.components.MyComponent"));
+ }
+
+ private List<String> getMessages(Enumeration<LogEntry> log2) {
+ List<String> list = new ArrayList<String>();
+ while (log2.hasMoreElements()) {
+ LogEntry entry = (LogEntry) log2.nextElement();
+ list.add(entry.getMessage());
+ }
+ return list;
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestErrorHandler.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestErrorHandler.java
new file mode 100644
index 0000000..30a14be
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestErrorHandler.java
@@ -0,0 +1,120 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ErrorHandler;
+import org.apache.felix.ipojo.runtime.core.components.MyComponent;
+import org.apache.felix.ipojo.runtime.core.components.MyErroneousComponent;
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
+public class TestErrorHandler extends Common {
+
+ @Configuration
+ public Option[] config() throws IOException {
+
+ Option[] options = super.config();
+
+ return OptionUtils.combine(options,
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version(asInProject()),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyService.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceInterface")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.services")
+ .build(withBnd())
+ ),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyComponent.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "MyComponent")
+ .set("Ipojo-log-level", "info")
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources/component.xml")))
+ ),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyErroneousComponent.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "MyErroneousComponent")
+ .set("Ipojo-log-level", "debug")
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources/erroneous-component.xml")))
+ )
+ );
+ }
+
+ @Test
+ public void testErrorHandlerEmpty() throws InterruptedException, InvalidSyntaxException {
+ MyErrorHandler handler = new MyErrorHandler();
+ bc.registerService(ErrorHandler.class.getName(), handler, null);
+
+ System.out.println(handler.m_errors);
+
+ Assert.assertTrue(handler.m_errors.isEmpty());
+ }
+
+ @Test
+ public void testErrorHandler() throws InterruptedException, InvalidSyntaxException {
+ MyErrorHandler handler = new MyErrorHandler();
+ bc.registerService(ErrorHandler.class.getName(), handler, null);
+
+ try {
+ ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.components.MyErroneousComponent");
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+
+
+ System.out.println(handler.m_errors);
+
+ Assert.assertFalse(handler.m_errors.isEmpty());
+ Assert.assertTrue(handler.m_errors.contains("org.apache.felix.ipojo.runtime.core.components.MyErroneousComponent-0:[org.apache.felix.ipojo.runtime.core.components.MyErroneousComponent-0] createInstance -> Cannot invoke the constructor method - the constructor throws an exception : bad:bad"));
+ }
+
+
+ private class MyErrorHandler implements ErrorHandler {
+
+ private List<String> m_errors = new ArrayList<String>();
+
+ public void onError(ComponentInstance instance, String message,
+ Throwable error) {
+ System.out.println("on Error ! " + instance + " - " + message);
+ if (instance == null) {
+ if (error == null) {
+ m_errors.add("no-instance:" + message);
+ } else {
+ m_errors.add("no-instance:" + message + ":" + error.getMessage());
+ }
+ } else {
+ if (error == null) {
+ m_errors.add(instance.getInstanceName() + ":" + message);
+ } else {
+ m_errors.add(instance.getInstanceName() + ":" + message + ":" + error.getMessage());
+ }
+ }
+ }
+
+ public void onWarning(ComponentInstance instance, String message,
+ Throwable error) {
+ System.out.println("on warning ! " + instance + " - " + message);
+ }
+
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManifestLoggerInfo.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManifestLoggerInfo.java
new file mode 100644
index 0000000..95f763f
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManifestLoggerInfo.java
@@ -0,0 +1,109 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.core.components.MyComponent;
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
+public class TestManifestLoggerInfo extends Common {
+
+ private LogReaderService log;
+
+ @Before
+ public void init() {
+ log = (LogReaderService) osgiHelper.getServiceObject(LogReaderService.class.getName(), null);
+ if (log == null) {
+ throw new RuntimeException("No Log Service !");
+ }
+
+ LogService logs = (LogService) osgiHelper.getServiceObject(LogService.class.getName(), null);
+ logs.log(LogService.LOG_WARNING, "Ready");
+ }
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ return OptionUtils.combine(options,
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version(asInProject()),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyService.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceInterface")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.services")
+ .build(withBnd())
+ ),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyComponent.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "MyComponent")
+ .set("Ipojo-log-level", "info")
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources/component.xml")))
+ )
+ );
+ }
+
+ @Test
+ public void testMessages() throws InterruptedException, InvalidSyntaxException {
+ Bundle bundle = osgiHelper.getBundle("MyComponent");
+ Assert.assertNotNull(bundle);
+ Assert.assertEquals(Bundle.ACTIVE, bundle.getState());
+
+ ServiceReference r = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(),
+ "org.apache.felix.ipojo.runtime.core.components.MyComponent-0");
+ Assert.assertNotNull(r);
+ System.out.println(((Architecture) osgiHelper.getServiceObject(r)).getInstanceDescription().getDescription());
+
+ ServiceReference[] refs = bc.getAllServiceReferences(null, null);
+ for (ServiceReference ref : refs) {
+ System.out.println(ref.getBundle().getBundleId() + " -> " + Arrays.asList((String[]) ref.getProperty(Constants.OBJECTCLASS)));
+ }
+
+
+ Assert.assertNotNull(osgiHelper.getServiceObject(MyService.class.getName(), null));
+
+ osgiHelper.waitForService(MyService.class.getName(), null, 5000);
+ List<String> messages = getMessages(log.getLog());
+ System.out.println(messages);
+ Assert.assertTrue(messages.contains("Ready"));
+ Assert.assertTrue(messages.contains("[INFO] org.apache.felix.ipojo.runtime.core.components.MyComponent : Instance org.apache.felix.ipojo.runtime.core.components.MyComponent-0 from factory org.apache.felix.ipojo.runtime.core.components.MyComponent created"));
+ Assert.assertTrue(messages.contains("[INFO] org.apache.felix.ipojo.runtime.core.components.MyComponent : New factory created : org.apache.felix.ipojo.runtime.core.components.MyComponent"));
+ }
+
+ private List<String> getMessages(Enumeration<LogEntry> log2) {
+ List<String> list = new ArrayList<String>();
+ while (log2.hasMoreElements()) {
+ LogEntry entry = (LogEntry) log2.nextElement();
+ list.add(entry.getMessage());
+ }
+ return list;
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSystemLoggerInfo.java b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSystemLoggerInfo.java
new file mode 100644
index 0000000..c49c7e1
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-logger-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestSystemLoggerInfo.java
@@ -0,0 +1,83 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.runtime.core.components.MyComponent;
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+
+public class TestSystemLoggerInfo extends Common {
+
+ private LogReaderService log;
+
+ @Before
+ public void init() {
+ log = (LogReaderService) osgiHelper.getServiceObject(LogReaderService.class.getName(), null);
+ if (log == null) {
+ throw new RuntimeException("No Log Service !");
+ }
+
+ LogService logs = (LogService) osgiHelper.getServiceObject(LogService.class.getName(), null);
+ logs.log(LogService.LOG_WARNING, "Ready");
+ }
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ return OptionUtils.combine(options,
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version(asInProject()),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyService.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceInterface")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.runtime.core.services")
+ .build(TinyBundles.withBnd())
+ ),
+ streamBundle(
+ TinyBundles.bundle()
+ .add(MyComponent.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "MyComponent")
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources/component.xml")))
+ ),
+ systemProperty("ipojo.log.level").value("info")
+ );
+ }
+
+ @Test
+ public void testMessages() throws InterruptedException {
+ List<String> messages = getMessages(log.getLog());
+ Assert.assertTrue(messages.contains("Ready"));
+ Assert.assertTrue(messages.contains("[INFO] org.apache.felix.ipojo.runtime.core.components.MyComponent : Instance org.apache.felix.ipojo.runtime.core.components.MyComponent-0 from factory org.apache.felix.ipojo.runtime.core.components.MyComponent created"));
+ Assert.assertTrue(messages.contains("[INFO] org.apache.felix.ipojo.runtime.core.components.MyComponent : New factory created : org.apache.felix.ipojo.runtime.core.components.MyComponent"));
+ }
+
+ private List<String> getMessages(Enumeration<LogEntry> log2) {
+ List<String> list = new ArrayList<String>();
+ while (log2.hasMoreElements()) {
+ LogEntry entry = (LogEntry) log2.nextElement();
+ list.add(entry.getMessage());
+ }
+ return list;
+ }
+
+
+}