Author: clement
Date: Mon Feb 18 21:03:02 2013
New Revision: 1447492
URL: http://svn.apache.org/r1447492
Log:
FELIX-3903
Migrate the core handler tests to pax exam 3
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/ (with
props)
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/pom.xml
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/DummyImpl.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyComponent.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/DummyHandler.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/EmptyHandler.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Dummy.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/MyService.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-component.xml
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-handler.xml
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/ignorecase.xml
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/DummyHandlerTest.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/IgnoreCaseHandlerSelectionTest.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/resources/
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/resources/exam.properties
Propchange: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Feb 18 21:03:02 2013
@@ -0,0 +1,3 @@
+target*
+*.iml
+.idea
Added: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/pom.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/pom.xml?rev=1447492&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/pom.xml
(added)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/pom.xml
Mon Feb 18 21:03:02 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-handler-test</artifactId>
+
+ <name>${project.artifactId}</name>
+
+</project>
\ No newline at end of file
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/DummyImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/DummyImpl.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/DummyImpl.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/DummyImpl.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,16 @@
+package org.apache.felix.ipojo.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.Dummy;
+
+
+/**
+ * Just a Dummy test
+ */
+public class DummyImpl implements Dummy {
+
+ private void start() {
+ }
+
+ private void stop() {
+ }
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyComponent.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyComponent.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyComponent.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/MyComponent.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,11 @@
+package org.apache.felix.ipojo.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+
+public class MyComponent implements MyService {
+
+ public void foo() {
+ // Nothing to do.
+ }
+
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/DummyHandler.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/DummyHandler.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/DummyHandler.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/DummyHandler.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2009 OW2 Chameleon Licensed 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.handlers;
+
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
+import org.apache.felix.ipojo.metadata.Element;
+import org.osgi.service.useradmin.User;
+
+import java.util.Dictionary;
+
+
+public class DummyHandler extends PrimitiveHandler {
+
+ public DummyHandler() {
+ }
+
+ /*------------------------------------------------------------*
+ * Handler Specific Methods *
+ *------------------------------------------------------------*/
+
+ @Override
+ public void initializeComponentFactory(ComponentTypeDescription typeDesc,
Element metadata) throws ConfigurationException {
+ // Initialize
+ super.initializeComponentFactory(typeDesc, metadata);
+ }
+
+ @Override
+ public void configure(Element metadata, Dictionary configuration) throws
ConfigurationException {
+ }
+
+
+ private void bindUser(User user) {
+ // in order to test
+ user.getName();
+ }
+
+ private void unBindUser(User user) {
+ // in order to test
+ user.getType();
+ }
+
+ @Override
+ public void start() {
+ }
+
+ @Override
+ public void stop() {
+ }
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/EmptyHandler.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/EmptyHandler.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/EmptyHandler.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/handlers/EmptyHandler.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,27 @@
+package org.apache.felix.ipojo.runtime.core.handlers;
+
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.PrimitiveHandler;
+import org.apache.felix.ipojo.metadata.Element;
+
+import java.util.Dictionary;
+
+public class EmptyHandler extends PrimitiveHandler {
+
+ @Override
+ public void configure(Element arg0, Dictionary arg1)
+ throws ConfigurationException {
+ info("Configured");
+ }
+
+ @Override
+ public void start() {
+ info("Started");
+ }
+
+ @Override
+ public void stop() {
+ info("Stopped");
+ }
+
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Dummy.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Dummy.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Dummy.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Dummy.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,5 @@
+package org.apache.felix.ipojo.runtime.core.services;
+
+public interface Dummy {
+}
+
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/MyService.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/MyService.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/MyService.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/MyService.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.runtime.core.services;
+
+public interface MyService {
+
+ public void foo();
+
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-component.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-component.xml?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-component.xml
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-component.xml
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<iPOJO xmlns:dummy="org.apache.felix.ipojo.test.dummy.handler.dummyhandler">
+ <component
className="org.apache.felix.ipojo.runtime.core.components.DummyImpl"
name="dummy.test">
+ <callback transition="validate" method="start" />
+ <callback transition="invalidate" method="stop" />
+
+ <dummy:dummy/>
+ </component>
+</iPOJO>
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-handler.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-handler.xml?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-handler.xml
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/dummy-handler.xml
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ <iPOJO xmlns:wbp="org.apache.felix.ipojo.whiteboard"
+ xmlns:jmx="org.apache.felix.ipojo.handlers.jmx">
+ -->
+<iPOJO>
+ <!-- Declare the handler -->
+ <handler
classname="org.apache.felix.ipojo.runtime.core.handlers.DummyHandler"
name="dummy"
+ namespace="org.apache.felix.ipojo.test.dummy.handler.dummyhandler">
+
+
+ <requires optional="true" aggregate="true">
+ <callback type="bind" method="bindUser" />
+ <callback type="unbind" method="unBindUser" />
+ </requires>
+ </handler>
+</iPOJO>
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/ignorecase.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/ignorecase.xml?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/ignorecase.xml
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/main/resources/ignorecase.xml
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,20 @@
+<ipojo xmlns:ex="org.apache.felix.ipojo.tests.core.handler">
+
+<!-- Empty handler, name and namespace written strangely -->
+<handler
+ name="EmPtY"
+ namespace="orG.apAche.feliX.iPOJO.tests.CORE.hAnDlEr"
+ classname="org.apache.felix.ipojo.runtime.core.handlers.EmptyHandler">
+</handler>
+
+<component
classname="org.apache.felix.ipojo.runtime.core.components.MyComponent"
name="IgnoreCase-1">
+ <ex:empty/>
+</component>
+<instance component="IgnoreCase-1" name="IgnoreCase-1"/>
+
+<component
classname="org.apache.felix.ipojo.runtime.core.components.MyComponent"
name="IgnoreCase-2">
+ <ex:eMptY/>
+</component>
+<instance component="IgnoreCase-2" name="IgnoreCase-2"/>
+
+</ipojo>
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-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-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,230 @@
+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.options.libraries.JUnitBundlesOption;
+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(),
+ junitAndMockitoBundles(),
+ // No tested bundle in this project
+
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")
+ );
+ }
+
+
+
+ /**
+ * Creates a {@link
org.ops4j.pax.exam.options.libraries.JUnitBundlesOption}.
+ *
+ * @return junit bundles option
+ */
+ public static CompositeOption junitBundles() {
+ return new DefaultCompositeOption(
+ // We need the spring source repository to get hamcrest
+
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.
+ new JUnitBundlesOption(),
+
+ // see config1()
+
frameworkProperty("felix.bootdelegation.implicit").value("false")
+ );
+
+// return new DefaultCompositeOption(new JUnitBundlesOption(),
+// systemProperty("pax.exam.invoker").value("junit"),
+//
bundle("mvn:org.ops4j.pax.tipi/org.ops4j.pax.tipi.hamcrest.core/1.3.0.1"),
+//
bundle("link:classpath:META-INF/links/org.ops4j.pax.exam.invoker.junit.link"));
+ }
+
+ @Before
+ public void commonSetUp() {
+ osgiHelper = new OSGiHelper(bc);
+ ipojoHelper = new IPOJOHelper(bc);
+
+ // Dump OSGi Framework information
+ String vendor = (String)
osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
+ if (vendor == null) {
+ vendor = (String)
osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
+ }
+ String version = (String)
osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
+ System.out.println("OSGi Framework : " + vendor + " - " + version);
+ }
+
+ @After
+ public void commonTearDown() {
+ ipojoHelper.dispose();
+ osgiHelper.dispose();
+ }
+
+ public CompositeOption ipojoBundles() {
+ return new DefaultCompositeOption(
+ mavenBundle("org.apache.felix",
"org.apache.felix.ipojo").versionAsInProject(),
+ mavenBundle("org.ow2.chameleon.testing",
"osgi-helpers").versionAsInProject(),
+ // harmcrest-all
+ //mavenBundle("de.twentyeleven.skysail",
"org.hamcrest.hamcrest-all-osgi").versionAsInProject(),
+ // configuration admin
+ mavenBundle("org.apache.felix",
"org.apache.felix.configadmin").versionAsInProject()
+ );
+ }
+
+ public Option testedBundle() throws MalformedURLException {
+ File out = new File("target/tested/bundle.jar");
+
+ TinyBundle tested = TinyBundles.bundle();
+
+ // We look inside target/classes to find the class and resources
+ File classes = new File("target/classes");
+ Collection<File> files = FileUtils.listFilesAndDirs(classes,
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
+ List<File> services = new ArrayList<File>();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ // By convention we export of .services and .service package
+ if (file.getName().endsWith("services") ||
file.getName().endsWith("service")) {
+ services.add(file);
+ }
+ } else {
+ // We need to compute the path
+ String path =
file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
+ tested.add(path, file.toURI().toURL());
+ System.out.println(file.getName() + " added to " + path);
+ }
+ }
+
+ String export = "";
+ for (File file : services) {
+ if (export.length() > 0) { export += ", "; }
+ String path =
file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
+ String packageName = path.replace('/', '.');
+ export += packageName;
+ }
+
+ System.out.println("Exported packages : " + export);
+
+ InputStream inputStream = tested
+ .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
+ .set(Constants.IMPORT_PACKAGE, "*")
+ .set(Constants.EXPORT_PACKAGE, export)
+ .build(IPOJOStrategy.withiPOJO(new
File("src/main/resources")));
+
+ try {
+ org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream,
out);
+ return bundle(out.toURI().toURL().toExternalForm());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Cannot compute the url of the
manipulated bundle");
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot write of the manipulated
bundle");
+ }
+ }
+
+ public void assertContains(String s, String[] arrays, String object) {
+ for (String suspect : arrays) {
+ if (object.equals(suspect)) {
+ return;
+ }
+ }
+ fail("Assertion failed : " + s);
+ }
+
+
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/DummyHandlerTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/DummyHandlerTest.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/DummyHandlerTest.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/DummyHandlerTest.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,185 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import junit.framework.Assert;
+import org.apache.commons.io.FileUtils;
+import org.apache.felix.ipojo.*;
+import org.apache.felix.ipojo.runtime.core.components.DummyImpl;
+import org.apache.felix.ipojo.runtime.core.handlers.DummyHandler;
+import org.apache.felix.ipojo.runtime.core.services.Dummy;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.useradmin.User;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.ops4j.pax.exam.CoreOptions.bundle;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+
+
+@ExamReactorStrategy(PerMethod.class)
+public class DummyHandlerTest extends Common {
+
+ private static final String DUMMY_TEST_FACTORY = "dummy.test";
+
+ /*
+ * Number of mock object by test.
+ */
+ private static final int NB_MOCK = 10;
+
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ // Build handler bundle
+ File handlerJar = new File("target/bundles/handler.jar");
+ FileUtils.copyInputStreamToFile(
+ TinyBundles.bundle()
+ .add(DummyHandler.class)
+ .set(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME,
"Dummy.Handler")
+ .build(IPOJOStrategy.withiPOJO(new
File("src/main/resources/dummy-handler.xml"))),
+ handlerJar);
+
+ // Build consumer bundle
+ File dummyJar = new File("target/bundles/dummy.jar");
+ FileUtils.copyInputStreamToFile(
+ TinyBundles.bundle()
+ .add(Dummy.class)
+ .add(DummyImpl.class)
+ .set(org.osgi.framework.Constants.EXPORT_PACKAGE,
"org.apache.felix.ipojo.runtime.core" +
+ ".services")
+ .set(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME,
"Dummy.Bundle")
+ .build(IPOJOStrategy.withiPOJO(new
File("src/main/resources/dummy-component.xml"))),
+ dummyJar);
+
+
+ return OptionUtils.combine(options,
+ bundle(handlerJar.toURI().toURL().toExternalForm()),
+ bundle(dummyJar.toURI().toURL().toExternalForm()),
+
mavenBundle().groupId("org.apache.felix").artifactId("org.osgi.compendium").version("1.4.0"));
+ }
+
+ /**
+ * Basic Test, in order to know if the instance is correctly create.
+ */
+ @Test
+ public void testDummyTestInstance() {
+ ComponentInstance instance;
+
+ // Get the factory
+ Factory factory = Tools.getValidFactory(osgiHelper,
DUMMY_TEST_FACTORY);
+ Assert.assertNotNull(factory);
+
+ // Create an instance
+ try {
+ instance = factory.createComponentInstance(null);
+ } catch (UnacceptableConfiguration e) {
+ throw new AssertionError(e);
+ } catch (MissingHandlerException e) {
+ throw new AssertionError(e);
+ } catch (ConfigurationException e) {
+ throw new AssertionError(e);
+ }
+
+ // Must be valid now
+ Assert.assertEquals(instance.getState(), ComponentInstance.VALID);
+
+ // Stop the instance
+ instance.stop();
+ Assert.assertEquals(instance.getState(), ComponentInstance.STOPPED);
+
+ // Start the instance
+ instance.start();
+ Assert.assertEquals(instance.getState(), ComponentInstance.VALID);
+ }
+
+ /**
+ * Test if the bind and unbind methods are called when the bind service
are registered after the instance creation
+ */
+ @Test
+ public void testDummyTestBindAfterStart() {
+ // Get the factory
+ Factory factory = Tools.getValidFactory(osgiHelper,
DUMMY_TEST_FACTORY);
+ assertNotNull(factory);
+
+ // Create an instance
+ ComponentInstance instance =
ipojoHelper.createComponentInstance(DUMMY_TEST_FACTORY);
+
+ Map<User, ServiceRegistration> registrations = new HashMap<User,
ServiceRegistration>();
+
+ for (int i = 0; i < NB_MOCK; i++) {
+ User service = mock(User.class);
+ ServiceRegistration sr = bc.registerService(User.class.getName(),
service, null);
+ registrations.put(service, sr);
+ }
+
+ //verify that the bind method of the handler has been called
+ for (User user : registrations.keySet()) {
+ verify(user).getName();
+ }
+
+ //verify that the unbind has been called
+ for (User user : registrations.keySet()) {
+ registrations.get(user).unregister();
+ verify(user).getType();
+ }
+
+ //verify no more interaction
+ for (User user : registrations.keySet()) {
+ Mockito.verifyNoMoreInteractions(user);
+ }
+ }
+
+
+ /**
+ * Test if the bind and unbind methods when the bind services are
registered before the instance creation
+ */
+ @Test
+ public void testDummyTestBindBeforeStart() {
+ ComponentInstance instance = null;
+
+ Map<User, ServiceRegistration> registrations = new HashMap<User,
ServiceRegistration>();
+
+ for (int i = 0; i < NB_MOCK; i++) {
+ User service = mock(User.class);
+ ServiceRegistration sr = bc.registerService(User.class.getName(),
service, null);
+ registrations.put(service, sr);
+ }
+
+ // Get the factory
+ Factory factory = Tools.getValidFactory(osgiHelper,
DUMMY_TEST_FACTORY);
+ assertNotNull(factory);
+
+ instance = ipojoHelper.createComponentInstance(DUMMY_TEST_FACTORY);
+
+ //verify that the bind method of the handler has been called
+ for (User user : registrations.keySet()) {
+ verify(user).getName();
+ }
+
+ //verify that the unbind has been called
+ for (User user : registrations.keySet()) {
+ registrations.get(user).unregister();
+ verify(user).getType();
+ }
+
+ //verify no more interaction
+ for (User user : registrations.keySet()) {
+ Mockito.verifyNoMoreInteractions(user);
+ }
+ }
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/IgnoreCaseHandlerSelectionTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/IgnoreCaseHandlerSelectionTest.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/IgnoreCaseHandlerSelectionTest.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/IgnoreCaseHandlerSelectionTest.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,140 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.HandlerDescription;
+import org.apache.felix.ipojo.runtime.core.components.MyComponent;
+import org.apache.felix.ipojo.runtime.core.handlers.EmptyHandler;
+import org.apache.felix.ipojo.runtime.core.services.MyService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.ops4j.pax.exam.CoreOptions.bundle;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
+/**
+ * Check that the handler selection ignore case.
+ * An empty handler declared with
+ * name="EmPtY" and namespace="orG.apAche.feliX.iPOJO.tests.CORE.hAnDlEr"
+ * is declared, and two instances using this handler are created. The test is
+ * successful is the two instances are created correctly.
+ * Test about Felix-1318 : Case mismatch problem of iPOJO custom handler name
+ */
+public class IgnoreCaseHandlerSelectionTest extends Common {
+
+ @Configuration
+ public Option[] config() throws IOException {
+
+ Option[] options = super.config();
+
+ File tmp = new File("target/bundles");
+ tmp.mkdirs();
+
+ // Build handler bundle
+ File serviceJar = new File("target/bundles/service.jar");
+ FileUtils.copyInputStreamToFile(
+ TinyBundles.bundle()
+ .add(MyService.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceInterface")
+ .set(Constants.EXPORT_PACKAGE,
"org.apache.felix.ipojo.runtime.core.services")
+ .build(withBnd()),
+ serviceJar);
+
+ // Build component and handler bundle
+ File componentJar = new File("target/bundles/componentAndHandler.jar");
+ FileUtils.copyInputStreamToFile(
+ TinyBundles.bundle()
+ .add(MyComponent.class)
+ .add(EmptyHandler.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "IgnoreCase")
+ .build(IPOJOStrategy.withiPOJO(new
File("src/main/resources/ignorecase.xml"))),
+ componentJar);
+
+ return OptionUtils.combine(options,
+ bundle(serviceJar.toURI().toURL().toExternalForm()),
+ bundle(componentJar.toURI().toURL().toExternalForm()));
+ }
+
+ @Test
+ public void testDeploy() {
+ Bundle[] bundles = bc.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ Assert.assertEquals(bundles[i].getSymbolicName() + " is not
active", Bundle.ACTIVE, bundles[i].getState());
+ }
+ }
+
+ /**
+ * Checks that the handler is declared and accessible.
+ */
+ @Test
+ public void testHandlerAvailability() {
+ ServiceReference[] refs =
osgiHelper.getServiceReferences(HandlerFactory.class.getName(), null);
+ for (ServiceReference ref : refs) {
+ String name = (String) ref.getProperty("handler.name");
+ String ns = (String) ref.getProperty("handler.namespace");
+ if (name != null
+ && name.equalsIgnoreCase("EmPtY") // Check with ignore
case.
+ && ns != null
+ &&
ns.equalsIgnoreCase("orG.apAche.feliX.iPOJO.tests.CORE.hAnDlEr")) { // Check
with ignore case.
+ Integer state = (Integer) ref.getProperty("factory.state");
+ if (state != null) {
+ Assert.assertEquals(Factory.VALID, state.intValue());
+ return; // Handler found and valid.
+ } else {
+ Assert.fail("Handler found but no state exposed");
+ }
+ }
+ }
+ Assert.fail("Handler not found");
+ }
+
+ /**
+ * Check that the instance is correctly created with "empty".
+ */
+ @Test
+ public void testCreationOfIgnoreCase1() {
+ ServiceReference refv1 =
ipojoHelper.getServiceReferenceByName(Architecture.class.getName(),
"IgnoreCase-1");
+ Assert.assertNotNull(refv1);
+ Architecture arch = (Architecture)
osgiHelper.getServiceObject(refv1);
+ Assert.assertEquals(ComponentInstance.VALID,
arch.getInstanceDescription().getState());
+
+ HandlerDescription desc = arch.getInstanceDescription()
+
.getHandlerDescription("orG.apAche.feliX.iPOJO.tests.CORE.hAnDlEr:EmPtY"); //
Check with the declared name.
+
+ Assert.assertNotNull(desc);
+ Assert.assertTrue(desc.isValid());
+ }
+
+ /**
+ * Check that the instance is correctly created with "eMptY".
+ */
+ @Test
+ public void testCreationOfIgnoreCase2() {
+ ServiceReference refv1 =
ipojoHelper.getServiceReferenceByName(Architecture.class.getName(),
"IgnoreCase-2");
+ Assert.assertNotNull(refv1);
+ Architecture arch = (Architecture)
osgiHelper.getServiceObject(refv1);
+ Assert.assertEquals(ComponentInstance.VALID,
arch.getInstanceDescription().getState());
+
+ HandlerDescription desc = arch.getInstanceDescription()
+
.getHandlerDescription("org.apache.felix.ipojo.tests.core.handler:empty"); //
Check with different case.
+ Assert.assertNotNull(desc);
+ Assert.assertTrue(desc.isValid());
+ }
+
+
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java?rev=1447492&view=auto
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java
(added)
+++
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/java/org/apache/felix/ipojo/runtime/core/Tools.java
Mon Feb 18 21:03:02 2013
@@ -0,0 +1,25 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.Factory;
+import org.osgi.framework.ServiceReference;
+import org.ow2.chameleon.testing.helpers.OSGiHelper;
+
+public class Tools {
+
+
+ /**
+ * Get the Factory linked to the given pid
+ * @param osgi
+ * @param name
+ * @return The factory
+ */
+ public static Factory getValidFactory(final OSGiHelper osgi, final String
name) {
+ // Get The Factory ServiceReference
+ ServiceReference facref =
osgiHelper.getServiceReference(Factory.class.getName(),
"(&(factory.state=1)(factory.name=" + name + "))");
+ // Get the factory
+ Factory factory = (Factory) osgiHelper.getServiceObject(facref);
+
+ return factory;
+ }
+
+}
Added:
felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/resources/exam.properties
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-handler-test/src/test/resources/exam.properties?rev=1447492&view=auto
==============================================================================
(empty)