You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2011/03/29 02:15:06 UTC
svn commit: r1086449 - in /openejb/trunk/openejb3/container/openejb-core/src:
main/java/org/apache/openejb/config/ test/java/org/apache/openejb/config/
test/java/org/apache/openejb/core/stateless/
test/java/org/apache/openejb/interceptors/ test/java/or...
Author: dblevins
Date: Tue Mar 29 00:15:05 2011
New Revision: 1086449
URL: http://svn.apache.org/viewvc?rev=1086449&view=rev
Log:
OPENEJB-1453: Metatyping for EJB and Dependency Injection Annotations
Sort the processing of interceptor annotations and callbacks
"isValidEjbAnnotationUsage" is now properly meta-annotation aware
Async method processing now meta-aware
Added:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/test/util/
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/test/util/Asserts.java (with props)
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/interceptors/FullyInterceptedTest.java
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1086449&r1=1086448&r2=1086449&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Tue Mar 29 00:15:05 2011
@@ -29,6 +29,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -459,7 +460,7 @@ public class AnnotationDeployer implemen
Singleton singleton = beanClass.getAnnotation(Singleton.class);
String ejbName = getEjbName(singleton, beanClass.get());
- if (!isValidEjbAnnotationUsage(Singleton.class, beanClass.get(), ejbName, ejbModule)) continue;
+ if (!isValidEjbAnnotationUsage(Singleton.class, beanClass, ejbName, ejbModule)) continue;
EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
if (enterpriseBean == null) {
@@ -485,7 +486,7 @@ public class AnnotationDeployer implemen
Stateless stateless = beanClass.getAnnotation(Stateless.class);
String ejbName = getEjbName(stateless, beanClass.get());
- if (!isValidEjbAnnotationUsage(Stateless.class, beanClass.get(), ejbName, ejbModule)) continue;
+ if (!isValidEjbAnnotationUsage(Stateless.class, beanClass, ejbName, ejbModule)) continue;
EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
if (enterpriseBean == null) {
@@ -511,7 +512,7 @@ public class AnnotationDeployer implemen
Stateful stateful = beanClass.getAnnotation(Stateful.class);
String ejbName = getEjbName(stateful, beanClass.get());
- if (!isValidEjbAnnotationUsage(Stateful.class, beanClass.get(), ejbName, ejbModule)) continue;
+ if (!isValidEjbAnnotationUsage(Stateful.class, beanClass, ejbName, ejbModule)) continue;
EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
if (enterpriseBean == null) {
@@ -540,7 +541,7 @@ public class AnnotationDeployer implemen
// TODO: this is actually against the spec, but the requirement is rather silly
// (allowing @Stateful and @ManagedBean on the same class)
// If the TCK doesn't complain we should discourage it
- if (!isValidEjbAnnotationUsage(ManagedBean.class, beanClass.get(), ejbName, ejbModule)) continue;
+ if (!isValidEjbAnnotationUsage(ManagedBean.class, beanClass, ejbName, ejbModule)) continue;
EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
if (enterpriseBean == null) {
@@ -556,10 +557,9 @@ public class AnnotationDeployer implemen
}
}
- List<Class<?>> classes = finder.findAnnotatedClasses(MessageDriven.class);
- for (Class<?> beanClass : classes) {
+ for (Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(MessageDriven.class)) {
MessageDriven mdb = beanClass.getAnnotation(MessageDriven.class);
- String ejbName = getEjbName(mdb, beanClass);
+ String ejbName = getEjbName(mdb, beanClass.get());
if (!isValidEjbAnnotationUsage(MessageDriven.class, beanClass, ejbName, ejbModule)) continue;
@@ -567,11 +567,11 @@ public class AnnotationDeployer implemen
if (messageBean == null) {
messageBean = new MessageDrivenBean(ejbName);
ejbJar.addEnterpriseBean(messageBean);
- LegacyProcessor.process(beanClass, messageBean);
+ LegacyProcessor.process(beanClass.get(), messageBean);
}
if (messageBean.getEjbClass() == null) {
- messageBean.setEjbClass(beanClass.getName());
- LegacyProcessor.process(beanClass, messageBean);
+ messageBean.setEjbClass(beanClass.get());
+ LegacyProcessor.process(beanClass.get(), messageBean);
}
}
@@ -622,7 +622,7 @@ public class AnnotationDeployer implemen
return ejbName;
}
- private boolean isValidEjbAnnotationUsage(Class annotationClass, Class<?> beanClass, String ejbName, EjbModule ejbModule) {
+ private boolean isValidEjbAnnotationUsage(Class annotationClass, Annotated<Class<?>> beanClass, String ejbName, EjbModule ejbModule) {
List<Class<? extends Annotation>> annotations = new ArrayList(asList(Singleton.class, Stateless.class, Stateful.class, MessageDriven.class));
annotations.remove(annotationClass);
@@ -634,27 +634,27 @@ public class AnnotationDeployer implemen
String secondEjbName = null;
if (annotation instanceof Stateful) {
- secondEjbName = getEjbName((Stateful) annotation, beanClass);
+ secondEjbName = getEjbName((Stateful) annotation, beanClass.get());
} else if (annotation instanceof Stateless) {
- secondEjbName = getEjbName((Stateless) annotation, beanClass);
+ secondEjbName = getEjbName((Stateless) annotation, beanClass.get());
} else if (annotation instanceof Singleton) {
- secondEjbName = getEjbName((Singleton) annotation, beanClass);
+ secondEjbName = getEjbName((Singleton) annotation, beanClass.get());
} else if (annotation instanceof MessageDriven) {
- secondEjbName = getEjbName((MessageDriven) annotation, beanClass);
+ secondEjbName = getEjbName((MessageDriven) annotation, beanClass.get());
}
if (ejbName.equals(secondEjbName)) {
- ejbModule.getValidation().fail(ejbName, "multiplyAnnotatedAsBean", annotationClass.getSimpleName(), secondAnnotation.getSimpleName(), ejbName, beanClass.getName());
+ ejbModule.getValidation().fail(ejbName, "multiplyAnnotatedAsBean", annotationClass.getSimpleName(), secondAnnotation.getSimpleName(), ejbName, beanClass.get().getName());
}
}
- if (beanClass.isInterface()) {
- ejbModule.getValidation().fail(ejbName, "interfaceAnnotatedAsBean", annotationClass.getSimpleName(), beanClass.getName());
+ if (beanClass.get().isInterface()) {
+ ejbModule.getValidation().fail(ejbName, "interfaceAnnotatedAsBean", annotationClass.getSimpleName(), beanClass.get().getName());
return false;
}
- if (isAbstract(beanClass.getModifiers())) {
- ejbModule.getValidation().fail(ejbName, "abstractAnnotatedAsBean", annotationClass.getSimpleName(), beanClass.getName());
+ if (isAbstract(beanClass.get().getModifiers())) {
+ ejbModule.getValidation().fail(ejbName, "abstractAnnotatedAsBean", annotationClass.getSimpleName(), beanClass.get().getName());
return false;
}
@@ -1165,7 +1165,7 @@ public class AnnotationDeployer implemen
/*
* @Interceptors
*/
- for (Annotated<Class<?>> interceptorsAnnotatedClass : annotationFinder.findMetaAnnotatedClasses(Interceptors.class)) {
+ for (Annotated<Class<?>> interceptorsAnnotatedClass : sortClasses(annotationFinder.findMetaAnnotatedClasses(Interceptors.class))) {
Interceptors interceptors = interceptorsAnnotatedClass.getAnnotation(Interceptors.class);
EjbJar ejbJar = ejbModule.getEjbJar();
for (Class interceptor : interceptors.value()) {
@@ -1182,7 +1182,7 @@ public class AnnotationDeployer implemen
}
}
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(Interceptors.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(Interceptors.class))) {
Interceptors interceptors = method.getAnnotation(Interceptors.class);
if (interceptors != null) {
EjbJar ejbJar = ejbModule.getEjbJar();
@@ -1224,7 +1224,7 @@ public class AnnotationDeployer implemen
binding.setExcludeClassInterceptors(true);
}
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(ExcludeClassInterceptors.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(ExcludeClassInterceptors.class))) {
InterceptorBinding binding = assemblyDescriptor.addInterceptorBinding(new InterceptorBinding(bean));
binding.setExcludeClassInterceptors(true);
binding.setMethod(new NamedMethod(method.get()));
@@ -1575,19 +1575,16 @@ public class AnnotationDeployer implemen
SessionBean sessionBean = (SessionBean) bean;
- List<Method> asyncMethods = annotationFinder.findAnnotatedMethods(Asynchronous.class);
- for (Method method : asyncMethods) {
- sessionBean.getAsyncMethod().add(new AsyncMethod(method));
+ for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(Asynchronous.class)) {
+ sessionBean.getAsyncMethod().add(new AsyncMethod(method.get()));
}
- List<Class<?>> clses = annotationFinder.findAnnotatedClasses(Asynchronous.class);
-
//Spec 4.5.1 @Asynchronous could be used at the class level of a bean-class ( or superclass ).
//Seems that it should not be used on the any interface view
- for (Class<?> cls : clses) {
- if (!cls.isInterface()) {
- sessionBean.getAsynchronousClasses().add(cls.getName());
+ for (Annotated<Class<?>> clazz : annotationFinder.findMetaAnnotatedClasses(Asynchronous.class)) {
+ if (!clazz.get().isInterface()) {
+ sessionBean.getAsynchronousClasses().add(clazz.get().getName());
}
}
}
@@ -2199,7 +2196,7 @@ public class AnnotationDeployer implemen
* @PostConstruct
*/
if (apply(override, bean.getPostConstruct())) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(PostConstruct.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(PostConstruct.class))) {
bean.getPostConstruct().add(new LifecycleCallback(method.get()));
}
}
@@ -2208,7 +2205,7 @@ public class AnnotationDeployer implemen
* @PreDestroy
*/
if (apply(override, bean.getPreDestroy())) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(PreDestroy.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(PreDestroy.class))) {
bean.getPreDestroy().add(new LifecycleCallback(method.get()));
}
}
@@ -2220,7 +2217,7 @@ public class AnnotationDeployer implemen
* @AroundInvoke
*/
if (apply(override, invokable.getAroundInvoke())) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(javax.interceptor.AroundInvoke.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(javax.interceptor.AroundInvoke.class))) {
invokable.getAroundInvoke().add(new AroundInvoke(method.get()));
}
}
@@ -2229,7 +2226,7 @@ public class AnnotationDeployer implemen
* @AroundTimeout
*/
if (apply(override, invokable.getAroundInvoke())) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(javax.interceptor.AroundTimeout.class)) {
+ for (Annotated<Method> method : sortMethods((annotationFinder.findMetaAnnotatedMethods(javax.interceptor.AroundTimeout.class)))) {
invokable.getAroundTimeout().add(new AroundTimeout(method.get()));
}
}
@@ -2241,10 +2238,10 @@ public class AnnotationDeployer implemen
if (bean instanceof TimerConsumer) {
TimerConsumer timerConsumer = (TimerConsumer) bean;
if (timerConsumer.getTimeoutMethod() == null) {
- List<Method> timeoutMethods = annotationFinder.findAnnotatedMethods(javax.ejb.Timeout.class);
+ List<Annotated<Method>> timeoutMethods = annotationFinder.findMetaAnnotatedMethods(javax.ejb.Timeout.class);
//Validation Logic is moved to CheckCallback class.
if(timeoutMethods.size() == 1){
- timerConsumer.setTimeoutMethod(new NamedMethod(timeoutMethods.get(0)));
+ timerConsumer.setTimeoutMethod(new NamedMethod(timeoutMethods.get(0).get()));
}
}
}
@@ -2257,7 +2254,7 @@ public class AnnotationDeployer implemen
*/
LifecycleCallback afterBegin = getFirst(session.getAfterBegin());
if (afterBegin == null) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(AfterBegin.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(AfterBegin.class))) {
session.getAfterBegin().add(new LifecycleCallback(method.get()));
}
}
@@ -2267,7 +2264,7 @@ public class AnnotationDeployer implemen
*/
LifecycleCallback beforeCompletion = getFirst(session.getBeforeCompletion());
if (beforeCompletion == null) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(BeforeCompletion.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(BeforeCompletion.class))) {
session.getBeforeCompletion().add(new LifecycleCallback(method.get()));
}
}
@@ -2277,7 +2274,7 @@ public class AnnotationDeployer implemen
*/
LifecycleCallback afterCompletion = getFirst(session.getAfterCompletion());
if (afterCompletion == null) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(AfterCompletion.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(AfterCompletion.class))) {
session.getAfterCompletion().add(new LifecycleCallback(method.get()));
}
}
@@ -2286,7 +2283,7 @@ public class AnnotationDeployer implemen
* @PostActivate
*/
if (apply(override, session.getPostActivate())) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(PostActivate.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(PostActivate.class))) {
session.getPostActivate().add(new LifecycleCallback(method.get()));
}
}
@@ -2295,16 +2292,15 @@ public class AnnotationDeployer implemen
* @PrePassivate
*/
if (apply(override, session.getPrePassivate())) {
- for (Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(PrePassivate.class)) {
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(PrePassivate.class))) {
session.getPrePassivate().add(new LifecycleCallback(method.get()));
}
}
/*
* @Init
*/
- List<Method> initMethods = annotationFinder.findAnnotatedMethods(Init.class);
- for (Method method : initMethods) {
- InitMethod initMethod = new InitMethod(method);
+ for (Annotated<Method> method : sortMethods(annotationFinder.findMetaAnnotatedMethods(Init.class))) {
+ InitMethod initMethod = new InitMethod(method.get());
Init init = method.getAnnotation(Init.class);
if (init.value() != null && !init.value().equals("")) {
@@ -2317,14 +2313,14 @@ public class AnnotationDeployer implemen
/*
* @Remove
*/
- List<Method> removeMethods = annotationFinder.findAnnotatedMethods(Remove.class);
+ List<Annotated<Method>> removeMethods = sortMethods(annotationFinder.findMetaAnnotatedMethods(Remove.class));
Map<NamedMethod, RemoveMethod> declaredRemoveMethods = new HashMap<NamedMethod, RemoveMethod>();
for (RemoveMethod removeMethod : session.getRemoveMethod()) {
declaredRemoveMethods.put(removeMethod.getBeanMethod(), removeMethod);
}
- for (Method method : removeMethods) {
+ for (Annotated<Method> method : removeMethods) {
Remove remove = method.getAnnotation(Remove.class);
- RemoveMethod removeMethod = new RemoveMethod(method, remove.retainIfException());
+ RemoveMethod removeMethod = new RemoveMethod(method.get(), remove.retainIfException());
RemoveMethod declaredRemoveMethod = declaredRemoveMethods.get(removeMethod.getBeanMethod());
@@ -3607,8 +3603,6 @@ public class AnnotationDeployer implemen
parents.addAll(ancestors(clazz));
}
- Collections.reverse(parents);
-
return new AnnotationFinder(new ClassesArchive(parents)).link();
}
@@ -3797,4 +3791,31 @@ public class AnnotationDeployer implemen
}
}
+ public static List<Annotated<Class<?>>> sortClasses(List<Annotated<Class<?>>> list) {
+ Collections.sort(list, new Comparator<Annotated<Class<?>>>() {
+ @Override
+ public int compare(Annotated<Class<?>> o1, Annotated<Class<?>> o2) {
+ return compareClasses(o1.get(), o2.get());
+ }
+ });
+ return list;
+ }
+
+ public static List<Annotated<Method>> sortMethods(List<Annotated<Method>> list) {
+ Collections.sort(list, new Comparator<Annotated<Method>>() {
+ @Override
+ public int compare(Annotated<Method> o1, Annotated<Method> o2) {
+ return compareClasses(o1.get().getDeclaringClass(), o2.get().getDeclaringClass());
+ }
+ });
+ return list;
+ }
+
+ private static int compareClasses(Class<?> a, Class<?> b) {
+ if (a == b) return 0;
+ if (a.isAssignableFrom(b)) return 1;
+ if (b.isAssignableFrom(a)) return -1;
+
+ return 0;
+ }
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java?rev=1086449&r1=1086448&r2=1086449&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java Tue Mar 29 00:15:05 2011
@@ -24,18 +24,24 @@ import org.apache.openejb.jee.AssemblyDe
import org.apache.openejb.jee.EjbJar;
import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.*;
import org.apache.openejb.jee.EnterpriseBean;
import org.apache.openejb.jee.SessionBean;
+import org.apache.xbean.finder.Annotated;
+import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.ClassFinder;
+import org.apache.xbean.finder.archive.ClassesArchive;
import org.junit.Assert;
import org.junit.Test;
+import javax.annotation.Resource;
import javax.ejb.ApplicationException;
import javax.ejb.Local;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
+import java.lang.reflect.Method;
+import java.util.List;
/**
* @version $Rev$ $Date$
@@ -78,6 +84,39 @@ public class AnnotationDeployerTest {
return ejbModule;
}
+
+ @Test
+ public void testSortClasses() throws Exception {
+ AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link();
+
+ List<Annotated<Class<?>>> classes = finder.findMetaAnnotatedClasses(Resource.class);
+ assertTrue(classes.size() >= 3);
+
+ List<Annotated<Class<?>>> sorted = AnnotationDeployer.sortClasses(classes);
+
+ assertTrue(sorted.size() >= 3);
+
+ assertEquals(Emerald.class, sorted.get(0).get());
+ assertEquals(Green.class, sorted.get(1).get());
+ assertEquals(Color.class, sorted.get(2).get());
+ }
+
+ @Test
+ public void testSortMethods() throws Exception {
+ AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link();
+
+ List<Annotated<Method>> classes = finder.findMetaAnnotatedMethods(Resource.class);
+ assertTrue(classes.size() >= 3);
+
+ List<Annotated<Method>> sorted = AnnotationDeployer.sortMethods(classes);
+
+ assertTrue(sorted.size() >= 3);
+
+ assertEquals(Emerald.class, sorted.get(0).get().getDeclaringClass());
+ assertEquals(Green.class, sorted.get(1).get().getDeclaringClass());
+ assertEquals(Color.class, sorted.get(2).get().getDeclaringClass());
+ }
+
@Test
/**
* For https://issues.apache.org/jira/browse/OPENEJB-1063
@@ -176,4 +215,22 @@ public class AnnotationDeployerTest {
}
}
+ @Resource
+ public static class Color {
+ @Resource
+ public void color(){}
+ }
+
+ @Resource
+ public static class Green extends Color {
+ @Resource
+ public void green(){}
+ }
+
+ @Resource
+ public static class Emerald extends Green {
+ @Resource
+ public void emerald(){}
+ }
+
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java?rev=1086449&r1=1086448&r2=1086449&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java Tue Mar 29 00:15:05 2011
@@ -26,6 +26,7 @@ import org.apache.openejb.config.Configu
import org.apache.openejb.core.ivm.naming.InitContextFactory;
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.test.util.Asserts;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
@@ -187,28 +188,11 @@ public class StatelessPoolStatsTest exte
}
public static void assertEquals(List<?> expectedList, List<?> actualList) {
- final Iterator<?> expected = expectedList.iterator();
- final Iterator<?> actual = actualList.iterator();
-
- while(expected.hasNext() && actual.hasNext()) {
- assertEquals(expected.next(), actual.next());
- }
-
- assertEquals(expected.hasNext(), actual.hasNext());
+ Asserts.assertEquals(expectedList, actualList);
}
public static void assertEquals(Map<?,?> expectedMap, Map<?,?> actualMap) {
- final Iterator<? extends Map.Entry<?, ?>> expectedIt = expectedMap.entrySet().iterator();
- final Iterator<? extends Map.Entry<?, ?>> actualIt = actualMap.entrySet().iterator();
-
- while (expectedIt.hasNext() && actualIt.hasNext()) {
- final Map.Entry<?, ?> expected = expectedIt.next();
- final Map.Entry<?, ?> actual = actualIt.next();
- assertEquals("key", expected.getKey(), actual.getKey());
- assertEquals(expected.getKey().toString(), expected.getValue(), actual.getValue());
- }
-
- assertEquals(expectedIt.hasNext(), actualIt.hasNext());
+ Asserts.assertEquals(expectedMap, actualMap);
}
/**
Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/interceptors/FullyInterceptedTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/interceptors/FullyInterceptedTest.java?rev=1086449&r1=1086448&r2=1086449&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/interceptors/FullyInterceptedTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/interceptors/FullyInterceptedTest.java Tue Mar 29 00:15:05 2011
@@ -25,6 +25,7 @@ import org.apache.openejb.jee.NamedMetho
import org.apache.openejb.jee.StatelessBean;
import org.apache.openejb.junit.ApplicationComposer;
import org.apache.openejb.junit.Module;
+import org.apache.openejb.test.util.Asserts;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -77,7 +78,7 @@ public class FullyInterceptedTest extend
expected.add("businessMethod");
List<String> actual = fullyIntercepted.businessMethod();
- assert expected.equals(actual) : "Expected " + expected + ", but got " + actual;
+ Asserts.assertEquals(expected, actual);
}
@Test
@@ -95,6 +96,6 @@ public class FullyInterceptedTest extend
expected.add("methodWithDefaultInterceptorsExcluded");
List<String> actual = fullyIntercepted.methodWithDefaultInterceptorsExcluded();
- assert expected.equals(actual) : "Expected " + expected + ", but got " + actual;
+ Asserts.assertEquals(expected, actual);
}
}
Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/test/util/Asserts.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/test/util/Asserts.java?rev=1086449&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/test/util/Asserts.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/test/util/Asserts.java Tue Mar 29 00:15:05 2011
@@ -0,0 +1,53 @@
+/**
+ * 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.openejb.test.util;
+
+import junit.framework.Assert;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Asserts {
+ public static void assertEquals(Iterable<?> expectedList, Iterable<?> actualList) {
+ final Iterator<?> expected = expectedList.iterator();
+ final Iterator<?> actual = actualList.iterator();
+
+ while (expected.hasNext() && actual.hasNext()) {
+ Assert.assertEquals(expected.next(), actual.next());
+ }
+
+ Assert.assertEquals(expected.hasNext(), actual.hasNext());
+ }
+
+ public static void assertEquals(Map<?, ?> expectedMap, Map<?, ?> actualMap) {
+ final Iterator<? extends Map.Entry<?, ?>> expectedIt = expectedMap.entrySet().iterator();
+ final Iterator<? extends Map.Entry<?, ?>> actualIt = actualMap.entrySet().iterator();
+
+ while (expectedIt.hasNext() && actualIt.hasNext()) {
+ final Map.Entry<?, ?> expected = expectedIt.next();
+ final Map.Entry<?, ?> actual = actualIt.next();
+ Assert.assertEquals("key", expected.getKey(), actual.getKey());
+ Assert.assertEquals(expected.getKey().toString(), expected.getValue(), actual.getValue());
+ }
+
+ Assert.assertEquals(expectedIt.hasNext(), actualIt.hasNext());
+ }
+
+}
Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/test/util/Asserts.java
------------------------------------------------------------------------------
svn:eol-style = native