Add two tests where the lifecycle controller is configured with the config admin
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1034778 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java b/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
index 33a01bd..fdd4d94 100644
--- a/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
+++ b/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
@@ -25,4 +25,10 @@
}
}
+ public void setController(boolean p) {
+ if (p) {
+ System.out.println("OK !!!!");
+ }
+ }
+
}
diff --git a/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java b/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java
index cbd3938..08edfe0 100644
--- a/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java
+++ b/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java
@@ -240,4 +240,96 @@
Assert.assertEquals("Is valid ?", ComponentInstance.VALID, arch.getInstanceDescription().getState());
}
+
+ public void testRevalidationOnReconfigurationOfTheController() {
+ ComponentFactory factory = (ComponentFactory) Utils.getFactoryByName(getContext(),
+ "org.apache.felix.ipojo.test.scenarios.component.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) {
+ e.printStackTrace();
+ } catch (MissingHandlerException e) {
+ e.printStackTrace();
+ } catch (ConfigurationException e) {
+ e.printStackTrace();
+ }
+
+ 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());
+ }
+
+ public void testRevalidationOnReconfigurationUsingConfigAdminOfTheController() throws InvalidSyntaxException {
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("org.apache.felix.ipojo.test.scenarios.component.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", getContext().getServiceReferences(Architecture.class.getName(), "(architecture.instance="+pid+")"));
+ Architecture arch = (Architecture) Utils.getServiceObject(getContext(), Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ Assert.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", getContext().getServiceReferences(Architecture.class.getName(), "(architecture.instance="+pid+")"));
+ arch = (Architecture) Utils.getServiceObject(getContext(), Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ Assert.assertEquals("Is valid ?", ComponentInstance.VALID, arch.getInstanceDescription().getState());
+ }
}
diff --git a/ipojo/tests/core/factories/src/main/resources/metadata.xml b/ipojo/tests/core/factories/src/main/resources/metadata.xml
index b59bd95..b7b6ef8 100644
--- a/ipojo/tests/core/factories/src/main/resources/metadata.xml
+++ b/ipojo/tests/core/factories/src/main/resources/metadata.xml
@@ -143,4 +143,12 @@
</properties>
<controller field="controller"/>
</component>
+ <component classname="org.apache.felix.ipojo.test.scenarios.component.ReconfigurableSimpleType"
+ name="org.apache.felix.ipojo.test.scenarios.component.ReconfigurableSimpleType3"
+ architecture="true" immediate="true">
+ <properties>
+ <property name="controller" method="setController" field="controller"/>
+ </properties>
+ <controller field="controller"/>
+ </component>
</ipojo>