FELIX-3903
Migrate the core factory test to pax exam 3
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1447488 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/pom.xml b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/pom.xml
new file mode 100644
index 0000000..c11abcf
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/pom.xml
@@ -0,0 +1,19 @@
+<?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>
+
+ <artifactId>ipojo-core-factory-test</artifactId>
+
+ <name>${project.artifactId}</name>
+
+</project>
\ No newline at end of file
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java
new file mode 100644
index 0000000..7d18712
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java
@@ -0,0 +1,51 @@
+/*
+ * 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.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+public abstract class CheckProviderParentClass {
+
+ int simpleU = 0;
+ int objectU = 0;
+ int refU = 0;
+ int bothU = 0;
+
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if(sr != null && o != null && o instanceof FooService) { bothU++; }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if(sr != null) { refU++; }
+ }
+
+ public void objectUnbind(FooService o) {
+ if(o != null && o instanceof FooService) { objectU++; }
+ else {
+ System.err.println("Unbind null : " + o);
+ }
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckServiceProvider.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckServiceProvider.java
new file mode 100644
index 0000000..eee88a2
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckServiceProvider.java
@@ -0,0 +1,83 @@
+/*
+ * 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.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+public class CheckServiceProvider extends CheckProviderParentClass implements CheckService {
+
+ FooService fs;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int bothB = 0;
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("bothB", new Integer(bothB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("bothU", new Integer(bothU));
+ if (fs != null) {
+ props.put("result", new Boolean(fs.foo()));
+ props.put("boolean", new Boolean(fs.getBoolean()));
+ props.put("int", new Integer(fs.getInt()));
+ props.put("long", new Long(fs.getLong()));
+ props.put("double", new Double(fs.getDouble()));
+ if(fs.getObject() != null) { props.put("object", fs.getObject()); }
+ }
+ props.put("static", CheckService.foo);
+ props.put("class", CheckService.class.getName());
+ return props;
+ }
+
+ private void voidBind() {
+ simpleB++;
+ }
+
+ protected void objectBind(FooService o) {
+ if (o == null) {
+ System.err.println("Bind receive null !!! ");
+ return;
+ }
+ if(o != null && o instanceof FooService) { objectB++; }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if(sr != null) { refB++; }
+ }
+
+ public void bothBind(FooService o, ServiceReference sr) {
+ if(sr != null && o != null && o instanceof FooService) { bothB++; }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooBarProviderType1.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooBarProviderType1.java
new file mode 100644
index 0000000..03016d3
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooBarProviderType1.java
@@ -0,0 +1,54 @@
+/*
+ * 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.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+
+import java.util.Properties;
+
+public class FooBarProviderType1 implements FooService, BarService {
+
+ public boolean foo() {
+ return true;
+ }
+
+ public Properties fooProps() {
+ return new Properties();
+ }
+
+ public boolean bar() {
+ return true;
+ }
+
+ public Properties getProps() {
+ return new Properties();
+ }
+
+ 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); }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderType1.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderType1.java
new file mode 100644
index 0000000..4d6add7
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/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.core.components;
+
+import org.apache.felix.ipojo.runtime.core.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-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn.java
new file mode 100644
index 0000000..9428190
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn.java
@@ -0,0 +1,64 @@
+/*
+ * 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.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+
+import java.util.Properties;
+
+
+public class FooProviderTypeDyn implements FooService {
+
+ private int intProp;
+ private String strProp;
+ private String[] strAProp;
+ private int[] intAProp;
+ private boolean boolProp;
+
+ public boolean foo() {
+ intProp = 3;
+ boolProp = true;
+ if(strProp.equals("foo")) { strProp = "bar"; }
+ else { strProp = "foo"; }
+ strAProp = new String[] {"foo", "bar", "baz"};
+ intAProp = new int[] {3, 2, 1};
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("intProp", new Integer(intProp));
+ p.put("boolProp", new Boolean(boolProp));
+ p.put("strProp", strProp);
+ p.put("strAProp", strAProp);
+ p.put("intAProp", intAProp);
+ return p;
+ }
+
+ 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); }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn2.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn2.java
new file mode 100644
index 0000000..efec5f0
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/FooProviderTypeDyn2.java
@@ -0,0 +1,58 @@
+/*
+ * 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.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+
+import java.util.Properties;
+
+public class FooProviderTypeDyn2 implements FooService {
+
+ private int intProp = 2;
+ private boolean boolProp = true;
+ private String strProp = "foo";
+ private String[] strAProp = new String[] {"foo", "bar"};
+ private int[] intAProp = new int[] {1, 2, 3};
+
+ public boolean foo() {
+ intAProp = null;
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("intProp", new Integer(intProp));
+ p.put("boolProp", new Boolean(boolProp));
+ p.put("strProp", strProp);
+ p.put("strAProp", strAProp);
+ p.put("intAProp", intAProp);
+ return p;
+ }
+
+ 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); }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ReconfigurableSimpleType.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ReconfigurableSimpleType.java
new file mode 100644
index 0000000..b459a4e
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ReconfigurableSimpleType.java
@@ -0,0 +1,44 @@
+package org.apache.felix.ipojo.runtime.core.components;
+
+public class ReconfigurableSimpleType {
+
+
+ private String prop; // Property.
+
+ private String x; // Property.
+
+ boolean controller;
+
+ public void start () {
+ if (prop == null || prop.equals("KO")) {
+ throw new IllegalStateException("Bad Configuration : " + prop);
+ }
+
+ if (x == null) {
+ throw new IllegalStateException("x is null");
+ }
+
+ System.out.println("OK !!!!");
+ }
+
+ public void setX(String v) {
+ x = v;
+ }
+
+ public void setProp(String p) {
+ prop = p;
+ if (prop == null || prop.equals("KO")) {
+ controller = false;
+ } else {
+ controller = true;
+ System.out.println("OK !!!!");
+ }
+ }
+
+ public void setController(boolean p) {
+ if (p) {
+ System.out.println("OK !!!!");
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/SimpleType.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/SimpleType.java
new file mode 100644
index 0000000..f41d711
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/SimpleType.java
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.runtime.core.components;
+
+public class SimpleType {
+
+ private boolean m_controller;
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java
new file mode 100644
index 0000000..f704138
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java
@@ -0,0 +1,29 @@
+/*
+ * 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.core.services;
+
+import java.util.Properties;
+
+public interface BarService {
+
+ public boolean bar();
+
+ public Properties getProps();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
new file mode 100644
index 0000000..eca0faa
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
@@ -0,0 +1,31 @@
+/*
+ * 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.core.services;
+
+import java.util.Properties;
+
+public interface CheckService {
+
+ public static final String foo = "foo";
+
+ public boolean check();
+
+ public Properties getProps();
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java
new file mode 100644
index 0000000..37c1a65
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/java/org/apache/felix/ipojo/runtime/core/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.core.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-factory-test/src/main/resources/metadata.xml b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/resources/metadata.xml
new file mode 100644
index 0000000..26ed5bf
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/main/resources/metadata.xml
@@ -0,0 +1,155 @@
+<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <!-- Simple provider -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"
+ name="Factories-FooProviderType-1" architecture="true">
+ <provides />
+ </component>
+
+ <!-- Provider providing 2 services -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooBarProviderType1"
+ name="Factories-FooBarProviderType-1" architecture="true">
+ <provides />
+ </component>
+
+ <!-- Provider with dynamic property -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderTypeDyn"
+ name="Factories-FooProviderType-Dyn" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="2" mandatory="true"/>
+ <property name="boolean" field="boolProp" value="false" mandatory="true"/>
+ <property name="string" field="strProp" value="foo" mandatory="true"/>
+ <property name="strAProp" field="strAProp"
+ value="{foo, bar}" mandatory="true"/>
+ <property name="intAProp" field="intAProp" value="{ 1,2,3}" mandatory="true"/>
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderTypeDyn"
+ name="Factories-FooProviderType-Dynopt" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="2"/>
+ <property name="boolean" field="boolProp" value="false"/>
+ <property name="string" field="strProp" value="foo"/>
+ <property name="strAProp" field="strAProp"
+ value="{foo, bar}"/>
+ <property name="intAProp" field="intAProp" value="{ 1,2,3}"/>
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"
+ name="Factories-FooProviderType-2" architecture="true">
+ <provides>
+ <property name="int" type="int" value="2" mandatory="true" />
+ <property name="long" type="long" value="40" mandatory="true"/>
+ <property name="string" type="java.lang.String" value="foo" mandatory="true"/>
+ <property name="strAProp" type="java.lang.String[]"
+ value="{foo, bar}" mandatory="true" />
+ <property name="intAProp" type="int[]" value="{1,2,3}" mandatory="true"/>
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"
+ name="Factories-FooProviderType-2opt" architecture="true">
+ <provides>
+ <property name="int" type="int" value="2"/>
+ <property name="long" type="long" value="40"/>
+ <property name="string" type="java.lang.String" value="foo"/>
+ <property name="strAProp" type="java.lang.String[]"
+ value="{foo, bar}" />
+ <property name="intAProp" type="int[]" value="{1,2,3}"/>
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderTypeDyn2"
+ name="Factories-FooProviderType-Dyn2" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="4" mandatory="true"/>
+ <property name="boolean" field="boolProp" mandatory="true"/>
+ <property name="string" field="strProp" mandatory="true"/>
+ <property name="strAProp" field="strAProp" mandatory="true"/>
+ <property name="intAProp" field="intAProp"
+ value="{1, 2,3 }" mandatory="true"/>
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderTypeDyn2"
+ name="Factories-FooProviderType-Dyn2opt" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="4" />
+ <property name="boolean" field="boolProp"/>
+ <property name="string" field="strProp"/>
+ <property name="strAProp" field="strAProp"/>
+ <property name="intAProp" field="intAProp"
+ value="{1, 2,3 }"/>
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"
+ name="Factories-FooProviderType-3" architecture="true">
+ <provides>
+ <property name="foo" field="m_foo" mandatory="true"/>
+ <property name="bar" field="m_bar" mandatory="true"/>
+ <property name="baz" type="java.lang.String" mandatory="true"/>
+ </provides>
+ <properties propagation="true">
+ <property name="foo" field="m_foo" mandatory="true"/>
+ <property name="bar" field="m_bar" mandatory="true"/>
+ </properties>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"
+ name="Factories-FooProviderType-3opt" architecture="true">
+ <provides>
+ <property name="foo" field="m_foo"/>
+ <property name="bar" field="m_bar"/>
+ <property name="baz" type="java.lang.String"/>
+ </provides>
+ <properties propagation="true">
+ <property name="foo" field="m_foo"/>
+ <property name="bar" field="m_bar"/>
+ </properties>
+ </component>
+
+ <!-- type & instance used to check instance lifecycle against factory validation & invalidation -->
+ <component classname="org.apache.felix.ipojo.runtime.core.components.SimpleType" architecture="true">
+ <controller field="m_controller"/>
+ </component>
+ <instance component="org.apache.felix.ipojo.runtime.core.components.SimpleType" name="SimpleInstance"/>
+
+ <!-- check that instance state is recomputed after reconfiguration -->
+ <component classname="org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType" architecture="true">
+ <properties>
+ <property name="prop" field="prop"/>
+ <property name="x" method="setX" value="x"/>
+ </properties>
+ <callback transition="validate" method="start"/>
+ </component>
+ <component classname="org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType"
+ name="org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType2"
+ architecture="true" immediate="true">
+ <properties>
+ <property name="prop" method="setProp"/>
+ <property name="x" method="setX" value="x"/>
+ </properties>
+ <controller field="controller"/>
+ </component>
+ <component classname="org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType"
+ name="org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType3"
+ architecture="true" immediate="true">
+ <properties>
+ <property name="controller" method="setController" field="controller"/>
+ <property name="x" method="setX" value="x"/>
+ </properties>
+ <controller field="controller"/>
+ </component>
+</ipojo>
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
new file mode 100644
index 0000000..1f8fc8a
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
@@ -0,0 +1,157 @@
+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.apache.felix.ipojo.runtime.core.components.*;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+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.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(PerClass.class)
+public class Common {
+
+ @Inject
+ BundleContext bc;
+
+ OSGiHelper osgiHelper;
+ IPOJOHelper ipojoHelper;
+
+ @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);
+
+ // 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");
+
+ 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-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestComponentDesc.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestComponentDesc.java
new file mode 100644
index 0000000..eb9ecaa
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestComponentDesc.java
@@ -0,0 +1,345 @@
+/*
+ * 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.core;
+
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Arrays;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+/**
+ * Check component type description.
+ */
+public class TestComponentDesc extends Common {
+
+ ServiceReference sr_fooProvider1;
+ ServiceReference sr_fooProvider2;
+ ServiceReference sr_fooProviderDyn2;
+ ServiceReference sr_fooProvider3;
+ ServiceReference sr_foobarProvider;
+
+ Factory fooProvider1;
+ Factory fooProvider2;
+ Factory fooProviderDyn2;
+ Factory fooProvider3;
+ Factory foobarProvider;
+
+ @Before
+ public void setUp() {
+
+ sr_fooProvider1 = osgiHelper.getServiceReferenceByPID(Factory.class, "Factories-FooProviderType-1");
+ sr_fooProvider2 = osgiHelper.getServiceReferenceByPID(Factory.class, "Factories-FooProviderType-2");
+ sr_fooProviderDyn2 = osgiHelper.getServiceReferenceByPID(Factory.class, "Factories-FooProviderType-Dyn2");
+ sr_fooProvider3 = osgiHelper.getServiceReferenceByPID(Factory.class, "Factories-FooProviderType-3");
+ sr_foobarProvider = osgiHelper.getServiceReferenceByPID(Factory.class, "Factories-FooBarProviderType-1");
+
+ fooProvider1 = ipojoHelper.getFactory("Factories-FooProviderType-1");
+ fooProvider2 = ipojoHelper.getFactory("Factories-FooProviderType-2");
+ fooProviderDyn2 = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+ fooProvider3 = ipojoHelper.getFactory("Factories-FooProviderType-3");
+ foobarProvider = ipojoHelper.getFactory("Factories-FooBarProviderType-1");
+ }
+
+ /**
+ * Check simple providing.
+ */
+ @Test
+ public void testFooProvider1() {
+ // Test SR properties
+// String impl = (String) sr_fooProvider1.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
+
+ String[] specs = (String[]) sr_fooProvider1.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
+ assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider1.getProperty("component.properties");
+ assertEquals("Check component.properties length", pd.length, 0);
+
+ // Test factory
+ assertEquals("Check factory name", fooProvider1.getName(), "Factories-FooProviderType-1");
+ Element cd = fooProvider1.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 1);
+ assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertNull("Check props null", pd2);
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider1.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+ }
+
+ /**
+ * Check component properties.
+ */
+ @Test
+ public void testFooProvider2() {
+ // Test SR properties
+// String impl = (String) sr_fooProvider2.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
+
+ String[] specs = (String[]) sr_fooProvider2.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
+ assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider2.getProperty("component.properties");
+ assertEquals("Check component.properties length", pd.length, 5);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "int", pd[0].getName());
+ assertEquals("Check component.properties type [" + 0 + "]", "int", pd[0].getType());
+ assertEquals("Check component.properties value [" + 0 + "]", "2", pd[0].getValue());
+
+ assertEquals("Check component.properties name [" + 1 + "]", "long", pd[1].getName());
+ assertEquals("Check component.properties type [" + 1 + "]", "long", pd[1].getType());
+ assertEquals("Check component.properties value [" + 1 + "]", "40", pd[1].getValue());
+
+ assertEquals("Check component.properties name [" + 2 + "]", "string", pd[2].getName());
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
+ assertEquals("Check component.properties value [" + 2 + "]", "foo", pd[2].getValue());
+
+ assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd[3].getName());
+ assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd[3].getType());
+
+ assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd[4].getName());
+ assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd[4].getType());
+
+ // Test factory
+ assertEquals("Check factory name", fooProvider2.getName(), "Factories-FooProviderType-2");
+ Element cd = fooProvider2.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 1);
+ assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertEquals("Check props length", pd2.length, 5);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "int", pd2[0].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 0 + "]", "int", pd2[0].getAttribute("type"));
+ assertEquals("Check component.properties value [" + 0 + "]", "2", pd2[0].getAttribute("value"));
+
+ assertEquals("Check component.properties name [" + 1 + "]", "long", pd2[1].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 1 + "]", "long", pd2[1].getAttribute("type"));
+ assertEquals("Check component.properties value [" + 1 + "]", "40", pd2[1].getAttribute("value"));
+
+ assertEquals("Check component.properties name [" + 2 + "]", "string", pd2[2].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
+ assertEquals("Check component.properties value [" + 2 + "]", "foo", pd2[2].getAttribute("value"));
+
+ assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd2[3].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd2[3].getAttribute("type"));
+
+ assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd2[4].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd2[4].getAttribute("type"));
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider2.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+
+ // Check that we have the complete metadata
+ assertNotNull(fooProvider2.getComponentMetadata());
+ }
+
+ /**
+ * Check component properties (dynamic).
+ */
+ @Test
+ public void testFooProviderDyn2() {
+ // Test SR properties
+// String impl = (String) sr_fooProviderDyn2.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2");
+
+ String[] specs = (String[]) sr_fooProviderDyn2.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
+ assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_fooProviderDyn2.getProperty("component.properties");
+ assertEquals("Check component.properties length", pd.length, 5);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "int", pd[0].getName());
+ assertEquals("Check component.properties type [" + 0 + "]", "int", pd[0].getType());
+ assertEquals("Check component.properties value [" + 0 + "]", "4", pd[0].getValue());
+
+ assertEquals("Check component.properties name [" + 1 + "]", "boolean", pd[1].getName());
+ assertEquals("Check component.properties type [" + 1 + "]", "boolean", pd[1].getType());
+
+ assertEquals("Check component.properties name [" + 2 + "]", "string", pd[2].getName());
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
+
+ assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd[3].getName());
+ assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd[3].getType());
+
+ assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd[4].getName());
+ assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd[4].getType());
+
+ // Test factory
+ assertEquals("Check factory name", fooProviderDyn2.getName(), "Factories-FooProviderType-Dyn2");
+ Element cd = fooProviderDyn2.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 1);
+ assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertEquals("Check props length", pd2.length, 5);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "int", pd2[0].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 0 + "]", "int", pd2[0].getAttribute("type"));
+ assertEquals("Check component.properties value [" + 0 + "]", "4", pd2[0].getAttribute("value"));
+
+ assertEquals("Check component.properties name [" + 1 + "]", "boolean", pd2[1].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 1 + "]", "boolean", pd2[1].getAttribute("type"));
+
+ assertEquals("Check component.properties name [" + 2 + "]", "string", pd2[2].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
+
+ assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd2[3].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd2[3].getAttribute("type"));
+
+ assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd2[4].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd2[4].getAttribute("type"));
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProviderDyn2.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+
+ // Check that we have the complete metadata
+ assertNotNull(fooProvider2.getComponentMetadata());
+ }
+
+ /**
+ * Check component properties.
+ */
+ @Test
+ public void testFooProvider3() {
+ // Test SR properties
+// String impl = (String) sr_fooProvider3.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
+
+ String[] specs = (String[]) sr_fooProvider3.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
+ assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider3.getProperty("component.properties");
+ assertEquals("Check component.properties length (" + pd.length +")", pd.length, 3);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "foo", pd[0].getName());
+
+ assertEquals("Check component.properties name [" + 1 + "]", "bar", pd[1].getName());
+
+ assertEquals("Check component.properties name [" + 2 + "]", "baz", pd[2].getName());
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
+
+ // Test factory
+ assertEquals("Check factory name", fooProvider3.getName(), "Factories-FooProviderType-3");
+ Element cd = fooProvider3.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 1);
+ assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
+
+ Element[] pd2 = cd.getElements("property");
+ assertEquals("Check props length", pd2.length, 3);
+
+ assertEquals("Check component.properties name [" + 0 + "]", "foo", pd2[0].getAttribute("name"));
+
+ assertEquals("Check component.properties name [" + 1 + "]", "bar", pd2[1].getAttribute("name"));
+
+ assertEquals("Check component.properties name [" + 2 + "]", "baz", pd2[2].getAttribute("name"));
+ assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider3.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+ }
+
+ /**
+ * Test two services provider.
+ */
+ @Test
+ public void testFooBar() {
+ // Test SR properties
+// String impl = (String) sr_foobarProvider.getProperty("component.class");
+// assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1");
+
+ String[] specs = (String[]) sr_foobarProvider.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check component.providedServiceSpecifications length", specs.length, 2);
+
+ assertContains("Check component.providedServiceSpecifications 1", specs, FooService.class.getName());
+ assertContains("Check component.providedServiceSpecifications 2", specs, BarService.class.getName());
+
+ PropertyDescription[] pd = (PropertyDescription[]) sr_foobarProvider.getProperty("component.properties");
+ assertEquals("Check component.properties length", pd.length, 0);
+
+ // Test factory
+ assertEquals("Check factory name", foobarProvider.getName(), "Factories-FooBarProviderType-1");
+ Element cd = foobarProvider.getDescription();
+
+// assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
+
+ Element[] specs2 = cd.getElements("provides");
+ assertEquals("Check specs length", specs2.length, 2);
+ assertTrue("Check specs", containsSpecification(FooService.class.getName(), specs2));
+ assertTrue("Check specs", containsSpecification(BarService.class.getName(), specs2));
+
+ Element[] pd2 = cd.getElements("property");
+ assertNull("Check props null", pd2);
+
+ // Check Description equality
+ ComponentTypeDescription desc = (ComponentTypeDescription) sr_foobarProvider.getProperty("component.description");
+ assertNotNull("check description equality", desc);
+
+ // Check that we have the complete metadata
+ assertNotNull(foobarProvider.getComponentMetadata());
+ }
+
+ private boolean containsSpecification(String value, Element[] array) {
+ for (int i = 0; array != null && i < array.length; i++) {
+ if (array[i] != null && array[i].containsAttribute("specification") && array[i].getAttribute("specification").equals(value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java
new file mode 100644
index 0000000..9cbf410
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigAdmin.java
@@ -0,0 +1,162 @@
+/*
+ * 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.core;
+
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+/**
+ * Check configuration admin reconfiguration.
+ */
+public class TestConfigAdmin extends Common {
+
+ private ManagedServiceFactory getFactoryByName(String pid) {
+ ServiceReference[] refs;
+
+ refs = osgiHelper.getServiceReferences(ManagedServiceFactory.class.getName(), "(service.pid=" + pid + ")");
+ if (refs == null) {
+ return null;
+ }
+
+ return ((ManagedServiceFactory) osgiHelper.getServiceObject((refs[0])));
+ }
+
+ /**
+ * Check creation.
+ */
+ @Test
+ public void testCreation() {
+ ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", 3);
+ p.put("long", (long) 42);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ try {
+ f.updated("ok2", p);
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "ok2");
+ assertNotNull("Check instance creation", ref);
+ f.deleted("ok2");
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "ok2");
+ assertNull("Check instance deletion", ref);
+ } catch (ConfigurationException e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check creation (push String).
+ */
+ @Test
+ public void testCreationString() {
+ ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", "3");
+ p.put("long", "42");
+ p.put("string", "absdir");
+ p.put("strAProp", "{a}");
+ p.put("intAProp", "{1,2}");
+
+ try {
+ f.updated("ok2", p);
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "ok2");
+ assertNotNull("Check instance creation", ref);
+ f.deleted("ok2");
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "ok2");
+ assertNull("Check instance deletion", ref);
+ } catch (ConfigurationException e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check update and delete.
+ */
+ @Test
+ public void testUpdate() {
+ ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", 3);
+ p.put("long", (long) 42);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ try {
+ f.updated("okkkk", p);
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
+ assertNotNull("Check instance creation", ref);
+ p.put("int", new Integer("4"));
+ f.updated("okkkk", p);
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
+ Integer test = (Integer) ref.getProperty("int");
+ assertEquals("Check instance modification", 4, test.intValue());
+ f.deleted("okkkk");
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
+ assertNull("Check instance deletion", ref);
+ } catch (ConfigurationException e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check update and delete.
+ * (Push String).
+ */
+ @Test
+ public void testUpdateString() {
+ ManagedServiceFactory f = getFactoryByName("Factories-FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", "3");
+ p.put("long", "42");
+ p.put("string", "absdir");
+ p.put("strAProp", "{a}");
+ p.put("intAProp", "{1,2}");
+
+ try {
+ f.updated("okkkk", p);
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
+ assertNotNull("Check instance creation", ref);
+ p.put("int", new Integer("4"));
+ f.updated("okkkk", p);
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
+ Integer test = (Integer) ref.getProperty("int");
+ assertEquals("Check instance modification", 4, test.intValue());
+ f.deleted("okkkk");
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "okkkk");
+ assertNull("Check instance deletion", ref);
+ } catch (ConfigurationException e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestFactoryProperties.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestFactoryProperties.java
new file mode 100644
index 0000000..bd73784
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestFactoryProperties.java
@@ -0,0 +1,86 @@
+/*
+ * 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.core;
+
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class TestFactoryProperties extends Common {
+
+ @Test
+ public void testSimpleExposition() {
+ ServiceReference ref1 = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "Factories-FooProviderType-1");
+ assertNotNull("The factory is available", ref1);
+ String[] spec = (String[]) ref1.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check array length", spec.length, 1);
+ assertEquals("Check spec", spec[0], FooService.class.getName());
+ }
+
+ @Test
+ public void testDoubleExposition() {
+ ServiceReference ref1 = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "Factories-FooBarProviderType-1");
+ assertNotNull("The factory is available", ref1);
+ String[] spec = (String[]) ref1.getProperty("component.providedServiceSpecifications");
+ assertEquals("Check array length", spec.length, 2);
+ assertContains("Check spec 1", spec, FooService.class.getName());
+ assertContains("Check spec 2", spec, BarService.class.getName());
+ }
+
+ @Test
+ public void testProps() {
+ ServiceReference ref1 = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "Factories-FooProviderType-Dyn2");
+ assertNotNull("The factory is available", ref1);
+ PropertyDescription[] pd = (PropertyDescription[]) ref1.getProperty("component.properties");
+ assertEquals("Check property list size", pd.length, 5);
+
+ //P0
+ assertEquals("0) Check name", "int", pd[0].getName());
+ assertEquals("0) Check type", "int", pd[0].getType());
+ assertEquals("0) Check value", "4", pd[0].getValue());
+
+ //P1
+ assertEquals("1) Check name", "boolean", pd[1].getName());
+ assertEquals("1) Check type", "boolean", pd[1].getType());
+ assertNull("1) Check value", pd[1].getValue());
+
+ //P2
+ assertEquals("2) Check name", "string", pd[2].getName());
+ assertEquals("2) Check type", String.class.getName(), pd[2].getType());
+ assertNull("2) Check value", pd[2].getValue());
+
+ //P3
+ assertEquals("3) Check name", "strAProp", pd[3].getName());
+ assertEquals("3) Check type", "java.lang.String[]", pd[3].getType());
+ assertNull("3) Check value", pd[3].getValue());
+
+ //P4
+ assertEquals("4) Check name", "intAProp", pd[4].getName());
+ assertEquals("4) Check type", "int[]", pd[4].getType());
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestObedience.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestObedience.java
new file mode 100644
index 0000000..900dd72
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestObedience.java
@@ -0,0 +1,119 @@
+/*
+ * 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.core;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.HandlerManagerFactory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+/**
+ * Check that instances are disposed when the factory is stopped.
+ */
+public class TestObedience extends Common {
+
+ @Test
+ public void testObedience() {
+ assertNull("Check no foo service", osgiHelper.getServiceReference(FooService.class.getName()));
+ ComponentFactory factory = (ComponentFactory) ipojoHelper.getFactory("Factories-FooProviderType-1");
+ assertNotNull("Check factory existing", factory);
+
+ Properties props1 = new Properties();
+ props1.put("instance.name", "foo1");
+ Properties props2 = new Properties();
+ props2.put("instance.name", "foo2");
+
+ ComponentInstance ci1 = null, ci2 = null;
+ try {
+ ci1 = factory.createComponentInstance(props1);
+ ci2 = factory.createComponentInstance(props2);
+ } catch (Exception e) {
+ fail("Cannot instantiate foo providers : " + e.getMessage());
+ }
+
+ assertTrue("Check foo1 validity", ci1.getState() == ComponentInstance.VALID);
+ assertTrue("Check foo2 validity", ci2.getState() == ComponentInstance.VALID);
+
+ assertNotNull("Check foo service", osgiHelper.getServiceReference(FooService.class.getName()));
+ assertEquals("Check the number of Foo", osgiHelper.getServiceReferences(FooService.class.getName(), null).length, 2);
+
+ factory.stop();
+
+ assertTrue("Check foo1 invalidity (" + ci1.getState() + ")", ci1.getState() == ComponentInstance.DISPOSED);
+ assertTrue("Check foo2 invalidity (" + ci1.getState() + ")", ci2.getState() == ComponentInstance.DISPOSED);
+
+ assertNull("Check no foo service", osgiHelper.getServiceReference(FooService.class.getName()));
+
+ factory.start();
+ assertNull("Check no foo service", osgiHelper.getServiceReference(FooService.class.getName()));
+ }
+
+ @Test
+ public void testDisposeAfterFactoryInvalidation() {
+ ComponentFactory cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
+ assertNotNull("Check factory availability -1", cf);
+ assertEquals("Check factory state -1", Factory.VALID, cf.getState());
+
+ ServiceReference ref_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "SimpleInstance");
+ assertNotNull("Check Architecture availability -1", ref_arch);
+
+ HandlerManagerFactory hf = (HandlerManagerFactory) ipojoHelper.getHandlerFactory("controller");
+ assertNotNull("Check handler availability -1", hf);
+ assertEquals("Check handler state -1", Factory.VALID, hf.getState());
+
+ // Stop the handler
+ hf.stop();
+ HandlerManagerFactory hf2 = (HandlerManagerFactory) ipojoHelper.getHandlerFactory("controller");
+ assertNull("Check handler availability -2", hf2);
+
+ // Check the factory invalidity
+ cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
+ assertNotNull("Check factory availability -2", cf);
+ assertEquals("Check factory state -2", Factory.INVALID, cf.getState());
+
+ // Check the instance disparition
+ ref_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "SimpleInstance");
+ assertNull("Check Architecture availability -1", ref_arch);
+
+ // Restart the handler
+ hf.start();
+ hf2 = (HandlerManagerFactory) ipojoHelper.getHandlerFactory("controller");
+ assertNotNull("Check handler availability -3", hf2);
+
+ // Check the factory state
+ cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
+ assertNotNull("Check factory availability -3", cf);
+ assertEquals("Check factory state -3", Factory.VALID, cf.getState());
+
+
+ // Check the instance re-creation
+ ref_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "SimpleInstance");
+ assertNotNull("Check Architecture availability -3", ref_arch);
+
+ }
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java
new file mode 100644
index 0000000..ba674d8
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestReconfiguration.java
@@ -0,0 +1,333 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import junit.framework.Assert;
+import org.apache.felix.ipojo.*;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.io.IOException;
+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.fail;
+
+public class TestReconfiguration extends Common {
+
+ private ConfigurationAdmin admin;
+
+ @Before
+ public void setUp() {
+ admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
+ assertNotNull("Check configuration admin availability", admin);
+ try {
+ Configuration[] configurations = admin.listConfigurations(
+ "(service.factoryPid=org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType)");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ fail(e.getMessage());
+ } catch (InvalidSyntaxException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ try {
+ Configuration[] configurations = admin.listConfigurations(
+ "(service.factoryPid=org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType)");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ fail(e.getMessage());
+ } catch (InvalidSyntaxException e) {
+ fail(e.getMessage());
+ }
+ admin = null;
+ }
+
+ @Test
+ public void testRevalidationOnReconfiguration() {
+ ComponentFactory factory = (ComponentFactory) ipojoHelper.getFactory(
+ "org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType");
+
+ // First inject a configuration triggering an exception of the validate method.
+ Properties props = new Properties();
+ props.put("prop", "KO");
+ ComponentInstance ci = null;
+ try {
+ ci = factory.createComponentInstance(props);
+ } catch (UnacceptableConfiguration e) {
+ fail(e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail(e.getMessage());
+ } catch (ConfigurationException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(ci);
+ assertEquals("instance invalid", ComponentInstance.STOPPED, ci.getState());
+
+ // Reconfigure
+ props = new Properties();
+ props.put("prop", "OK");
+
+ ci.reconfigure(props);
+
+ assertNotNull(ci);
+ assertEquals("instance valid", ComponentInstance.VALID, ci.getState());
+ }
+
+ public static long UPDATE_WAIT_TIME = 2000;
+
+ @Test public void testRevalidationOnReconfigurationUsingConfigAdmin() throws InvalidSyntaxException {
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType", null);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ // First inject a configuration triggering an exception of the validate method.
+ props.put("prop", "KO");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ String pid = configuration.getPid();
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ Assert.assertNull("No architecture", osgiHelper.getServiceReference(Architecture.class.getName(),
+ "(architecture.instance=" + pid + ")"));
+
+
+ // Reconfigure
+ props = new Properties();
+ props.put("prop", "OK");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ pid = configuration.getPid();
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+ Architecture arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Is valid ?", ComponentInstance.VALID, arch.getInstanceDescription().getState());
+ }
+
+ @Test public void testRevalidationOnReconfigurationWithController() {
+ ComponentFactory factory = (ComponentFactory) ipojoHelper.getFactory(
+ "org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType2");
+
+ // First inject a configuration triggering an exception of the validate method.
+ Properties props = new Properties();
+ props.put("prop", "KO");
+ ComponentInstance ci = null;
+ try {
+ ci = factory.createComponentInstance(props);
+ } catch (UnacceptableConfiguration e) {
+ fail(e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail(e.getMessage());
+ } catch (ConfigurationException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(ci);
+ assertEquals("instance invalid", ComponentInstance.INVALID, ci.getState()); // Controller effect.
+
+ // Reconfigure
+ props = new Properties();
+ props.put("prop", "OK");
+
+ ci.reconfigure(props);
+
+ assertNotNull(ci);
+ assertEquals("instance valid", ComponentInstance.VALID, ci.getState());
+ }
+
+ @Test public void testRevalidationOnReconfigurationUsingConfigAdminAndController() throws InvalidSyntaxException {
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType2",
+ null);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ // First inject a configuration triggering an exception of the validate method.
+ props.put("prop", "KO");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ String pid = configuration.getPid();
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ // Invalid ... controller effect
+ Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+ Architecture arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Is invalid ?", ComponentInstance.INVALID, arch.getInstanceDescription().getState());
+
+ // Reconfigure
+ props = new Properties();
+ props.put("prop", "OK");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ pid = configuration.getPid();
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+ arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Is valid ?", ComponentInstance.VALID, arch.getInstanceDescription().getState());
+ }
+
+ @Test public void testRevalidationOnReconfigurationOfTheController() {
+ ComponentFactory factory = (ComponentFactory) ipojoHelper.getFactory(
+ "org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType3");
+
+ // First inject a configuration triggering an exception of the validate method.
+ Properties props = new Properties();
+ props.put("controller", "false");
+ ComponentInstance ci = null;
+ try {
+ ci = factory.createComponentInstance(props);
+ } catch (UnacceptableConfiguration e) {
+ fail(e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail(e.getMessage());
+ } catch (ConfigurationException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(ci);
+ assertEquals("instance invalid", ComponentInstance.INVALID, ci.getState()); // Controller effect.
+
+ // Reconfigure
+ props = new Properties();
+ props.put("controller", "true");
+
+ ci.reconfigure(props);
+
+ assertNotNull(ci);
+ assertEquals("instance valid", ComponentInstance.VALID, ci.getState());
+ }
+
+ @Test public void testRevalidationOnReconfigurationUsingConfigAdminOfTheController() throws InvalidSyntaxException {
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("org.apache.felix.ipojo.runtime.core.components.ReconfigurableSimpleType3",
+ null);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ // First inject a configuration triggering an exception of the validate method.
+ props.put("controller", "false");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ String pid = configuration.getPid();
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ // Invalid ... controller effect
+ Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+ Architecture arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Is invalid ?", ComponentInstance.INVALID, arch.getInstanceDescription().getState());
+
+ // Reconfigure
+ props = new Properties();
+ props.put("controller", "true");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ pid = configuration.getPid();
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ Assert.assertNotNull("architecture", osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+ arch = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Is valid ?", ComponentInstance.VALID, arch.getInstanceDescription().getState());
+ }
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUnacceptableConfiguration.java b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUnacceptableConfiguration.java
new file mode 100644
index 0000000..a0ccc5e
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUnacceptableConfiguration.java
@@ -0,0 +1,836 @@
+/*
+ * 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.core;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * Test unacceptable configuration.
+ */
+public class TestUnacceptableConfiguration extends Common {
+
+ /**
+ * Configuration without the name property.
+ */
+ @Test
+ public void testWithoutName() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("int", 3);
+ p.put("long", (long) 42);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("an acceptable configuration is refused : " + e.getMessage());
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Configuration without the name property.
+ */
+ @Test
+ public void testWithoutNameOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2opt");
+
+ Properties p = new Properties();
+ p.put("int", 3);
+ p.put("long", (long) 42);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("an acceptable configuration is refused : " + e.getMessage());
+ }
+
+ }
+
+ /**
+ * Empty configuration.
+ */
+ @Test
+ public void testEmptyConfiguration() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
+ Properties p = new Properties();
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+ }
+
+ /**
+ * Empty configuration.
+ */
+ @Test
+ public void testEmptyConfigurationOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2opt");
+ Properties p = new Properties();
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+ }
+
+ /**
+ * Empty configuration (just the name).
+ */
+ @Test
+ public void testEmptyConfiguration2() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+ Properties p = new Properties();
+ p.put("instance.name", "ko");
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ return;
+ }
+
+ fail("An unacceptable configuration is accepted");
+ }
+
+ /**
+ * Empty configuration (just the name).
+ */
+ @Test
+ public void testEmptyConfiguration2opt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
+ Properties p = new Properties();
+ p.put("instance.name", "ko");
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+
+ }
+
+ /**
+ * Null configuration (accept).
+ */
+ @Test
+ public void testNull() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(null);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+ }
+
+ /**
+ * Null configuration (accept).
+ */
+ @Test
+ public void testNullOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2opt");
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(null);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+ }
+
+ /**
+ * Null configuration (fail).
+ */
+ @Test
+ public void testNull2() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(null);
+ ci.dispose();
+ } catch (Exception e) {
+ return;
+ }
+
+ fail("An unacceptable configuration is accepted");
+ }
+
+ /**
+ * Null configuration (success).
+ */
+ @Test
+ public void testNull2Opt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(null);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+
+
+ }
+
+ /**
+ * Check static properties.
+ */
+ @Test
+ public void testStaticOK() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("long", 42l);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check static properties.
+ */
+ @Test
+ public void testStaticOKopt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2opt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("long", 42l);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check dynamic properties.
+ */
+ @Test
+ public void testDynamicOK() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+
+ /**
+ * Check dynamic properties.
+ */
+ @Test
+ public void testDynamicOKopt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dynopt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+
+ p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("boolean", true);
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("An acceptable configuration is rejected (2) : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check inconsistent types.
+ */
+ @Test
+ public void testDynamicBadType() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("long", (long) 42);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check inconsistent types.
+ */
+ @Test
+ public void testDynamicBadTypeOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dynopt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("long", (long) 42);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+
+ p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected (2) : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check good configuration (with overriding).
+ */
+ @Test
+ public void testDynamicComplete() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check good configuration (with overriding).
+ */
+ @Test
+ public void testDynamicCompleteOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+
+
+ p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected (2) : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check good configuration.
+ */
+ @Test
+ public void testDynamicJustEnough() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check good configuration.
+ */
+ @Test
+ public void testDynamicJustEnoughOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+
+ p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("boolean", true);
+ p.put("strAProp", new String[]{"a"});
+
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check good configuration.
+ */
+ @Test
+ public void testDynamicMix() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check good configuration.
+ */
+ @Test
+ public void testDynamicMixOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+
+ p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check uncomplete configuration.
+ */
+ @Test
+ public void testDynamicUncomplete() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ return;
+ }
+
+ fail("An unacceptable configuration is accepted");
+ }
+
+ /**
+ * Check uncomplete configuration.
+ */
+ @Test
+ public void testDynamicUncompleteOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+
+
+ }
+
+ /**
+ * Check good configuration (more properties).
+ */
+ @Test
+ public void testDynamicMore() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+ p.put("tralala", "foo");
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check good configuration (more properties).
+ */
+ @Test
+ public void testDynamicMoreOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+ p.put("tralala", "foo");
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check properties affecting services and component.
+ */
+ @Test
+ public void testDoubleProps() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+ p.put("boolean", false);
+ p.put("string", "toto");
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check properties affecting services and component.
+ */
+ @Test
+ public void testDoublePropsOpt() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
+
+ Properties p = new Properties();
+ p.put("instance.name", "ok");
+ p.put("int", 3);
+ p.put("boolean", true);
+ p.put("string", "absdir");
+ p.put("strAProp", new String[]{"a"});
+ p.put("intAProp", new int[]{1, 2});
+ p.put("boolean", false);
+ p.put("string", "toto");
+
+ ComponentInstance ci;
+ try {
+ ci = f.createComponentInstance(p);
+ ci.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is rejected : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check instance name unicity.
+ */
+ @Test
+ public void testUnicity1() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
+
+ ComponentInstance ci1, ci2, ci3;
+ try {
+ ci1 = f.createComponentInstance(null);
+ ci2 = f.createComponentInstance(null);
+ ci3 = f.createComponentInstance(null);
+ assertThat("Check name ci1, ci2", ci1.getInstanceName(), not(ci2.getInstanceName()));
+ assertThat("Check name ci1, ci3", ci1.getInstanceName(), not(ci3.getInstanceName()));
+ assertThat("Check name ci3, ci2", ci3.getInstanceName(), not(ci2.getInstanceName()));
+ ci1.dispose();
+ ci2.dispose();
+ ci3.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+ }
+
+ /**
+ * Check instance name unicity.
+ */
+ @Test
+ public void testUnicity2() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
+
+ ComponentInstance ci1, ci2, ci3;
+ try {
+ Properties p1 = new Properties();
+ p1.put("instance.name", "name1");
+ ci1 = f.createComponentInstance(p1);
+ Properties p2 = new Properties();
+ p2.put("instance.name", "name2");
+ ci2 = f.createComponentInstance(p2);
+ Properties p3 = new Properties();
+ p3.put("instance.name", "name3");
+ ci3 = f.createComponentInstance(p3);
+ assertThat("Check name ci1, ci2", ci1.getInstanceName(), not(ci2.getInstanceName()));
+ assertThat("Check name ci1, ci3", ci1.getInstanceName(), not(ci3.getInstanceName()));
+ assertThat("Check name ci3, ci2", ci3.getInstanceName(), not(ci2.getInstanceName()));
+ ci1.dispose();
+ ci2.dispose();
+ ci3.dispose();
+ } catch (Exception e) {
+ fail("An acceptable configuration is refused");
+ }
+ }
+
+ /**
+ * Check instance name unicity.
+ */
+ @Test
+ public void testUnicity3() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
+
+ ComponentInstance ci1 = null, ci2;
+ try {
+ Properties p1 = new Properties();
+ p1.put("instance.name", "name1");
+ ci1 = f.createComponentInstance(p1);
+ Properties p2 = new Properties();
+ p2.put("instance.name", "name1");
+ ci2 = f.createComponentInstance(p2);
+ assertThat("Check name ci1, ci2", ci1.getInstanceName(), not(ci2.getInstanceName()));
+ ci1.dispose();
+ ci2.dispose();
+ } catch (Exception e) {
+ if (ci1 != null) {
+ ci1.dispose();
+ }
+ // OK.
+ return;
+ }
+
+ fail("An unacceptable configuration is acceptable");
+ }
+
+ /**
+ * Check instance name unicity.
+ */
+ @Test
+ public void testUnicity4() {
+ Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
+ Factory f2 = ipojoHelper.getFactory("Factories-FooProviderType-1");
+
+ ComponentInstance ci1 = null, ci2;
+ try {
+ Properties p1 = new Properties();
+ p1.put("instance.name", "name1");
+ ci1 = f.createComponentInstance(p1);
+ Properties p2 = new Properties();
+ p2.put("instance.name", "name1");
+ ci2 = f2.createComponentInstance(p2);
+ assertThat("Check name ci1, ci2", ci1.getInstanceName(), not(ci2.getInstanceName()));
+ ci1.dispose();
+ ci2.dispose();
+ } catch (Exception e) {
+ if (ci1 != null) {
+ ci1.dispose();
+ }
+ return;
+ }
+
+ fail("An unacceptable configuration is acceptable");
+ }
+
+
+}
diff --git a/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/resources/exam.properties b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/resources/exam.properties
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ipojo/runtime/core-it/src/it/ipojo-core-factory-test/src/test/resources/exam.properties