HHH-6841 - @SkipForDialects and @RequiresDialects
This commit is contained in:
parent
b7d545e778
commit
86ba2beb29
|
@ -34,6 +34,8 @@ import org.hibernate.dialect.Dialect;
|
|||
* Annotation used to indicate that a test should be run only when run against the
|
||||
* indicated dialects.
|
||||
*
|
||||
* @see RequiresDialects
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package org.hibernate.testing;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Plural annotation for {@link RequiresDialect}.
|
||||
* Useful when test needs to be run against more than one dialect because of a different reason.
|
||||
*
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
public @interface RequiresDialects {
|
||||
RequiresDialect[] value();
|
||||
}
|
|
@ -34,6 +34,8 @@ import org.hibernate.dialect.Dialect;
|
|||
* Annotation used to indicate that a test should be skipped when run against the
|
||||
* indicated dialects.
|
||||
*
|
||||
* @see SkipForDialects
|
||||
*
|
||||
* @author Hardy Ferentschik
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package org.hibernate.testing;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Plural annotation for {@link SkipForDialect}.
|
||||
* Useful when more than one dialect needs to be skipped because of a different reason.
|
||||
*
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
public @interface SkipForDialects {
|
||||
SkipForDialect[] value();
|
||||
}
|
|
@ -25,8 +25,10 @@ package org.hibernate.testing.junit4;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -44,8 +46,10 @@ import org.hibernate.testing.DialectCheck;
|
|||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.RequiresDialects;
|
||||
import org.hibernate.testing.Skip;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.SkipForDialects;
|
||||
|
||||
/**
|
||||
* The Hibernate-specific {@link org.junit.runner.Runner} implementation which layers {@link ExtendedFrameworkMethod}
|
||||
|
@ -151,7 +155,9 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
}
|
||||
|
||||
protected void sortMethods(List<FrameworkMethod> computedTestMethods) {
|
||||
if( CollectionHelper.isEmpty( computedTestMethods ))return;
|
||||
if ( CollectionHelper.isEmpty( computedTestMethods ) ) {
|
||||
return;
|
||||
}
|
||||
Collections.sort( computedTestMethods, new Comparator<FrameworkMethod>() {
|
||||
@Override
|
||||
public int compare(FrameworkMethod o1, FrameworkMethod o2) {
|
||||
|
@ -228,9 +234,10 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
}
|
||||
}
|
||||
|
||||
// @SkipForDialect
|
||||
SkipForDialect skipForDialectAnn = Helper.locateAnnotation( SkipForDialect.class, frameworkMethod, getTestClass() );
|
||||
if ( skipForDialectAnn != null ) {
|
||||
// @SkipForDialects & @SkipForDialect
|
||||
for ( SkipForDialect skipForDialectAnn : Helper.collectAnnotations(
|
||||
SkipForDialect.class, SkipForDialects.class, frameworkMethod, getTestClass()
|
||||
) ) {
|
||||
for ( Class<? extends Dialect> dialectClass : skipForDialectAnn.value() ) {
|
||||
if ( skipForDialectAnn.strictMatching() ) {
|
||||
if ( dialectClass.equals( dialect.getClass() ) ) {
|
||||
|
@ -245,9 +252,10 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
|
|||
}
|
||||
}
|
||||
|
||||
// @RequiresDialect
|
||||
RequiresDialect requiresDialectAnn = Helper.locateAnnotation( RequiresDialect.class, frameworkMethod, getTestClass() );
|
||||
if ( requiresDialectAnn != null ) {
|
||||
// @RequiresDialects & @RequiresDialect
|
||||
for ( RequiresDialect requiresDialectAnn : Helper.collectAnnotations(
|
||||
RequiresDialect.class, RequiresDialects.class, frameworkMethod, getTestClass()
|
||||
) ) {
|
||||
boolean foundMatch = false;
|
||||
for ( Class<? extends Dialect> dialectClass : requiresDialectAnn.value() ) {
|
||||
foundMatch = requiresDialectAnn.strictMatching()
|
||||
|
|
|
@ -25,6 +25,9 @@ package org.hibernate.testing.junit4;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
|
@ -33,6 +36,8 @@ import org.junit.runners.model.TestClass;
|
|||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.SkipForDialects;
|
||||
|
||||
/**
|
||||
* Centralized utility functionality
|
||||
|
@ -84,6 +89,38 @@ public class Helper {
|
|||
return annotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param singularAnnotationClass Singular annotation class (e.g. {@link SkipForDialect}).
|
||||
* @param pluralAnnotationClass Plural annotation class (e.g. {@link SkipForDialects}). Assuming that the only
|
||||
* declared method is an array of singular annotations.
|
||||
* @param frameworkMethod Test method.
|
||||
* @param testClass Test class.
|
||||
* @param <S> Singular annotation type.
|
||||
* @param <P> Plural annotation type.
|
||||
* @return Collection of all singular annotations or an empty list.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <S extends Annotation, P extends Annotation> List<S> collectAnnotations(Class<S> singularAnnotationClass,
|
||||
Class<P> pluralAnnotationClass,
|
||||
FrameworkMethod frameworkMethod,
|
||||
TestClass testClass) {
|
||||
final List<S> collection = new LinkedList<S>();
|
||||
final S singularAnn = Helper.locateAnnotation( singularAnnotationClass, frameworkMethod, testClass );
|
||||
if ( singularAnn != null ) {
|
||||
collection.add( singularAnn );
|
||||
}
|
||||
final P pluralAnn = Helper.locateAnnotation( pluralAnnotationClass, frameworkMethod, testClass );
|
||||
if ( pluralAnn != null ) {
|
||||
try {
|
||||
collection.addAll( Arrays.asList( (S[]) pluralAnnotationClass.getDeclaredMethods()[0].invoke(pluralAnn) ) );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static String extractMessage(FailureExpected failureExpected) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append( '(' ).append( failureExpected.jiraKey() ).append( ')' );
|
||||
|
|
Loading…
Reference in New Issue