You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/04/29 14:59:53 UTC
svn commit: r1477027 [1/3] - in /felix/trunk/ipojo/runtime:
core-it/src/it/ipojo-core-configuration-admin-test/
core-it/src/it/ipojo-core-configuration-admin-test/src/
core-it/src/it/ipojo-core-configuration-admin-test/src/main/
core-it/src/it/ipojo-co...
Author: clement
Date: Mon Apr 29 12:59:52 2013
New Revision: 1477027
URL: http://svn.apache.org/r1477027
Log:
Fix FELIX-4040, reimplement configuration admin support
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/ (with props)
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/pom.xml
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableFooProvider.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/resources/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/resources/metadata.xml
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/ConfigurationMonitor.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForService.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/resources/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurablePropertiesUsingConfigAdmin.java
- copied, changed from r1471456, felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurableProperties.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndConfigAdmin.java
- copied, changed from r1471456, felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedServiceFactory.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndConfigAdmin.java
- copied, changed from r1471456, felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndManagedServiceFactory.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/ConfigurationTracker.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/FactoryClassloader.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/PrimitiveTypeDescription.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/util/ServiceLocator.java
Removed:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestDynamicallyConfigurableProperties.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedMethodAndManagedServiceFactory.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestUpdatedNoArgMethodAndManagedServiceFactory.java
Modified:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentTypeDescription.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/configuration/Instance.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/Extender.java
Propchange: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Apr 29 12:59:52 2013
@@ -0,0 +1,2 @@
+target
+*.iml
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/pom.xml?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/pom.xml (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/pom.xml Mon Apr 29 12:59:52 2013
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<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-configuration-admin-test</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <version>1.2.8</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableFooProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableFooProvider.java?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableFooProvider.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableFooProvider.java Mon Apr 29 12:59:52 2013
@@ -0,0 +1,72 @@
+/*
+ * 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 ConfigurableFooProvider implements FooService {
+
+ private String message; // Configurable property
+ private int invokeCount = 0;
+
+ public void setMessage(String message) {
+ System.err.println("=== Set message to " + message);
+ this.message = message;
+ invokeCount++;
+ }
+
+ public boolean foo() {
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties props = new Properties();
+ if (message == null) {
+ props.put("message", "NULL");
+ } else {
+ props.put("message", message);
+ }
+ props.put("count", new Integer(invokeCount));
+ return props;
+ }
+
+ public boolean getBoolean() {
+ return false;
+ }
+
+ public double getDouble() {
+ return invokeCount;
+ }
+
+ public int getInt() {
+ return invokeCount;
+ }
+
+ public long getLong() {
+ return invokeCount;
+ }
+
+ public Boolean getObject() {
+ return null;
+ }
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java Mon Apr 29 12:59:52 2013
@@ -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();
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java Mon Apr 29 12:59:52 2013
@@ -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();
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/resources/metadata.xml?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/resources/metadata.xml (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/main/resources/metadata.xml Mon Apr 29 12:59:52 2013
@@ -0,0 +1,41 @@
+<!--
+ ~ 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.
+ -->
+
+<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
+ xmlns="org.apache.felix.ipojo">
+ <component classname="org.apache.felix.ipojo.runtime.core.components.ConfigurableFooProvider"
+ name="CA-ConfigurableProvider">
+ <provides/>
+ <properties>
+ <property name="message" method="setMessage"/>
+ </properties>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.runtime.core.components.ConfigurableFooProvider"
+ immediate="true"
+ name="CA-ImmConfigurableProvider">
+ <provides/>
+ <properties>
+ <property name="message" method="setMessage"/>
+ </properties>
+ </component>
+
+
+</ipojo>
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java Mon Apr 29 12:59:52 2013
@@ -0,0 +1,248 @@
+/*
+ * 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 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.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.ow2.chameleon.testing.helpers.IPOJOHelper;
+import org.ow2.chameleon.testing.helpers.OSGiHelper;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+/**
+ * Bootstrap the test from this project
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class Common {
+
+ public static long UPDATE_WAIT_TIME = 2000;
+
+ @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);
+
+ waitForStability(bc);
+ }
+
+ public Bundle getTestBundle() {
+ return osgiHelper.getBundle("test.bundle");
+ }
+
+ @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(),
+ 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");
+ }
+ }
+
+ /**
+ * Waits for stability:
+ * <ul>
+ * <li>all bundles are activated
+ * <li>service count is stable
+ * </ul>
+ * If the stability can't be reached after a specified time,
+ * the method throws a {@link IllegalStateException}.
+ *
+ * @param context the bundle context
+ * @throws IllegalStateException when the stability can't be reach after a several attempts.
+ */
+ private void waitForStability(BundleContext context) throws IllegalStateException {
+ // Wait for bundle initialization.
+ boolean bundleStability = getBundleStability(context);
+ int count = 0;
+ while (!bundleStability && count < 500) {
+ try {
+ Thread.sleep(5);
+ } catch (InterruptedException e) {
+ // Interrupted
+ }
+ count++;
+ bundleStability = getBundleStability(context);
+ }
+
+ if (count == 500) {
+ System.err.println("Bundle stability isn't reached after 500 tries");
+ throw new IllegalStateException("Cannot reach the bundle stability");
+ }
+
+ boolean serviceStability = false;
+ count = 0;
+ int count1 = 0;
+ int count2 = 0;
+ while (!serviceStability && count < 500) {
+ try {
+ ServiceReference[] refs = context.getServiceReferences((String) null, null);
+ count1 = refs.length;
+ Thread.sleep(500);
+ refs = context.getServiceReferences((String) null, null);
+ count2 = refs.length;
+ serviceStability = count1 == count2;
+ } catch (Exception e) {
+ System.err.println(e);
+ serviceStability = false;
+ // Nothing to do, while recheck the condition
+ }
+ count++;
+ }
+
+ if (count == 500) {
+ System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
+ throw new IllegalStateException("Cannot reach the service stability");
+ }
+ }
+
+ /**
+ * Are bundle stables.
+ *
+ * @param bc the bundle context
+ * @return <code>true</code> if every bundles are activated.
+ */
+ private boolean getBundleStability(BundleContext bc) {
+ boolean stability = true;
+ Bundle[] bundles = bc.getBundles();
+ for (Bundle bundle : bundles) {
+ stability = stability && (bundle.getState() == Bundle.ACTIVE);
+ }
+ return stability;
+ }
+
+ public boolean isKF() {
+ return bc.getClass().toString().contains("knopflerfish");
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/ConfigurationMonitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/ConfigurationMonitor.java?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/ConfigurationMonitor.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/ConfigurationMonitor.java Mon Apr 29 12:59:52 2013
@@ -0,0 +1,74 @@
+/*
+ * 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 junit.framework.Assert;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationEvent;
+import org.osgi.service.cm.ConfigurationListener;
+
+public class ConfigurationMonitor implements ConfigurationListener {
+
+ private String waitForEvent;
+ private boolean detected;
+ private ServiceRegistration reg;
+
+ public synchronized void configurationEvent(ConfigurationEvent arg0) {
+ System.out.println(arg0.getPid() + " reconfiguration received");
+ if (waitForEvent != null) {
+ if (arg0.getPid().equals(waitForEvent)) {
+ this.detected = true;
+ }
+ }
+ }
+
+ public ConfigurationMonitor(BundleContext bc) {
+ reg = bc.registerService(ConfigurationListener.class.getName(), this, null);
+ }
+
+ public void stop() {
+ reg.unregister();
+ reg = null;
+ }
+
+ public void waitForEvent(String pid, String mes) {
+ waitForEvent = pid;
+ detected = false;
+ long begin = System.currentTimeMillis();
+ long duration = 0;
+ while( ! this.detected) {
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ // Interrupted
+ }
+ long end = System.currentTimeMillis();
+ duration = end - begin;
+ if (duration > 10000) {
+ Assert.fail(mes + " -> Timeout when waiting for a reconfiguration of " + pid);
+ }
+ }
+ System.out.println("Reconfiguration detected of " + pid);
+ waitForEvent = null;
+ detected = false;
+ }
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForImmediate.java Mon Apr 29 12:59:52 2013
@@ -0,0 +1,404 @@
+/*
+ * 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.PrimitiveInstanceDescription;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+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.*;
+
+public class TestManagedServiceFactoryTestForImmediate extends Common {
+
+ private ComponentFactory factory;
+ private ConfigurationAdmin admin;
+
+ @Before
+ public void setUp() {
+ factory = (ComponentFactory) ipojoHelper.getFactory("CA-ImmConfigurableProvider");
+ admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName(), null);
+ assertNotNull("Check configuration admin availability", admin);
+ try {
+ Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ImmConfigurableProvider)");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void tearDown() {
+ try {
+ Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ImmConfigurableProvider)");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ admin = null;
+
+
+ }
+
+ @Test
+ public void testCreationAndReconfiguration() {
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("message", "message");
+
+ 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());
+ }
+
+ // The instance should be created, wait for the architecture service
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
+ Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = (Integer) p.get("count");
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message", mes);
+ assertEquals("Assert count", 1, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ props.put("message", "message2");
+ try {
+ configuration.update(props);
+ // Update the configuration ...
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = (Integer) p.get("count");
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message2", mes);
+ assertEquals("Assert count", 2, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ try {
+ configuration.delete();
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNull("Check unavailability", ref);
+ }
+
+ @Test
+ public void testCreationAndReconfiguration2() {
+ //The reconfiguration happens before the service invocation
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("message", "message");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ String pid = configuration.getPid();
+ System.out.println("PID : " + pid);
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ // The instance should be created, wait for the architecture service
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
+ Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ props.put("message", "message2");
+ try {
+ configuration.update(props);
+ // Update the configuration ...
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Check object -2", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ //Invoke
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message2", mes);
+ assertEquals("Assert count", 2, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ try {
+ configuration.delete();
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNull("Check unavailability", ref);
+ }
+
+ @Test
+ public void testDelayedCreationAndReconfiguration() {
+ factory.stop();
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("message", "message");
+
+ 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());
+ }
+
+ assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+
+ factory.start();
+
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+
+ // The instance should be created, wait for the architecture service
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
+ Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = (Integer) p.get("count");
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message", mes);
+ assertEquals("Assert count", 1, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ props.put("message", "message2");
+ try {
+ configuration.update(props);
+ // Update the configuration ...
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = (Integer) p.get("count");
+ // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message2", mes);
+ //assertEquals("Assert count", 2, count);
+ // This test was removed as the result can be 3.
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ try {
+ configuration.delete();
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNull("Check unavailability", ref);
+ }
+
+ @Test
+ public void testDelayedCreationAndReconfiguration2() {
+ factory.stop();
+ //The reconfiguration happens before the service invocation
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("message", "message");
+
+ 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());
+ }
+
+ assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+
+ factory.start();
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+
+ // The instance should be created, wait for the architecture service
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
+ Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ props.put("message", "message2");
+ try {
+ configuration.update(props);
+ // Update the configuration ...
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Check object -1", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ //Invoke
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = (Integer) p.get("count");
+ // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message2", mes);
+ assertEquals("Assert count", 2, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ try {
+ configuration.delete();
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNull("Check unavailability", ref);
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceFactoryTestForServices.java Mon Apr 29 12:59:52 2013
@@ -0,0 +1,406 @@
+/*
+ * 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.PrimitiveInstanceDescription;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+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.*;
+
+public class TestManagedServiceFactoryTestForServices extends Common {
+
+ private ComponentFactory factory;
+ private ConfigurationAdmin admin;
+
+ @Before
+ public void setUp() {
+ factory = (ComponentFactory) ipojoHelper.getFactory("CA-ConfigurableProvider");
+ admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName(), null);
+ assertNotNull("Check configuration admin availability", admin);
+ try {
+ Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ConfigurableProvider)");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void tearDown() {
+ try {
+ Configuration[] configurations = admin.listConfigurations("(service.factoryPid=CA-ConfigurableProvider)");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ admin = null;
+
+
+ }
+
+ @Test
+ public void testMSFCreationAndReconfiguration() {
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", "?");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("message", "message");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ String pid = configuration.getPid();
+ System.out.println("PID : " + pid);
+
+ // The instance should be created, wait for the architecture service
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
+ Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ osgiHelper.waitForService(FooService.class.getName(), "(instance.name=" + pid + ")", 1000);
+
+ ServiceReference refx = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNotNull("Check refx", refx);
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNotNull("Check fs", fs);
+
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = (Integer) p.get("count");
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message", mes);
+ assertEquals("Assert count", 1, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+
+ Dictionary p2 = configuration.getProperties();
+ p2.put("message", "message2");
+ try {
+ System.err.println("The configuration will be updated with message2");
+
+ configuration.update(p2);
+ // Update the configuration ...
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.err.println("The configuration should be updated with message2");
+
+ fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = (Integer) p.get("count");
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message2", mes);
+ assertEquals("Assert count", 2, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ try {
+ configuration.delete();
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNull("Check unavailability", ref);
+ }
+
+ @Test
+ public void testMSFCreationAndReconfiguration2() {
+ //The reconfiguration happens before the service invocation
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", "?");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("message", "message");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ String pid = configuration.getPid();
+
+ // The instance should be created, wait for the architecture service
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
+ Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ props.put("message", "message2");
+ try {
+ configuration.update(props);
+ // Update the configuration ...
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Check no object -2", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ //Invoke
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = (Integer) p.get("count");
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message2", mes);
+ assertEquals("Assert count", 1, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ try {
+ configuration.delete();
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNull("Check unavailability", ref);
+ }
+
+ @Test
+ public void testDelayedCreationAndReconfiguration() {
+ factory.stop();
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", "?");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("message", "message");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ String pid = configuration.getPid();
+
+ assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+
+ factory.start();
+
+
+ // The instance should be created, wait for the architecture service
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
+ Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ osgiHelper.waitForService(FooService.class.getName(), "(instance.name=" + pid + ")", 1000);
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = (Integer) p.get("count");
+ // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message", mes);
+ assertEquals("Assert count", 1, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ System.out.println("===");
+
+ props.put("message", "message2");
+ try {
+ configuration.update(props);
+ // Update the configuration ...
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.out.println("===");
+
+ fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = (Integer) p.get("count");
+ // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message2", mes);
+ assertEquals("Assert count", 2, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ try {
+ configuration.delete();
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNull("Check unavailability", ref);
+ }
+
+ @Test
+ public void testDelayedCreationAndReconfiguration2() {
+ factory.stop();
+ //The reconfiguration happens before the service invocation
+ Configuration configuration = null;
+ try {
+ configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", "?");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ Dictionary props = configuration.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("message", "message");
+
+ try {
+ configuration.update(props);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ String pid = configuration.getPid();
+ System.out.println("PID : " + pid);
+
+ assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
+
+ factory.start();
+
+
+ // The instance should be created, wait for the architecture service
+ osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
+ Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
+
+ assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ // Wait for the processing of the first configuration.
+ try {
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (InterruptedException e1) {
+ fail(e1.getMessage());
+ }
+
+ props.put("message", "message2");
+ try {
+ configuration.update(props);
+ // Update the configuration ...
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ //architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Check no object -2", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ //Invoke
+ FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = (Integer) p.get("count");
+ // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
+
+ assertEquals("Assert Message", "message2", mes);
+ assertEquals("Assert count", 1, count);
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
+
+ try {
+ configuration.delete();
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
+ assertNull("Check unavailability", ref);
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java?rev=1477027&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-configuration-admin-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestManagedServiceTestForImmediate.java Mon Apr 29 12:59:52 2013
@@ -0,0 +1,398 @@
+/*
+ * 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.PrimitiveInstanceDescription;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+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 TestManagedServiceTestForImmediate extends Common {
+
+ private String factNameImm = "CA-ImmConfigurableProvider";
+ private String msp = "foo";
+
+ private ComponentFactory factImm;
+
+ private ConfigurationAdmin admin;
+
+ ConfigurationMonitor listener;
+
+ @Before
+ public void setUp() throws InterruptedException {
+ factImm = (ComponentFactory) ipojoHelper.getFactory(factNameImm);
+ admin = (ConfigurationAdmin) osgiHelper.getServiceObject(ConfigurationAdmin.class.getName(), null);
+ assertNotNull("Check configuration admin availability", admin);
+ cleanConfigurationAdmin();
+ listener = new ConfigurationMonitor(bc);
+ }
+
+ @After
+ public void tearDown() {
+ listener.stop();
+ cleanConfigurationAdmin();
+ admin = null;
+ }
+
+ private void cleanConfigurationAdmin() {
+ try {
+ Configuration[] configurations = admin.listConfigurations("(service.pid=" + msp + ")");
+ for (int i = 0; configurations != null && i < configurations.length; i++) {
+ configurations[i].delete();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testFactoryCreationAndReconfigurationUsingManagedService() {
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp); // Exposes a ManagedService.
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) bc.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = (Integer) p.get("count");
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertEquals("Check message", "message", mes);
+ assertEquals("Check count", 1, count);
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ System.err.println("updated ? ");
+ //Thread.sleep(UPDATE_WAIT_TIME);
+ listener.waitForEvent(configuration.getPid(), "1");
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) bc.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = (Integer) p.get("count");
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes);
+ assertEquals("Check count", 2, count);
+
+ instance.dispose();
+ cleanConfigurationAdmin();
+ }
+
+ /**
+ * Creates an instance using a factory configuration.
+ * The configuration specifies the managed.service.pid property
+ * Reconfiguration is applied using the exposed managed service.
+ */
+ @Test
+ public void testCreationUsingFactoryConfigurationSettingTheManagedServicePid() {
+ Configuration conf = null;
+ try {
+ //TODO test multi-location:?
+ conf = admin.createFactoryConfiguration(factNameImm, getTestBundle().getLocation());
+ Dictionary props = conf.getProperties();
+ if (props == null) {
+ props = new Properties();
+ }
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ conf.update(props);
+ Thread.sleep(UPDATE_WAIT_TIME); // Wait for the creation.
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+
+ Architecture arch = (Architecture) osgiHelper.getServiceObject(org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), conf.getPid());
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ // arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ FooService fs = (FooService) bc.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
+ assertEquals("Check message", "message", mes);
+ assertEquals("Check count", 1, count);
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ //Thread.sleep(UPDATE_WAIT_TIME);
+ listener.waitForEvent(configuration.getPid(), "1");
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), conf.getPid());
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ // arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
+ fs = (FooService) bc.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
+ if (mes.equals("message")) {
+ System.out.println("Warning, configuration not yet applied");
+ assertEquals("Check count - W", 1, count);
+ } else {
+ assertEquals("Check message", "message2", mes);
+ assertEquals("Check count", 2, count);
+ }
+
+ try {
+ conf.delete();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ @Test
+ public void testCreationAndReconfiguration2() {
+ // The configuration exists before the instance creation.
+
+ //Update
+ Configuration configuration = null;
+ try {
+ configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) bc.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ // int count1 = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertEquals("Check message - 1 (" + mes + ")", "message2", mes); // Already reconfigured.
+ // assertEquals("Check count", 2, count); // Two : 1) "message" on immediate, "message2" on the reconfiguration,
+ // not necessary as the property can be set before the immediate instance creation
+
+ instance.dispose();
+
+ //Reconfiguration
+ try {
+ configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message3");
+ configuration.update(prc);
+ listener.waitForEvent(msp, "1");
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // Recreation of the instance.
+ props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ Thread.sleep(UPDATE_WAIT_TIME * 2);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) bc.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ // int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertEquals("Check message already reconfigured", "message3", mes); // Already reconfigured.
+ //assertEquals("Check count", count1 + 1, count); // message before the reconfiguration, message3 after the reconfiguration
+
+ instance.dispose();
+
+
+ }
+
+ @Test
+ public void testCreationAndReconfiguration3() {
+ // The configuration exists before the instance creation.
+
+ //Update
+ Configuration configuration;
+ try {
+ configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message2");
+ configuration.update(prc);
+ listener.waitForEvent(msp, "1");
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ Properties props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ ComponentInstance instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ Thread.sleep(UPDATE_WAIT_TIME);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ FooService fs = (FooService) bc.getService(ref);
+ Properties p = fs.fooProps();
+ String mes = p.getProperty("message");
+ // int count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertEquals("Check message", "message2", mes); // Already reconfigured.
+ //assertEquals("Check count", 1, count);
+
+ //Reconfiguration
+ try {
+ configuration = admin.getConfiguration(msp);
+ Dictionary prc = configuration.getProperties();
+ if (prc == null) {
+ prc = new Properties();
+ }
+ prc.put("message", "message3");
+ configuration.update(prc);
+ //Thread.sleep(UPDATE_WAIT_TIME);
+ listener.waitForEvent(msp, "1");
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ instance.dispose();
+
+ // Recreation of the instance.
+ props = new Properties();
+ props.put("managed.service.pid", msp);
+ props.put("message", "message");
+ instance = null;
+ try {
+ instance = factImm.createComponentInstance(props);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertNotNull("FS availability", ref);
+
+ fs = (FooService) bc.getService(ref);
+ p = fs.fooProps();
+ mes = p.getProperty("message");
+ // count = ((Integer) p.get("count")).intValue();
+ assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
+ assertEquals("Check message", "message3", mes); // Already reconfigured.
+ // assertEquals("Check count", 1, count);
+
+ instance.dispose();
+
+
+ }
+
+
+}