Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-493 Converted ejb and interceptor tests to Arquillian
- Loading branch information
1 parent
ecfb52c
commit 36db20e
Showing
28 changed files
with
598 additions
and
136 deletions.
There are no files selected for viewing
File renamed without changes.
51 changes: 51 additions & 0 deletions
51
tests-arquillian/src/test/java/org/jboss/weld/tests/ejb/EJBTest.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,51 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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.jboss.weld.tests.ejb; | ||
|
||
import org.jboss.arquillian.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.jboss.shrinkwrap.api.spec.EnterpriseArchive; | ||
import org.jboss.weld.tests.category.Integration; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
@Category(Integration.class) | ||
@RunWith(Arquillian.class) | ||
public class EJBTest | ||
{ | ||
@Deployment | ||
public static Archive<?> deploy() | ||
{ | ||
return ShrinkWrap.create(EnterpriseArchive.class, "test.ear") | ||
.addModule( | ||
ShrinkWrap.create(BeanArchive.class) | ||
.addPackage(EJBTest.class.getPackage()) | ||
); | ||
} | ||
|
||
@Test | ||
public void testNoInterface(Cow cow) | ||
{ | ||
cow.ping(); | ||
Assert.assertTrue(cow.isPinged()); | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
88 changes: 88 additions & 0 deletions
88
...n/src/test/java/org/jboss/weld/tests/interceptors/ejb/EnterpriseBeanInterceptionTest.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,88 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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.jboss.weld.tests.interceptors.ejb; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.ejb.Timer; | ||
import javax.enterprise.inject.spi.InterceptionType; | ||
import javax.inject.Inject; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.jboss.arquillian.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.jboss.shrinkwrap.api.spec.EnterpriseArchive; | ||
import org.jboss.weld.bean.SessionBean; | ||
import org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter; | ||
import org.jboss.weld.ejb.spi.InterceptorBindings; | ||
import org.jboss.weld.manager.BeanManagerImpl; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Arquillian.class) | ||
public class EnterpriseBeanInterceptionTest | ||
{ | ||
@Deployment | ||
public static Archive<?> deploy() | ||
{ | ||
return ShrinkWrap.create(EnterpriseArchive.class, "test.ear") | ||
.addModule( | ||
ShrinkWrap.create(BeanArchive.class) | ||
.intercept(Goalkeeper.class, Defender.class, Referee.class) | ||
.addPackage(EnterpriseBeanInterceptionTest.class.getPackage()) | ||
); | ||
} | ||
|
||
@Inject | ||
private BeanManagerImpl beanManager; | ||
|
||
@Test | ||
public void testInterceptors() throws Exception | ||
{ | ||
SessionBean<Ball> ballSessionBean = (SessionBean<Ball>)beanManager.getBeans(Ball.class).iterator().next(); | ||
InterceptorBindings interceptorBindings = new InterceptorBindingsAdapter(beanManager.getCdiInterceptorsRegistry().getInterceptionModel(ballSessionBean.getType())); | ||
List<javax.enterprise.inject.spi.Interceptor> interceptors = | ||
new ArrayList<javax.enterprise.inject.spi.Interceptor>(interceptorBindings.getAllInterceptors()); | ||
|
||
Assert.assertEquals(3, interceptors.size()); | ||
List<Class<?>> expectedInterceptors = Arrays.<Class<?>>asList(Goalkeeper.class, Defender.class, Referee.class); | ||
Assert.assertTrue(expectedInterceptors.contains(interceptors.get(0).getBeanClass())); | ||
Assert.assertTrue(expectedInterceptors.contains(interceptors.get(1).getBeanClass())); | ||
Assert.assertTrue(expectedInterceptors.contains(interceptors.get(2).getBeanClass())); | ||
|
||
|
||
Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getType().getMethod("shoot")).size()); | ||
Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("shoot")).size()); | ||
Assert.assertEquals(Goalkeeper.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("shoot")).get(0).getBeanClass()); | ||
|
||
Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getType().getMethod("pass")).size()); | ||
Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("pass")).size()); | ||
Assert.assertEquals(Defender.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getType().getMethod("pass")).get(0).getBeanClass()); | ||
|
||
Method finishGameMethod = ballSessionBean.getType().getMethod("finishGame", Timer.class); | ||
Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, finishGameMethod).size()); | ||
Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, finishGameMethod).size()); | ||
Assert.assertEquals(Referee.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, finishGameMethod).get(0).getBeanClass()); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions
30
...ian/src/test/java/org/jboss/weld/tests/interceptors/generic/AbstractMessageProcessor.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,30 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* 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.jboss.weld.tests.interceptors.generic; | ||
|
||
/** | ||
* @author Marius Bogoevici | ||
*/ | ||
public abstract class AbstractMessageProcessor<I> | ||
{ | ||
void process(I input) { | ||
// do nothing; | ||
} | ||
|
||
abstract I generate(); | ||
} |
36 changes: 36 additions & 0 deletions
36
...-arquillian/src/test/java/org/jboss/weld/tests/interceptors/generic/IntegerProcessor.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,36 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* 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.jboss.weld.tests.interceptors.generic; | ||
|
||
/** | ||
* @author Marius Bogoevici | ||
*/ | ||
public class IntegerProcessor extends AbstractMessageProcessor<Integer> | ||
{ | ||
@Override | ||
void process(Integer input) | ||
{ | ||
super.process(input); //To change body of overridden methods use File | Settings | File Templates. | ||
} | ||
|
||
@Override | ||
Integer generate() | ||
{ | ||
return 1; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...quillian/src/test/java/org/jboss/weld/tests/interceptors/generic/SimpleWeldClassTest.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,67 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* 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.jboss.weld.tests.interceptors.generic; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.jboss.arquillian.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.jboss.weld.introspector.WeldClass; | ||
import org.jboss.weld.introspector.WeldMethod; | ||
import org.jboss.weld.introspector.jlr.WeldClassImpl; | ||
import org.jboss.weld.metadata.TypeStore; | ||
import org.jboss.weld.resources.ClassTransformer; | ||
import org.jboss.weld.tests.category.Broken; | ||
import org.jboss.weld.util.Beans; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* @author Marius Bogoevici | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class SimpleWeldClassTest | ||
{ | ||
@Deployment | ||
public static Archive<?> deploy() | ||
{ | ||
return ShrinkWrap.create(BeanArchive.class) | ||
.addPackage(SimpleWeldClassTest.class.getPackage()); | ||
} | ||
|
||
/* | ||
* description = "WELD-568" | ||
*/ | ||
@Category(Broken.class) | ||
@Test | ||
public void testWeldClassForGenericSuperclass() | ||
{ | ||
WeldClass<StringProcessor> weldClass = WeldClassImpl.of(StringProcessor.class, new ClassTransformer(new TypeStore())); | ||
Collection<WeldMethod<?, ?>> methods = weldClass.getWeldMethods(); | ||
//assert methods.size() == 2; | ||
List<WeldMethod<?,?>> interceptableMethods = Beans.getInterceptableMethods(weldClass); | ||
Assert.assertEquals(4, interceptableMethods.size()); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...s-arquillian/src/test/java/org/jboss/weld/tests/interceptors/generic/StringProcessor.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,36 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* 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.jboss.weld.tests.interceptors.generic; | ||
|
||
/** | ||
* @author Marius Bogoevici | ||
*/ | ||
public class StringProcessor extends AbstractMessageProcessor<String> | ||
{ | ||
@Override | ||
void process(String input) | ||
{ | ||
super.process(input); | ||
} | ||
|
||
@Override | ||
String generate() | ||
{ | ||
return "1"; | ||
} | ||
} |
Oops, something went wrong.