Feature/contitional test runner (#1132)

* FIX: warnings (add generics, overrides, fix imports) - should be no effecive code change

* replaced deprecated methods by default methods

* FIX: more compiler warnings

* FIX more warnings - no code changes

* FIX: deprecated call to JsonParseException

* Remove unused code, check unused variables

* ADD: ContitonaltestRunner to skip tests for certain platforms

* Use annotations to control on which platforms a test shoud run

* FIX: compile errors
This commit is contained in:
Roland Praml
2017-09-15 21:03:03 +12:00
committed by Rob Bygrave
parent f3e4696498
commit 8d334ff2e8
17 changed files with 176 additions and 76 deletions
+7 -1
View File
@@ -5,12 +5,14 @@ import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import org.tests.model.basic.Country;
import org.avaje.agentloader.AgentLoader;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Types;
public class BaseTestCase {
@RunWith(ConditionalTestRunner.class)
public abstract class BaseTestCase {
protected static Logger logger = LoggerFactory.getLogger(BaseTestCase.class);
@@ -75,6 +77,10 @@ public class BaseTestCase {
return Platform.ORACLE == platform();
}
public boolean isDb2() {
return Platform.DB2 == platform();
}
public boolean isPostgres() {
return Platform.POSTGRES == platform();
}
@@ -0,0 +1,48 @@
package io.ebean;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.IgnorePlatform;
/**
* This testrunner checks for an {@link IgnorePlatform} annotation and ignores the test.
*
* @author Roland Praml, FOCONIS AG
*/
public class ConditionalTestRunner extends BlockJUnit4ClassRunner {
public ConditionalTestRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override
public void runChild(FrameworkMethod method, RunNotifier notifier) {
ForPlatform forPlatform = method.getAnnotation(ForPlatform.class);
if (forPlatform != null) {
if (!platformMath(forPlatform.value())) {
notifier.fireTestIgnored(describeChild(method));
return;
}
}
IgnorePlatform ignore = method.getAnnotation(IgnorePlatform.class);
if (ignore == null || !platformMath(ignore.value())) {
super.runChild(method, notifier);
} else {
notifier.fireTestIgnored(describeChild(method));
}
}
private boolean platformMath(Platform[] platforms) {
Platform current = Ebean.getDefaultServer().getPluginApi().getDatabasePlatform().getPlatform();
for (Platform p : platforms) {
if (p.equals(current)) {
return true;
}
}
return false;
}
}
@@ -1,14 +1,15 @@
package io.ebean;
import io.ebean.PrimaryServer;
import org.junit.Ignore;
import io.ebean.annotation.ForPlatform;
import org.junit.Test;
import java.util.Properties;
import static org.junit.Assert.*;
public class PrimaryServerTest {
public class PrimaryServerTest extends BaseTestCase {
@Test
@@ -19,8 +20,8 @@ public class PrimaryServerTest {
assertFalse(PrimaryServer.isSkip());
}
@Ignore
@Test
@ForPlatform(Platform.H2)
public void testGetPrimaryServerName() throws Exception {
String primaryServerName = PrimaryServer.getDefaultServerName();
@@ -2,6 +2,9 @@ package io.ebean;
import org.tests.model.basic.Country;
import org.tests.model.basic.Customer;
import io.ebean.annotation.IgnorePlatform;
import org.junit.Test;
import java.sql.Timestamp;
@@ -30,6 +33,7 @@ public class UpdateQueryTest extends BaseTestCase {
}
@Test
@IgnorePlatform(Platform.SQLSERVER)
public void withTableAlias() {
EbeanServer server = server();
@@ -0,0 +1,17 @@
package io.ebean.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import io.ebean.Platform;
/**
* Annotation to run a test for a certain platform.
* @author Roland Praml, FOCONIS AG
*/
@Target(ElementType.METHOD )
@Retention(RetentionPolicy.RUNTIME)
public @interface ForPlatform {
Platform[] value();
}
@@ -0,0 +1,17 @@
package io.ebean.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import io.ebean.Platform;
/**
* Annotation to ignore a test for a certain platform.
* @author Roland Praml, FOCONIS AG
*/
@Target(ElementType.METHOD )
@Retention(RetentionPolicy.RUNTIME)
public @interface IgnorePlatform {
Platform[] value();
}
@@ -30,7 +30,7 @@ public class DefaultServerCache_RunEvictionTest {
this.cache = createCache();
}
@Ignore
@Ignore("test takes long time")
@Test
public void runEvict() throws InterruptedException {
@@ -6,7 +6,7 @@ import org.junit.Test;
public class DefaultBackgroundExecutorTest {
@Test
@Ignore
@Ignore("test takes long time")
public void shutdown_when_running_expect_waitAndNiceShutdown() throws Exception {
DefaultBackgroundExecutor es = new DefaultBackgroundExecutor(1, 20, "test");
@@ -19,7 +19,7 @@ public class DefaultBackgroundExecutorTest {
}
@Test
@Ignore
@Ignore("test takes long time")
public void shutdown_when_rougeRunnable_expect_InterruptedException() throws Exception {
DefaultBackgroundExecutor es = new DefaultBackgroundExecutor(1, 10, "test");