Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/weld1019/HelloBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.jboss.weld.tests.interceptors.weld1019; | ||
|
||
import javax.inject.Named; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* | ||
*/ | ||
@MyScope | ||
public class HelloBean implements Serializable { | ||
private static final long serialVersionUID = -3216074155876250969L; | ||
|
||
@UpperCased | ||
public String getMessage() { | ||
return "Hello World"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/weld1019/MyScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.jboss.weld.tests.interceptors.weld1019; | ||
|
||
import javax.enterprise.context.NormalScope; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* | ||
*/ | ||
@Inherited | ||
@NormalScope(passivating = true) | ||
@Target({TYPE, METHOD, FIELD}) | ||
@Retention(RUNTIME) | ||
public @interface MyScope { | ||
} |
34 changes: 34 additions & 0 deletions
34
...s-arquillian/src/test/java/org/jboss/weld/tests/interceptors/weld1019/MyScopeContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jboss.weld.tests.interceptors.weld1019; | ||
|
||
import org.jboss.weld.context.AbstractContext; | ||
import org.jboss.weld.context.beanstore.BeanStore; | ||
import org.jboss.weld.context.beanstore.HashMapBeanStore; | ||
|
||
import javax.enterprise.context.spi.Contextual; | ||
import javax.enterprise.context.spi.CreationalContext; | ||
import java.lang.annotation.Annotation; | ||
|
||
/** | ||
* | ||
*/ | ||
public class MyScopeContext extends AbstractContext { | ||
|
||
private HashMapBeanStore beanStore = new HashMapBeanStore(); | ||
|
||
public MyScopeContext() { | ||
super(false); | ||
} | ||
|
||
public Class<? extends Annotation> getScope() { | ||
return MyScope.class; | ||
} | ||
|
||
@Override | ||
protected BeanStore getBeanStore() { | ||
return beanStore; | ||
} | ||
|
||
public boolean isActive() { | ||
return true; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...arquillian/src/test/java/org/jboss/weld/tests/interceptors/weld1019/MyScopeExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.jboss.weld.tests.interceptors.weld1019; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.enterprise.inject.spi.AfterBeanDiscovery; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.BeforeBeanDiscovery; | ||
import javax.enterprise.inject.spi.Extension; | ||
|
||
/** | ||
* | ||
*/ | ||
public class MyScopeExtension implements Extension { | ||
|
||
public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager manager) { | ||
event.addScope(MyScope.class, true, true); | ||
} | ||
|
||
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) { | ||
event.addContext(new MyScopeContext()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/weld1019/UpperCased.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.jboss.weld.tests.interceptors.weld1019; | ||
|
||
import javax.interceptor.InterceptorBinding; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* | ||
*/ | ||
@InterceptorBinding | ||
@Target({METHOD, TYPE}) | ||
@Retention(RUNTIME) | ||
public @interface UpperCased { | ||
} |
25 changes: 25 additions & 0 deletions
25
...lian/src/test/java/org/jboss/weld/tests/interceptors/weld1019/UppercasingInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.jboss.weld.tests.interceptors.weld1019; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* | ||
*/ | ||
@Interceptor | ||
@UpperCased | ||
public class UppercasingInterceptor implements Serializable { | ||
private static final long serialVersionUID = 7685137612002720995L; | ||
|
||
@AroundInvoke | ||
public Object intercept(InvocationContext ctx) throws Exception { | ||
Object value = ctx.proceed(); | ||
if (value instanceof String) { | ||
return ((String) value).toUpperCase(); | ||
} else { | ||
throw new RuntimeException("UppercasingInterceptor can only intercept methods that return String"); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/weld1019/Weld1019Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.jboss.weld.tests.interceptors.weld1019; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.BeanArchive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.enterprise.inject.spi.Extension; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author <a href="mailto:marko.luksa@gmail.com">Marko Luksa</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class Weld1019Test { | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
return ShrinkWrap | ||
.create(BeanArchive.class) | ||
.intercept(UppercasingInterceptor.class) | ||
.addPackage(Weld1019Test.class.getPackage()) | ||
.addAsServiceProvider(Extension.class, MyScopeExtension.class); | ||
} | ||
|
||
@Test | ||
public void testInterceptorInvoked(HelloBean helloBean, BeanManager beanManager) { | ||
assertEquals("HELLO WORLD", helloBean.getMessage()); | ||
} | ||
|
||
|
||
} |