diff --git a/ebean-ddl-generator/src/test/java/io/ebean/BaseTestCase.java b/ebean-ddl-generator/src/test/java/io/ebean/BaseTestCase.java index 66189f3c0..223598f91 100644 --- a/ebean-ddl-generator/src/test/java/io/ebean/BaseTestCase.java +++ b/ebean-ddl-generator/src/test/java/io/ebean/BaseTestCase.java @@ -28,20 +28,6 @@ public abstract class BaseTestCase { protected static Logger logger = LoggerFactory.getLogger(BaseTestCase.class); -// @Rule public TestName name = new TestName(); -// -// @After -// public void checkForLeak() { -// TransactionScopeManager scope = spiEbeanServer().getTransactionManager().scope(); -// SpiTransaction trans = scope.getInScope(); -// if (trans != null) { -// String msg = getClass().getSimpleName() + "." + name.getMethodName() + " did not clear threadScope:" + trans; -// scope.clearExternal(); // clear for next test -// fail(msg); -// } -// } - - /** * this is the clock delta that may occur between testing machine and db server. * If the clock delta of DB server is in future, an "asOf" query may not find the @@ -68,99 +54,6 @@ public abstract class BaseTestCase { } } - protected void clearAllL2Cache() { - server().cacheManager().clearAll(); - } - - protected void resetAllMetrics() { - server().metaInfo().resetAllMetrics(); - } - - protected ServerMetrics collectMetrics() { - return server().metaInfo().collectMetrics(); - } - - protected List visitTimedMetrics() { - return collectMetrics().timedMetrics(); - } - - protected List sqlMetrics() { - List timedMetrics = visitTimedMetrics(); - - return timedMetrics.stream() - .filter((it) -> it.name().startsWith("sql.") || it.name().startsWith("orm.")) - .collect(Collectors.toList()); - } - - protected SpiTransaction getInScopeTransaction() { - return spiEbeanServer().transactionManager().scope().getInScope(); - } - - /** - * Return the generated sql trimming column alias if required. - */ - protected String sqlOf(Query query) { - return trimSql(query.getGeneratedSql()); - } - - /** - * Return the generated sql trimming column alias if required. - */ - protected String sqlOf(Query query, int columns) { - return trimSql(query.getGeneratedSql(), columns); - } - - protected void assertSqlBind(String sql) { - assertThat(sql).contains("-- bind"); - } - - protected void assertSqlBind(List sql, int i) { - assertThat(sql.get(i)).contains("-- bind"); - } - - protected void assertSqlBind(List sql, int from, int to) { - for (int i = from; i <= to; i++) { - assertThat(sql.get(i)).contains("-- bind"); - } - } - - protected AbstractCharSequenceAssert assertSql(Query query, int count) { - return org.assertj.core.api.Assertions.assertThat(sqlOf(query, count)); - } - - protected AbstractCharSequenceAssert assertSql(Query query) { - return org.assertj.core.api.Assertions.assertThat(sqlOf(query)); - } - - protected AbstractCharSequenceAssert assertSql(String sql) { - return org.assertj.core.api.Assertions.assertThat(trimSql(sql)); - } - - protected String trimSql(String sql) { - if (sql.contains(" c0,") || sql.contains(" c0 ") || sql.contains(" c1,") || sql.contains(" c1 ")) { - // for oracle we include column alias so lets remove those - return trimSql(sql, 10); - } - return sql;//trimSql(sql, 0); - } - - /** - * Trim out column alias if required from the generated sql. - */ - protected String trimSql(String sql, int columns) { - for (int i = 0; i <= columns; i++) { - sql = StringHelper.replace(sql, " c" + i + ",", ","); - } - for (int i = 0; i <= columns; i++) { - sql = StringHelper.replace(sql, " c" + i + " ", " "); - } - return sql; - } - - public boolean isPlatformCaseSensitive() { - return spiEbeanServer().databasePlatform().isCaseSensitiveCollation(); - } - /** * MS SQL Server does not allow setting explicit values on identity columns * so tests that do this need to be skipped for SQL Server. @@ -173,22 +66,10 @@ public abstract class BaseTestCase { return Platform.H2 == platform(); } - public boolean isHSqlDb() { - return Platform.HSQLDB == platform(); - } - public boolean isOracle() { return Platform.ORACLE == platform(); } - public boolean isNuoDb() { - return Platform.NUODB == platform(); - } - - public boolean isDb2() { - return Platform.DB2 == platform(); - } - public boolean isPostgres() { return Platform.POSTGRES == platform().base(); } @@ -228,22 +109,10 @@ public abstract class BaseTestCase { // do nothing, used to thread sleep } - protected BeanDescriptor getBeanDescriptor(Class cls) { - return spiEbeanServer().descriptor(cls); - } - - protected ServerCacheStatistics getBeanCacheStats(Class cls, boolean reset) { - return server().cacheManager().beanCache(cls).statistics(reset); - } - protected Platform platform() { return spiEbeanServer().databasePlatform().getPlatform().base(); } - protected IdType idType() { - return spiEbeanServer().databasePlatform().getDbIdentity().getIdType(); - } - protected SpiEbeanServer spiEbeanServer() { return (SpiEbeanServer) DB.getDefault(); } @@ -252,39 +121,4 @@ public abstract class BaseTestCase { return DB.getDefault(); } - /** - * Platform specific IN clause assert. - */ - protected void platformAssertIn(String sql, String containsIn) { - if (isPostgres()) { - assertThat(sql).contains(containsIn+" = any("); - } else { - assertThat(sql).contains(containsIn+" in "); - } - // H2 contains("where t0.name in (select * from table(x varchar = ?)"); - } - - /** - * Platform specific NOT IN clause assert. - */ - protected void platformAssertNotIn(String sql, String containsIn) { - if (isPostgres()) { - assertThat(sql).contains(containsIn+" != all("); - } else { - assertThat(sql).contains(containsIn+" not in "); - } - } - - /** - * Platform specific CONCAT clause. - */ - protected String concat(String property0, String separator, String property1) { - return concat(property0, separator, property1, null); - } - - protected String concat(String property0, String separator, String property1, String suffix) { - DbExpressionHandler dbExpressionHandler = DbExpressionHandlerFactory.from(spiEbeanServer().databasePlatform()); - return dbExpressionHandler.concat(property0, separator, property1, suffix); - } - }