felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1447494 - in /felix/trunk/ipojo/runtime/core-it/src/it: ipojo-core-lifecycle-callback-test/ ipojo-core-lifecycle-controller-test/ ipojo-core-lifecycle-controller-test/src/ ipojo-core-lifecycle-controller-test/src/main/ ipojo-core-lifecycle...
Date Mon, 18 Feb 2013 21:08:01 GMT
Author: clement
Date: Mon Feb 18 21:08:01 2013
New Revision: 1447494

URL: http://svn.apache.org/r1447494
Log:
FELIX-3903

Migrate the core lifecycle controller tests to pax exam 3

Added:
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/pom.xml
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/   (with
props)
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableLifecycleControllerTest.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/LifecycleControllerTest.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/resources/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/resources/metadata.xml
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurableLifeCycleController.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestImmediateLifeCycleController.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestLifeCycleController.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/resources/
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/resources/exam.properties

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/pom.xml?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/pom.xml (added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-callback-test/pom.xml Mon
Feb 18 21:08:01 2013
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <parent>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>org.apache.felix.ipojo.runtime.core-it</artifactId>
+        <version>1.9.0-SNAPSHOT</version>
+        <relativePath>../../../pom.xml</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.felix</groupId>
+    <artifactId>ipojo-core-lifecycle-callback-test</artifactId>
+
+    <name>${project.artifactId}</name>
+    
+</project>
\ No newline at end of file

Propchange: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Feb 18 21:08:01 2013
@@ -0,0 +1,3 @@
+target*
+*.iml
+.idea*

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableLifecycleControllerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableLifecycleControllerTest.java?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableLifecycleControllerTest.java
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ConfigurableLifecycleControllerTest.java
Mon Feb 18 21:08:01 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.
+ */
+package org.apache.felix.ipojo.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+
+import java.util.Properties;
+
+public class ConfigurableLifecycleControllerTest implements CheckService {
+
+	// This is both a property and the controller.
+    private boolean m_state;
+
+    public boolean check() {
+        return m_state;
+    }
+
+    public Properties getProps() {
+       Properties props = new Properties();
+       props.put("state", new Boolean(m_state));
+       return props;
+    }
+
+}
+

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/LifecycleControllerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/LifecycleControllerTest.java?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/LifecycleControllerTest.java
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/LifecycleControllerTest.java
Mon Feb 18 21:08:01 2013
@@ -0,0 +1,49 @@
+/* 
+ * 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 java.util.Properties;
+
+public class LifecycleControllerTest implements CheckService {
+    
+    private boolean m_state = true;
+    private String m_conf;
+    
+    public void setConf(String newConf) {
+        if (newConf.equals("foo")) {
+            m_state = true;
+        } else {
+            m_state = false;
+        }
+    }
+
+    public boolean check() {
+        return m_state;
+    }
+
+    public Properties getProps() {
+       Properties props = new Properties();
+       props.put("conf", m_conf);
+       props.put("state", new Boolean(m_state));
+       return props;
+    }
+}
+

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-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-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
Mon Feb 18 21:08:01 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-lifecycle-controller-test/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/resources/metadata.xml?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/resources/metadata.xml
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/main/resources/metadata.xml
Mon Feb 18 21:08:01 2013
@@ -0,0 +1,35 @@
+<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.LifecycleControllerTest"
+            name="LFC-Test">
+        <provides />
+        <controller field="m_state" />
+        <properties>
+            <property name="conf" field="m_conf" method="setConf" />
+        </properties>
+    </component>
+
+    <component
+            classname="org.apache.felix.ipojo.runtime.core.components.LifecycleControllerTest"
+            name="LFC-Test-Immediate" immediate="true" architecture="true">
+        <provides />
+        <controller field="m_state" />
+        <properties>
+            <property name="conf" field="m_conf" method="setConf" />
+        </properties>
+    </component>
+
+    <component
+            classname="org.apache.felix.ipojo.runtime.core.components.ConfigurableLifecycleControllerTest"
+            name="LFC-Test-Configurable" architecture="true">
+        <provides />
+        <!-- The property and the controller share the same field -->
+        <controller field="m_state" />
+        <properties>
+            <property name="state" field="m_state" />
+        </properties>
+    </component>
+</ipojo>
\ No newline at end of file

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-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-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
Mon Feb 18 21:08:01 2013
@@ -0,0 +1,196 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.CompositeOption;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.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 IOException {
+        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")
+        );
+    }
+
+    public static Option junitAndMockitoBundles() {
+        return new DefaultCompositeOption(
+                // Repository required to load harmcrest (OSGi-fied version).
+                repository("http://repository.springsource.com/maven/bundles/external").id(
+                        "com.springsource.repository.bundles.external"),
+
+                // Mockito without Hamcrest and Objenesis
+                mavenBundle("org.mockito", "mockito-core", "1.9.5"),
+
+                // Hamcrest with a version matching the range expected by Mockito
+                mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
+
+                // Objenesis with a version matching the range expected by Mockito
+                wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
+                        .exports("*;version=1.2"),
+
+                // The default JUnit bundle also exports Hamcrest, but with an (incorrect)
version of
+                // 4.9 which does not match the Mockito import.
+                CoreOptions.junitBundles(),
+
+                /*
+                 * Felix has implicit boot delegation enabled by default. It conflicts with
Mockito:
+                 * java.lang.LinkageError: loader constraint violation in interface itable
initialization:
+                 * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
+                 * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the
class loader
+                 * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader)
of the current class,
+                 * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc,
and the class loader
+                 * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5)
for interface
+                 * org/mockito/cglib/proxy/Factory have different Class objects for the type
org/mockito/cglib/
+                 * proxy/Callback used in the signature
+                 *
+                 * So we disable the bootdelegation.
+                 */
+                frameworkProperty("felix.bootdelegation.implicit").value("false")
+        );
+    }
+
+
+    @Before
+    public void commonSetUp() {
+        osgiHelper = new OSGiHelper(bc);
+        ipojoHelper = new IPOJOHelper(bc);
+
+        // Dump OSGi Framework information
+        String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
+        if (vendor == null) {
+            vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
+        }
+        String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
+        System.out.println("OSGi Framework : " + vendor + " - " + version);
+    }
+
+    @After
+    public void commonTearDown() {
+        ipojoHelper.dispose();
+        osgiHelper.dispose();
+    }
+
+    public CompositeOption ipojoBundles() {
+        return new DefaultCompositeOption(
+                mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+                mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
+                // harmcrest-all
+                //mavenBundle("de.twentyeleven.skysail", "org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
+                // configuration admin
+                mavenBundle("org.apache.felix",  "org.apache.felix.configadmin").versionAsInProject()
+        );
+    }
+
+    public Option testedBundle() throws MalformedURLException {
+        File out = new File("target/tested/bundle.jar");
+        if (out.exists()) {
+            return bundle(out.toURI().toURL().toExternalForm());
+        }
+
+        TinyBundle tested = TinyBundles.bundle();
+
+        // We look inside target/classes to find the class and resources
+        File classes = new File("target/classes");
+        Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE,
TrueFileFilter.INSTANCE);
+        List<File> services = new ArrayList<File>();
+        for (File file : files) {
+            if (file.isDirectory()) {
+                // By convention we export of .services and .service package
+                if (file.getName().endsWith("services")  || file.getName().endsWith("service"))
{
+                    services.add(file);
+                }
+            } else {
+                // We need to compute the path
+                String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length()
+1);
+                tested.add(path, file.toURI().toURL());
+                System.out.println(file.getName() + " added to " + path);
+            }
+        }
+
+        String export = "";
+        for (File file : services) {
+            if (export.length() > 0) { export += ", "; }
+            String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length()
+1);
+            String packageName = path.replace('/', '.');
+            export += packageName;
+        }
+
+        System.out.println("Exported packages : " + export);
+
+        InputStream inputStream = tested
+                .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
+                .set(Constants.IMPORT_PACKAGE, "*")
+                .set(Constants.EXPORT_PACKAGE, export)
+                .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
+
+        try {
+            org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
+            return bundle(out.toURI().toURL().toExternalForm());
+        } catch (MalformedURLException e) {
+            throw new RuntimeException("Cannot compute the url of the manipulated bundle");
+        } catch (IOException e) {
+            throw new RuntimeException("Cannot write of the manipulated bundle");
+        }
+    }
+
+    public void assertContains(String s, String[] arrays, String object) {
+        for (String suspect : arrays) {
+            if (object.equals(suspect)) {
+                return;
+            }
+        }
+        fail("Assertion failed : " + s);
+    }
+
+
+}

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurableLifeCycleController.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurableLifeCycleController.java?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurableLifeCycleController.java
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConfigurableLifeCycleController.java
Mon Feb 18 21:08:01 2013
@@ -0,0 +1,150 @@
+/*
+ * 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.*;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class TestConfigurableLifeCycleController extends Common {
+
+    private ComponentInstance under;
+
+    private Factory factory;
+
+
+    @Before
+    public void setUp() {
+        factory = ipojoHelper.getFactory("LFC-Test-Configurable");
+    }
+
+    @Test
+    public void testValidThenInvalid() throws UnacceptableConfiguration, MissingHandlerException,
ConfigurationException {
+        Properties props = new Properties();
+        props.put("instance.name", "under1");
+        props.put("state", "true");
+        under = factory.createComponentInstance(props);
+
+        // The conf is correct, the PS must be provided
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(),
"under1");
+        assertNotNull("Check service availability -1", ref);
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state 1", cs.check());
+        bc.ungetService(ref);
+
+        // Reconfigure the instance
+        props.put("state", "false"); // Bar is a bad conf
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+        }
+
+        // The instance should now be invalid
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNull("Check service availability -2", ref);
+
+        // Reconfigure the instance with a valid configuration
+        props.put("state", "true");
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable (2) : "
+ props);
+        }
+
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNotNull("Check service availability -3", ref);
+        cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state 2", cs.check());
+        bc.ungetService(ref);
+
+        under.dispose();
+    }
+
+    @Test
+    public void testInValidThenValid() throws Exception {
+        Properties props = new Properties();
+        props.put("instance.name", "under1");
+        props.put("state", "false");
+        under = factory.createComponentInstance(props);
+
+        // The instance should now be invalid
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(),
"under1");
+        assertNull("Check service availability -2", ref);
+
+        // Reconfigure the instance
+        props.put("state", "true"); // Bar is a bad conf
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+        }
+
+//        Object[] objects = Utils.getServiceObjects(context, Architecture.class.getName(),
null);
+//        for (int i = 0; i < objects.length; i++) {
+//        	Architecture a = (Architecture) objects[i];
+//        	System.out.println(a.getInstanceDescription().getDescription());
+//        }
+
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNotNull("Check service availability -1", ref);
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state 1", cs.check());
+        bc.ungetService(ref);
+
+
+        // Reconfigure the instance
+        props.put("state", "false"); // Bar is a bad conf
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+        }
+
+        // The instance should now be invalid
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNull("Check service availability -2", ref);
+
+        // Reconfigure the instance with a valid configuration
+        props.put("state", "true");
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable (2) : "
+ props);
+        }
+
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNotNull("Check service availability -3", ref);
+        cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state 2", cs.check());
+        bc.ungetService(ref);
+
+        under.dispose();
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestImmediateLifeCycleController.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestImmediateLifeCycleController.java?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestImmediateLifeCycleController.java
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestImmediateLifeCycleController.java
Mon Feb 18 21:08:01 2013
@@ -0,0 +1,118 @@
+/* 
+ * 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.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestImmediateLifeCycleController extends Common {
+
+    private ComponentInstance under;
+    private Factory factory;
+
+    @Before
+    public void setUp() {
+        factory = ipojoHelper.getFactory("LFC-Test-Immediate");
+    }
+
+    @Test
+    public void testOne() {
+        Properties props = new Properties();
+        props.put("conf", "foo");
+        props.put("instance.name", "under1");
+        under = ipojoHelper.createComponentInstance("LFC-Test-Immediate", props);
+
+        // The conf is correct, the PS must be provided
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(),
"under1");
+        assertNotNull("Check service availability -1", ref);
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state 1", cs.check());
+        bc.ungetService(ref);
+
+
+        // Reconfigure the instance with a bad configuration
+        props.put("conf", "bar"); // Bar is a bad conf
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+        }
+
+        // The instance should now be invalid 
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNull("Check service availability -2", ref);
+
+        // Reconfigure the instance with a valid configuration
+        props.put("conf", "foo"); // Bar is a bad conf
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable (2) : "
+ props);
+        }
+
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNotNull("Check service availability -3", ref);
+        cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state 2", cs.check());
+        bc.ungetService(ref);
+
+        under.dispose();
+    }
+
+    @Test
+    public void testTwo() {
+        Properties props = new Properties();
+        props.put("conf", "bar");
+        props.put("instance.name", "under2");
+        under = ipojoHelper.createComponentInstance("LFC-Test-Immediate", props);
+
+        assertEquals("check under state", under.getState(), ComponentInstance.INVALID);
+
+        // The conf is incorrect, the PS must not be provided
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(),
"under2");
+        assertNull("Check service availability -1", ref);
+
+        // Reconfigure the instance with a correct configuration
+        props.put("conf", "foo");
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+        }
+
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under2");
+        assertNotNull("Check service availability -2", ref);
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state ", cs.check());
+        bc.ungetService(ref);
+
+
+        under.dispose();
+    }
+
+
+}

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestLifeCycleController.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestLifeCycleController.java?rev=1447494&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestLifeCycleController.java
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestLifeCycleController.java
Mon Feb 18 21:08:01 2013
@@ -0,0 +1,138 @@
+/* 
+ * 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.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class TestLifeCycleController extends Common {
+
+    private ComponentInstance under;
+
+    private Factory factory;
+
+    @Before
+    public void setUp() {
+        factory = ipojoHelper.getFactory("LFC-Test");
+    }
+
+    @Test
+    public void testOne() {
+        Properties props = new Properties();
+        props.put("conf", "foo");
+        props.put("instance.name", "under1");
+        under = ipojoHelper.createComponentInstance("LFC-Test", props);
+
+        // The conf is correct, the PS must be provided
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(),
"under1");
+        assertNotNull("Check service availability -1", ref);
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state 1", cs.check());
+        bc.ungetService(ref);
+
+        // Reconfigure the instance with a bad configuration
+        props.put("conf", "bar"); // Bar is a bad conf
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+        }
+
+        // The instance should now be invalid 
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNull("Check service availability -2", ref);
+
+        // Reconfigure the instance with a valid configuration
+        props.put("conf", "foo"); // Bar is a bad conf
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable (2) : "
+ props);
+        }
+
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
+        assertNotNull("Check service availability -3", ref);
+        cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state 2", cs.check());
+        bc.ungetService(ref);
+
+        under.dispose();
+    }
+
+    /**
+     * This test must be removed as it is not compliant with osgiHelper. It unregisters a
service during the creation of the
+     * service instance, so the returned object is null.
+     */
+    @Test
+    @Ignore("This test must be removed as it is not compliant with osgiHelper. It unregisters
a service during the creation" +
+            " of the service instance, so the returned object is null.")
+    public void testTwo() {
+        Properties props = new Properties();
+        props.put("conf", "bar");
+        props.put("instance.name", "under2");
+        under = ipojoHelper.createComponentInstance("LFC-Test", props);
+
+        // The conf is incorrect, but the test can appears only when the object is created
: the PS must be provided
+        ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(),
"under2");
+        assertNotNull("Check service availability -1", ref);
+
+        System.out.println("CS received : " + osgiHelper.getServiceObject(ref));
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertNotNull("Assert CS not null", cs);
+        try {
+            assertFalse("Check state (false)", cs.check());
+        } catch (Throwable e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+
+        // As soon as the instance is created, the service has to disappear :
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under2");
+        assertNull("Check service availability -2", ref);
+
+        // Reconfigure the instance with a correct configuration
+        props.put("conf", "foo");
+        try {
+            factory.reconfigure(props);
+        } catch (Exception e) {
+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
+        }
+
+        ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under2");
+        assertNotNull("Check service availability -3", ref);
+        cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertTrue("Check state ", cs.check());
+        bc.ungetService(ref);
+
+        under.dispose();
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/resources/exam.properties
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-lifecycle-controller-test/src/test/resources/exam.properties?rev=1447494&view=auto
==============================================================================
    (empty)



Mime
View raw message