Migrate some core tests (external handlers) to pax exam 3
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1446477 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/pom.xml b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/pom.xml
new file mode 100644
index 0000000..6590909
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/pom.xml
@@ -0,0 +1,153 @@
+<?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-external-handlers-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>${project.artifactId}</name>
+
+ <properties>
+ <exam.version>3.0.0</exam.version>
+ <url.version>1.5.1</url.version>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-native</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-aether</artifactId>
+ <version>${url.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>4.2.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>0.9.6</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>0.9.6</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.ops4j.pax.tinybundles</groupId>
+ <artifactId>tinybundles</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ow2.chameleon.testing</groupId>
+ <artifactId>osgi-helpers</artifactId>
+ <version>0.6.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ow2.chameleon.testing</groupId>
+ <artifactId>tinybundles-ipojo</artifactId>
+ <version>0.3.0</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>1.2</version>
+ <executions>
+ <execution>
+ <id>generate-config</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/components/CheckServiceHandler.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/components/CheckServiceHandler.java
new file mode 100644
index 0000000..528d804
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/components/CheckServiceHandler.java
@@ -0,0 +1,105 @@
+/*
+ * 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.felix.ipojo.runtime.externalhandlers.components;
+
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService;
+import org.apache.felix.ipojo.runtime.externalhandlers.services.CheckServiceHandlerDescription;
+import org.osgi.framework.ServiceRegistration;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+public class CheckServiceHandler extends PrimitiveHandler implements CheckService {
+
+ ServiceRegistration sr;
+ boolean isValid;
+ int changes = 0;
+ static final String NAMESPACE = "org.apache.felix.ipojo.test.handler.checkservice";
+
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+
+ public void configure(Element metadata, Dictionary configuration) {
+ Element[] meta = metadata.getElements("check", NAMESPACE);
+ if(meta == null) { return; }
+ // Get handler props
+ props.put("instance.name", configuration.get("instance.name"));
+ if(configuration.get("csh.simple") != null) { props.put("Simple", configuration.get("csh.simple")); }
+ if(configuration.get("csh.map") != null) {
+ Dictionary m = (Dictionary) configuration.get("csh.map");
+ if (m.size() > 0) {
+ props.put("Map1", m.get("a"));
+ props.put("Map2", m.get("b"));
+ props.put("Map3", m.get("c"));
+ }
+ }
+ props.put("changes", new Integer(changes));
+
+ }
+
+ public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) {
+ cd.addProperty(new PropertyDescription("csh.simple", "java.lang.String", null));
+ cd.addProperty(new PropertyDescription("csh.map", "java.util.Dictionary", null));
+ }
+
+ public void start() {
+ if(sr == null) {
+ sr = getInstanceManager().getContext().registerService(CheckService.class.getName(), this, props);
+ }
+ isValid = true;
+ }
+
+ public void stop() {
+ isValid = false;
+ synchronized(this) {
+ if(sr != null) { sr.unregister(); }
+ }
+ }
+
+ public boolean check() {
+ if(isValid) { isValid = false;}
+ else { isValid = true; }
+ return isValid;
+ }
+
+ public Dictionary<String, Object> getProps() {
+ return props;
+ }
+
+ public void stateChanged(int state) {
+ if (sr != null) {
+ changes++;
+ props.put("changes", new Integer(changes));
+ sr.setProperties(props);
+ }
+ }
+
+ public String getName() {
+ return NAMESPACE;
+ }
+
+ public HandlerDescription getDescription() {
+ return new CheckServiceHandlerDescription(this);
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/components/FooProviderType1.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/components/FooProviderType1.java
new file mode 100644
index 0000000..f64b27e
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/components/FooProviderType1.java
@@ -0,0 +1,117 @@
+/*
+ * 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.felix.ipojo.runtime.externalhandlers.components;
+
+import org.apache.felix.ipojo.runtime.externalhandlers.services.FooService;
+import org.osgi.framework.BundleContext;
+
+import java.util.Properties;
+
+public class FooProviderType1 implements FooService {
+
+ private int m_bar;
+ private String m_foo;
+
+ private BundleContext m_context;
+
+ private static FooProviderType1 singleton;
+ private static int count = 0;
+
+ private static FooProviderType1 singleton(BundleContext bc) {
+ if (singleton == null) {
+ count++;
+ singleton = new FooProviderType1(bc);
+ }
+ return singleton;
+ }
+
+ public static FooProviderType1 several(BundleContext bc) {
+ count++;
+ return new FooProviderType1(bc);
+ }
+
+ public FooProviderType1(BundleContext bc) {
+ if (bc ==null) {
+ throw new RuntimeException("Injected bundle context null");
+ }
+ m_context = bc;
+ }
+
+ public boolean foo() {
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("bar", new Integer(m_bar));
+ if(m_foo != null) {
+ p.put("foo", m_foo);
+ }
+ p.put("context", m_context);
+
+ p.put("count", new Integer(count));
+ return p;
+ }
+
+ public void testException() throws Exception {
+ String a = "foobarbaz";
+ throw new Exception("foo"+a);
+ }
+
+ public void testTry() {
+ String a = "foo";
+ a.charAt(0);
+ }
+
+ public void testTry2(String s) {
+ String a = "foo";
+ a.charAt(0);
+ }
+
+ private void nexttry(String s) {
+ try {
+ s += "foo";
+ } catch(RuntimeException e) {
+
+ }
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+ /**
+ * Custom constructor.
+ * @param bar
+ * @param foo
+ * @param bc
+ */
+ public FooProviderType1(int bar, String foo, BundleContext bc) {
+ m_bar = bar;
+ m_foo = foo;
+ m_context = bc;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/CheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/CheckService.java
new file mode 100644
index 0000000..1415982
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/CheckService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.felix.ipojo.runtime.externalhandlers.services;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+public interface CheckService {
+
+ public static final String foo = "foo";
+
+ public boolean check();
+
+ public Dictionary<String, Object> getProps();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/CheckServiceHandlerDescription.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/CheckServiceHandlerDescription.java
new file mode 100644
index 0000000..c95b0ff
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/CheckServiceHandlerDescription.java
@@ -0,0 +1,38 @@
+/*
+ * 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.felix.ipojo.runtime.externalhandlers.services;
+
+import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
+public class CheckServiceHandlerDescription extends HandlerDescription {
+
+ public CheckServiceHandlerDescription(Handler h) {
+ super(h);
+ }
+
+ public Element getHandlerInfo() {
+ Element elem = super.getHandlerInfo();
+ elem.addAttribute(new Attribute("isValid", isValid()+""));
+ return elem;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/FooService.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/FooService.java
new file mode 100644
index 0000000..108df33
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/java/org/apache/felix/ipojo/runtime/externalhandlers/services/FooService.java
@@ -0,0 +1,39 @@
+/*
+ * 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.felix.ipojo.runtime.externalhandlers.services;
+
+import java.util.Properties;
+
+public interface FooService {
+
+ boolean foo();
+
+ Properties fooProps();
+
+ Boolean getObject();
+
+ boolean getBoolean();
+
+ int getInt();
+
+ long getLong();
+
+ double getDouble();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/resources/metadata.xml b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/resources/metadata.xml
new file mode 100644
index 0000000..3fad3a8
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/main/resources/metadata.xml
@@ -0,0 +1,39 @@
+<ipojo
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/DEV/core.xsd"
+ xmlns="org.apache.felix.ipojo"
+ xmlns:cs="org.apache.felix.ipojo.test.handler.checkservice">
+ <handler
+ classname="org.apache.felix.ipojo.runtime.externalhandlers.components.CheckServiceHandler"
+ name="check"
+ namespace="org.apache.felix.ipojo.test.handler.checkservice"
+ architecture="false">
+ <controller field="isValid" />
+ </handler>
+ <component
+ classname="org.apache.felix.ipojo.runtime.externalhandlers.components.FooProviderType1"
+ name="HANDLER-HandlerTester" architecture="true">
+ <cs:check />
+ </component>
+ <instance name="HandlerTest-2" component="HANDLER-HandlerTester">
+ <property name="csh.simple" value="Simple" />
+ <property name="csh.map">
+ <property name="a" value="a" />
+ <property name="b" value="b" />
+ <property name="c" value="c" />
+ </property>
+ </instance>
+ <instance name="HandlerTest-2-empty" component="HANDLER-HandlerTester">
+ <property name="csh.simple" value="Simple" />
+ <property name="csh.map">
+ <!-- Empty dictionary -->
+ </property>
+ </instance>
+
+ <!-- The handler will be added using the auto handler property -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.externalhandlers.components.FooProviderType1"
+ name="HANDLER-HandlerTesterWO" architecture="true">
+ </component>
+
+</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/AutoHandlerTest.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/AutoHandlerTest.java
new file mode 100644
index 0000000..79a224c
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/AutoHandlerTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.felix.ipojo.runtime.externalhandlers.test;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.runtime.externalhandlers.services.CheckServiceHandlerDescription;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+public class AutoHandlerTest extends Common {
+
+ private static final String ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE = "org.apache.felix.ipojo.handler.auto.primitive";
+
+ ComponentInstance instance;
+
+ ComponentFactory factory;
+
+ @Before
+ public void setUp() {
+ factory = (ComponentFactory) ipojoHelper.getFactory("HANDLER-HandlerTesterWO");
+ System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, "");
+ }
+
+ @After
+ public void tearDown() {
+ if (instance != null) {
+ instance.dispose();
+ }
+ instance = null;
+
+ System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, "");
+
+ }
+
+ @Test
+ public void testRequiredHandlerList() {
+ System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, "");
+
+ factory.stop();
+ factory.restart();
+ factory.start();
+
+ List list = factory.getRequiredHandlers();
+ assertFalse(list.contains("org.apache.felix.ipojo.test.handler.checkservice:check"));
+
+ String v = "org.apache.felix.ipojo.test.handler.checkservice:check";
+ System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, v);
+
+ factory.stop();
+ factory.restart();
+ factory.start();
+
+ list = factory.getRequiredHandlers();
+ assertTrue(list.contains("org.apache.felix.ipojo.test.handler.checkservice:check"));
+
+ System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, "");
+
+ }
+
+
+ @Test
+ public void testInstanceCreation() throws Exception {
+ String v = "org.apache.felix.ipojo.test.handler.checkservice:check";
+ System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, v);
+
+ factory.stop();
+ factory.restart();
+ factory.start();
+
+ instance = factory.createComponentInstance(new Properties());
+ assertEquals(ComponentInstance.VALID, instance.getState());
+
+ HandlerDescription hd = instance.getInstanceDescription().getHandlerDescription(v);
+ assertNotNull(hd);
+ assertTrue(hd instanceof CheckServiceHandlerDescription);
+
+ System.setProperty(ORG_APACHE_FELIX_IPOJO_HANDLER_AUTO_PRIMITIVE, "");
+
+ factory.stop();
+ factory.restart();
+ factory.start();
+ }
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/Common.java
new file mode 100644
index 0000000..47dc22d
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/Common.java
@@ -0,0 +1,146 @@
+package org.apache.felix.ipojo.runtime.externalhandlers.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.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 static org.ops4j.pax.exam.CoreOptions.*;
+
+/**
+ * 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 MalformedURLException {
+ Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ root.setLevel(Level.INFO);
+
+ return options(
+ ipojoBundles(),
+ junitBundles(),
+ testedBundle(),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ );
+ }
+
+ @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 CompositeOption ipojoBundles() {
+ return new DefaultCompositeOption(
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+ mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").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.IMPORT_PACKAGE, "*")
+ .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");
+ }
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/HandlerTest.java b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/HandlerTest.java
new file mode 100644
index 0000000..ea57346
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/java/org/apache/felix/ipojo/runtime/externalhandlers/test/HandlerTest.java
@@ -0,0 +1,205 @@
+/*
+ * 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.felix.ipojo.runtime.externalhandlers.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.HandlerManagerFactory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class HandlerTest extends Common {
+
+ ComponentInstance instance;
+
+ @Before
+ public void setUp() {
+ Properties props = new Properties();
+ props.put("instance.name","HandlerTest-1");
+ props.put("csh.simple", "simple");
+ Properties p = new Properties();
+ p.put("a", "a");
+ p.put("b", "b");
+ p.put("c", "c");
+ props.put("csh.map", p);
+ instance = ipojoHelper.createComponentInstance("HANDLER-HandlerTester", props);
+ }
+
+ @After
+ public void tearDown() {
+ instance.dispose();
+ instance = null;
+ }
+
+ @Test
+ public void testConfiguration1() {
+ // Check the availability of CheckService
+ String name = "HandlerTest-1";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+ refs =osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
+ if(refs != null) { sr = refs[0]; }
+
+ assertNotNull("Check the check service availability", sr);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(sr);
+ Dictionary<String, Object> p = cs.getProps();
+ assertEquals("Assert 'simple' equality", p.get("Simple"), "simple");
+ assertEquals("Assert 'a' equality", p.get("Map1"), "a");
+ assertEquals("Assert 'b' equality", p.get("Map2"), "b");
+ assertEquals("Assert 'c' equality", p.get("Map3"), "c");
+ }
+
+ @Test
+ public void testConfiguration2() {
+ // Check the availability of CheckService
+ String name = "HandlerTest-2";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+
+ refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
+
+ if(refs != null) { sr = refs[0]; }
+ assertNotNull("Check the check service availability", sr);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(sr);
+ Dictionary<String, Object> p = cs.getProps();
+ assertEquals("Assert 'simple' equality", p.get("Simple"), "Simple");
+ assertEquals("Assert 'a' equality", p.get("Map1"), "a");
+ assertEquals("Assert 'b' equality", p.get("Map2"), "b");
+ assertEquals("Assert 'c' equality", p.get("Map3"), "c");
+ }
+
+ @Test
+ public void testConfiguration3() {
+ // Check the availability of CheckService
+ String name = "HandlerTest-2-empty";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+ refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
+ if(refs != null) { sr = refs[0]; }
+ assertNotNull("Check the check service availability", sr);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(sr);
+ Dictionary<String, Object> p = cs.getProps();
+ assertEquals("Assert 'simple' equality", p.get("Simple"), "Simple");
+ assertEquals("Size of p", 3, p.size()); // instance name, simple and changes.
+
+ cs = null;
+ }
+
+ @Test
+ public void testLifecycle() {
+ // Check the availability of CheckService
+ String name = "HandlerTest-1";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+ refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
+ if(refs != null) { sr = refs[0]; }
+ assertNotNull("Check the check service availability", sr);
+
+ ServiceReference sr_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "HandlerTest-1");
+ Architecture arch = (Architecture) osgiHelper.getServiceObject(sr_arch);
+
+ assertEquals("Check instance validity - 0", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(sr);
+ Dictionary<String, Object> p = cs.getProps();
+ Integer changes = (Integer) p.get("changes");
+ assertNotNull("Check changes no null", changes);
+ assertEquals("Changes changes 1 ("+changes+")", changes.intValue(), 1);
+ assertEquals("Check instance validity - 1", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+ cs.check();
+ p = cs.getProps();
+ changes = (Integer) p.get("changes");
+ assertEquals("Changes changes 2 ("+changes+")", changes.intValue(), 2);
+ assertEquals("Check instance validity - 2", arch.getInstanceDescription().getState(), ComponentInstance.INVALID);
+ cs.check();
+ p = cs.getProps();
+ changes = (Integer) p.get("changes");
+ assertEquals("Changes changes 3 ("+changes+")", changes.intValue(), 3);
+ assertEquals("Check instance validity - 3", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+ cs.check();
+ p = cs.getProps();
+ changes = (Integer) p.get("changes");
+ assertEquals("Changes changes 4 ("+changes+")", changes.intValue(), 4);
+ assertEquals("Check instance validity - 4", arch.getInstanceDescription().getState(), ComponentInstance.INVALID);
+ }
+
+ @Test
+ public void testAvailability() {
+ String name = "HandlerTest-1";
+ ServiceReference sr = null;
+ ServiceReference[] refs = null;
+ String filter = "("+"instance.name"+"="+name+")";
+ refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
+
+ if(refs != null) { sr = refs[0]; }
+ assertNotNull("Check the check service availability", sr);
+
+ ServiceReference sr_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "HandlerTest-1");
+ Architecture arch = (Architecture) osgiHelper.getServiceObject(sr_arch);
+ assertEquals("Check validity", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+
+ // Kill the handler factory
+ HandlerManagerFactory f = (HandlerManagerFactory)ipojoHelper.getHandlerFactory( "check");
+ f.stop();
+
+ sr = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "HandlerTest-1");
+ assertNull("Check the check service unavailability", sr);
+
+ sr_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "HandlerTest-1");
+ assertNull("Check the architecture unavailability", sr_arch);
+
+ // The instance is disposed, restart the handler
+ f.start();
+
+ Properties props = new Properties();
+ props.put("instance.name","HandlerTest-1");
+ props.put("csh.simple", "simple");
+ Properties p = new Properties();
+ p.put("a", "a");
+ p.put("b", "b");
+ p.put("c", "c");
+ props.put("csh.map", p);
+ instance = ipojoHelper.createComponentInstance("HANDLER-HandlerTester", props);
+
+ sr = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "HandlerTest-1");
+ assertNotNull("Check the check service availability - 2", sr);
+
+ sr_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "HandlerTest-1");
+ arch = (Architecture) osgiHelper.getServiceObject(sr_arch);
+ assertEquals("Check validity - 2", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/resources/exam.properties b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/resources/exam.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-external-handlers-test/src/test/resources/exam.properties