Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New test-container for Eclipse Sisu #41

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions containers/pax-exam-container-sisu/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ops4j.pax</groupId>
<artifactId>exam</artifactId>
<version>4.7.0-SNAPSHOT</version>
<relativePath>../../pom</relativePath>
</parent>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-sisu</artifactId>

<name>OPS4J Pax Exam Sisu JSR330 Container</name>

<dependencies>

<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-cdi</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-spi</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<exclusions>
<exclusion>
<artifactId>javax.inject</artifactId>
<groupId>javax.inject</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
</dependency>

<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>javax.inject</artifactId>
<groupId>javax.inject</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<scope>test</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<scope>test</scope>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
<dependency>
<scope>test</scope>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<scope>test</scope>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2015 Roland Hauser
*
* 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.pax.exam.sisu;

import static org.pax.exam.sisu.ProxyFactory.createProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import javax.enterprise.inject.spi.InjectionTarget;

/**
* @author Roland Hauser
* @since 4.7.0
*/
public class BeanManagerProxy implements InvocationHandler {

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("createAnnotatedType".equals(method.getName()) || "createCreationalContext".equals(method.getName())) {
return null;
} else if ("createInjectionTarget".equals(method.getName())) {
return createProxy(InjectionTarget.class, new InjectionTargetProxy<>());
}

throw new UnsupportedOperationException(
"Sisu BeanManager proxy only supports createAnnotatedType(), createInjectionTarget() and createCreationalContext()");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2015 Roland Hauser
*
* 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.pax.exam.sisu;

import static org.pax.exam.sisu.SisuTestContainer.getInjector;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
* @author Roland Hauser
* @since 4.7.0
*/
public class InjectionTargetProxy<X> implements InvocationHandler {

/*
* (non-Javadoc)
*
* @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
* java.lang.reflect.Method, java.lang.Object[])
*/
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("inject".equals(method.getName())) {
getInjector().injectMembers(args[0]);
return null;
}
throw new UnsupportedOperationException("Sisu InjectionTarget proxy only supports inject()");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2015 Roland Hauser
*
* 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.pax.exam.sisu;

import static java.lang.reflect.Proxy.newProxyInstance;

import java.lang.reflect.InvocationHandler;

/**
* @author Roland Hauser
* @since 4.7.0
*/
public class ProxyFactory {

@SuppressWarnings("unchecked")
public static <T> T createProxy(Class<T> type, InvocationHandler handler) {
return (T) newProxyInstance(ProxyFactory.class.getClassLoader(), new Class<?>[] { type }, handler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2015 Roland Hauser
*
* 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.pax.exam.sisu;

import static org.pax.exam.sisu.ProxyFactory.createProxy;

import javax.enterprise.inject.spi.BeanManager;

import org.kohsuke.MetaInfServices;
import org.ops4j.pax.exam.cdi.spi.BeanManagerProvider;

/**
* @author Roland Hauser
* @since 4.7.0
*/
@MetaInfServices
public class SisuBeanManagerProvider implements BeanManagerProvider{

/* (non-Javadoc)
* @see org.ops4j.pax.exam.cdi.spi.BeanManagerProvider#getBeanManager()
*/
@Override
public BeanManager getBeanManager() {
return createProxy(BeanManager.class, new BeanManagerProxy());
}

}
Loading