mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Tidy tests for ServerConfig -> DatabaseConfig
This commit is contained in:
@@ -36,7 +36,7 @@ public class EbeanServerFactory_ServerConfigStart_Test {
|
||||
|
||||
assertThat(db).isNotNull();
|
||||
|
||||
// test server shutdown and restart using the same ServerConfig
|
||||
// test server shutdown and restart using the same DatabaseConfig
|
||||
db.shutdown(true, false);
|
||||
|
||||
Database restartedServer = DatabaseFactory.create(config);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ServerConfigSqlServerTest {
|
||||
assertThat(sqlServer).isNotNull();
|
||||
sqlServer.shutdown();
|
||||
|
||||
// javax.persistence.PersistenceException: java.lang.IllegalArgumentException: For SqlServer please choose the more specific sqlserver16 or sqlserver17 platform via ServerConfig.setDatabasePlatformName. Refer to issue #1340 for details
|
||||
// javax.persistence.PersistenceException: java.lang.IllegalArgumentException: For SqlServer please choose the more specific sqlserver16 or sqlserver17 platform via DatabaseConfig.setDatabasePlatformName. Refer to issue #1340 for details
|
||||
//
|
||||
// at io.ebeaninternal.server.core.DatabasePlatformFactory.create(DatabasePlatformFactory.java:62)
|
||||
// at io.ebeaninternal.server.core.DefaultContainer.setDatabasePlatform(DefaultContainer.java:266)
|
||||
@@ -50,7 +50,6 @@ public class ServerConfigSqlServerTest {
|
||||
// at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:45)
|
||||
// at io.ebean.EbeanServerFactory.createInternal(EbeanServerFactory.java:109)
|
||||
// at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:70)
|
||||
// at io.ebean.config.ServerConfigSqlServerTest.need_explicitPlatform(ServerConfigSqlServerTest.java:35)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.MatchingNamingConvention;
|
||||
import io.ebean.config.PlatformConfig;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
|
||||
@@ -55,33 +55,32 @@ public class DatabasePlatformTest extends BaseTestCase {
|
||||
@Test
|
||||
public void convertQuotedIdentifiers_when_allQuotedIdentifier_sqlServer() {
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setAllQuotedIdentifiers(true);
|
||||
config.setNamingConvention(new MatchingNamingConvention());
|
||||
|
||||
DatabasePlatform dbPlatform = new SqlServer17Platform();
|
||||
dbPlatform.configure(config.getPlatformConfig(), config.isAllQuotedIdentifiers());
|
||||
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("order"),"[order]");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("`order`"),"[order]");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("firstName"),"[firstName]");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("order"), "[order]");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("`order`"), "[order]");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("firstName"), "[firstName]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertQuotedIdentifiers() {
|
||||
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
|
||||
DatabasePlatform dbPlatform = new SqlServer17Platform();
|
||||
dbPlatform.configure(config.getPlatformConfig(), config.isAllQuotedIdentifiers());
|
||||
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("order"),"order");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("`order`"),"[order]");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("firstName"),"firstName");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("order"), "order");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("`order`"), "[order]");
|
||||
assertEquals(dbPlatform.convertQuotedIdentifiers("firstName"), "firstName");
|
||||
|
||||
assertEquals(dbPlatform.unQuote("order"),"order");
|
||||
assertEquals(dbPlatform.unQuote("[order]"),"order");
|
||||
assertEquals(dbPlatform.unQuote("[firstName]"),"firstName");
|
||||
assertEquals(dbPlatform.unQuote("order"), "order");
|
||||
assertEquals(dbPlatform.unQuote("[order]"), "order");
|
||||
assertEquals(dbPlatform.unQuote("[firstName]"), "firstName");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+16
-19
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.cache;
|
||||
import io.ebean.cache.ServerCacheFactory;
|
||||
import io.ebean.cache.ServerCacheOptions;
|
||||
import io.ebean.cache.ServerCacheType;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebeaninternal.server.transaction.TableModState;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
@@ -14,13 +14,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DefaultCacheHolderTest {
|
||||
|
||||
private ThreadLocal<String> tenantId = new ThreadLocal<>();
|
||||
private final ThreadLocal<String> tenantId = new ThreadLocal<>();
|
||||
|
||||
private final ServerCacheFactory cacheFactory = new DefaultServerCacheFactory();
|
||||
private final ServerCacheOptions defaultOptions = new ServerCacheOptions();
|
||||
|
||||
private CacheManagerOptions options() {
|
||||
return new CacheManagerOptions(null, new ServerConfig(), true)
|
||||
return new CacheManagerOptions(null, new DatabaseConfig(), true)
|
||||
.with(defaultOptions, defaultOptions)
|
||||
.with(cacheFactory, new TableModState());
|
||||
}
|
||||
@@ -82,25 +82,22 @@ public class DefaultCacheHolderTest {
|
||||
assertThat(cache.get("1")).isEqualTo("value-for-tenant1");
|
||||
assertThat(cache.get("2")).isEqualTo("an other value-for-tenant1");
|
||||
|
||||
Exception exInThread[] = new Exception[1];
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
assertThat(cache.get("1")).isNull();
|
||||
tenantId.set("ten_2");
|
||||
Exception[] exInThread = new Exception[1];
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
assertThat(cache.get("1")).isNull();
|
||||
tenantId.set("ten_2");
|
||||
|
||||
cache.put("1", "value-for-tenant2");
|
||||
cache.put("2", "an other value-for-tenant2");
|
||||
cache.put("1", "value-for-tenant2");
|
||||
cache.put("2", "an other value-for-tenant2");
|
||||
|
||||
tenantId.set(null);
|
||||
tenantId.set(null);
|
||||
|
||||
cache.clear();
|
||||
} catch (Exception e) {
|
||||
exInThread[0] = e;
|
||||
}
|
||||
};
|
||||
};
|
||||
cache.clear();
|
||||
} catch (Exception e) {
|
||||
exInThread[0] = e;
|
||||
}
|
||||
});
|
||||
|
||||
// do some async work
|
||||
t.start();
|
||||
|
||||
Vendored
+4
-4
@@ -2,17 +2,17 @@ package io.ebeaninternal.server.cache;
|
||||
|
||||
import io.ebean.cache.ServerCacheOptions;
|
||||
import io.ebean.cache.ServerCacheType;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Article;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.Product;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class DefaultCacheHolder_getCacheOptions_Test {
|
||||
|
||||
private DefaultCacheHolder cacheHolder;
|
||||
private final DefaultCacheHolder cacheHolder;
|
||||
|
||||
public DefaultCacheHolder_getCacheOptions_Test() {
|
||||
|
||||
@@ -20,7 +20,7 @@ public class DefaultCacheHolder_getCacheOptions_Test {
|
||||
defaultOptions.setMaxSize(10000);
|
||||
defaultOptions.setMaxSecsToLive(120);
|
||||
|
||||
CacheManagerOptions builder = new CacheManagerOptions(null, new ServerConfig(), true)
|
||||
CacheManagerOptions builder = new CacheManagerOptions(null, new DatabaseConfig(), true)
|
||||
.with(defaultOptions, defaultOptions);
|
||||
|
||||
this.cacheHolder = new DefaultCacheHolder(builder);
|
||||
|
||||
+6
-8
@@ -2,7 +2,7 @@ package io.ebeaninternal.server.cache;
|
||||
|
||||
import io.ebean.config.ContainerConfig;
|
||||
import io.ebean.config.CurrentTenantProvider;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebeaninternal.server.cluster.ClusterManager;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
@@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class DefaultServerCacheManagerTest {
|
||||
|
||||
private ThreadLocal<String> tenantId = new ThreadLocal<>();
|
||||
private final ThreadLocal<String> tenantId = new ThreadLocal<>();
|
||||
|
||||
class TdTenPro implements CurrentTenantProvider {
|
||||
|
||||
@@ -23,17 +23,15 @@ public class DefaultServerCacheManagerTest {
|
||||
}
|
||||
}
|
||||
|
||||
private ClusterManager clusterManager = new ClusterManager(new ContainerConfig());
|
||||
private final ClusterManager clusterManager = new ClusterManager(new ContainerConfig());
|
||||
|
||||
private DefaultServerCacheManager manager = new DefaultServerCacheManager(new CacheManagerOptions(clusterManager, new ServerConfig(), true));
|
||||
private final DefaultServerCacheManager manager = new DefaultServerCacheManager(new CacheManagerOptions(clusterManager, new DatabaseConfig(), true));
|
||||
|
||||
private DefaultServerCacheManager multiTenantManager;
|
||||
private final DefaultServerCacheManager multiTenantManager;
|
||||
|
||||
public DefaultServerCacheManagerTest(){
|
||||
|
||||
CacheManagerOptions builder = new CacheManagerOptions(clusterManager, new ServerConfig(), true);
|
||||
CacheManagerOptions builder = new CacheManagerOptions(clusterManager, new DatabaseConfig(), true);
|
||||
builder.with(new TdTenPro());
|
||||
|
||||
this.multiTenantManager = new DefaultServerCacheManager(builder);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.ebeaninternal.server.core;
|
||||
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -8,8 +8,8 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class InitDataSourceTest {
|
||||
|
||||
private ServerConfig newConfig(String readOnlyUrl) {
|
||||
ServerConfig config = new ServerConfig();
|
||||
private DatabaseConfig newConfig(String readOnlyUrl) {
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
DataSourceConfig roConfig = new DataSourceConfig();
|
||||
roConfig.setUrl(readOnlyUrl);
|
||||
config.setReadOnlyDataSourceConfig(roConfig);
|
||||
@@ -18,13 +18,13 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_nullByDefault() {
|
||||
InitDataSource init = new InitDataSource(new ServerConfig());
|
||||
InitDataSource init = new InitDataSource(new DatabaseConfig());
|
||||
assertNull(init.readOnlyConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_null_whenSetNullExplicitly() {
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setReadOnlyDataSourceConfig(null);
|
||||
|
||||
assertNull(new InitDataSource(config).readOnlyConfig());
|
||||
@@ -46,7 +46,7 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_when_autoReadOnlyDataSource() {
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setAutoReadOnlyDataSource(true);
|
||||
|
||||
assertNotNull(new InitDataSource(config).readOnlyConfig());
|
||||
@@ -54,7 +54,7 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_when_autoReadOnlyDataSource_expect_setToNull() {
|
||||
ServerConfig config = newConfig("none");
|
||||
DatabaseConfig config = newConfig("none");
|
||||
config.setAutoReadOnlyDataSource(true);
|
||||
|
||||
final DataSourceConfig readOnlyConfig = new InitDataSource(config).readOnlyConfig();
|
||||
@@ -63,7 +63,7 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_when_urlSet() {
|
||||
ServerConfig config = newConfig("foo");
|
||||
DatabaseConfig config = newConfig("foo");
|
||||
|
||||
final DataSourceConfig roConfig = new InitDataSource(config).readOnlyConfig();
|
||||
assertNotNull(roConfig);
|
||||
@@ -72,7 +72,7 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_when_readOnlyUrlSetOnMain() {
|
||||
ServerConfig config = newConfig(null);
|
||||
DatabaseConfig config = newConfig(null);
|
||||
// alternate location to set read-only url for developer convenience
|
||||
config.getDataSourceConfig().setReadOnlyUrl("bar");
|
||||
|
||||
@@ -83,7 +83,7 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_when_readOnlyUrlSetOnMain_withNone() {
|
||||
ServerConfig config = newConfig("None");
|
||||
DatabaseConfig config = newConfig("None");
|
||||
// alternate location to set read-only url for developer convenience
|
||||
config.getDataSourceConfig().setReadOnlyUrl("bar");
|
||||
|
||||
@@ -94,7 +94,7 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_when_bothReadOnlyUrlsSet() {
|
||||
ServerConfig config = newConfig("one");
|
||||
DatabaseConfig config = newConfig("one");
|
||||
config.getDataSourceConfig().setReadOnlyUrl("two");
|
||||
|
||||
final DataSourceConfig roConfig = new InitDataSource(config).readOnlyConfig();
|
||||
@@ -104,7 +104,7 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_when_readOnlyUrlSetOnMain_withNoneNone() {
|
||||
ServerConfig config = newConfig("none");
|
||||
DatabaseConfig config = newConfig("none");
|
||||
// alternate location to set read-only url for developer convenience
|
||||
config.getDataSourceConfig().setReadOnlyUrl("none");
|
||||
|
||||
@@ -114,7 +114,7 @@ public class InitDataSourceTest {
|
||||
|
||||
@Test
|
||||
public void readOnlyConfig_when_urlSet_2() {
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.getReadOnlyDataSourceConfig().setUrl("foo");
|
||||
|
||||
final DataSourceConfig roConfig = new InitDataSource(config).readOnlyConfig();
|
||||
|
||||
+4
-8
@@ -1,7 +1,6 @@
|
||||
package io.ebeaninternal.server.deploy.parse;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
|
||||
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
||||
import io.ebeaninternal.server.deploy.generatedproperty.GeneratedPropertyFactory;
|
||||
@@ -12,7 +11,6 @@ import org.junit.jupiter.api.Test;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class AnnotationClassTest {
|
||||
|
||||
@@ -45,9 +43,8 @@ public class AnnotationClassTest {
|
||||
assertThat(columnNames[2]).isEqualTo("col3");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private AnnotationClass createAnnotationClass(ServerConfig config) {
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private AnnotationClass createAnnotationClass(DatabaseConfig config) {
|
||||
DeployUtil deployUtil = new DeployUtil(new DefaultTypeManager(config, new BootupClasses()), config);
|
||||
|
||||
DeployBeanInfo deployBeanInfo = new DeployBeanInfo(deployUtil, new DeployBeanDescriptor<>(null, null, null));
|
||||
@@ -55,10 +52,9 @@ public class AnnotationClassTest {
|
||||
return new AnnotationClass(deployBeanInfo, readAnnotationConfig);
|
||||
}
|
||||
|
||||
private ServerConfig sqlServerPlatform(boolean allQuotedIdentifiers) {
|
||||
|
||||
private DatabaseConfig sqlServerPlatform(boolean allQuotedIdentifiers) {
|
||||
SqlServer17Platform sqlServer17Platform = new SqlServer17Platform();
|
||||
ServerConfig config = new ServerConfig();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setDatabasePlatform(sqlServer17Platform);
|
||||
config.setAllQuotedIdentifiers(allQuotedIdentifiers);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.ebeaninternal.server.text.json;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
||||
import io.ebeaninternal.server.type.DefaultTypeManager;
|
||||
@@ -22,8 +22,7 @@ public class DJsonScalarTest {
|
||||
private final DJsonScalar jsonScalar;
|
||||
|
||||
public DJsonScalarTest() {
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
DatabaseConfig serverConfig = new DatabaseConfig();
|
||||
serverConfig.setDatabasePlatform(new H2Platform());
|
||||
DefaultTypeManager typeManager = new DefaultTypeManager(serverConfig, new BootupClasses());
|
||||
jsonScalar = new DJsonScalar(typeManager);
|
||||
@@ -31,7 +30,6 @@ public class DJsonScalarTest {
|
||||
|
||||
@Test
|
||||
public void writeBasicTypes() throws IOException {
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
JsonGenerator generator = createGenerator(writer);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.core.type.ScalarType;
|
||||
import io.ebean.server.type.MyDayOfWeek;
|
||||
@@ -99,38 +99,36 @@ public class TestTypeManager extends BaseTestCase {
|
||||
public void testWithConfig() {
|
||||
DefaultTypeManager typeManager1 = createTypeManager();
|
||||
ScalarType<?> type1 = typeManager1.createEnumScalarType(MySex.class, null);
|
||||
assertThat(type1 instanceof ScalarTypeEnumStandard.OrdinalEnum);
|
||||
assertThat(type1).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class);
|
||||
//
|
||||
DefaultTypeManager typeManager2 = createTypeManagerDefaultEnumTypeString();
|
||||
ScalarType<?> type2 = typeManager2.createEnumScalarType(MySex.class, null);
|
||||
assertThat(type2 instanceof ScalarTypeEnumStandard.StringEnum);
|
||||
assertThat(type2).isInstanceOf(ScalarTypeEnumStandard.StringEnum.class);
|
||||
//
|
||||
DefaultTypeManager typeManager3 = createTypeManagerDefaultEnumTypeString();
|
||||
ScalarType<?> type3 = typeManager3.createEnumScalarType(MySex.class, EnumType.ORDINAL);
|
||||
assertThat(type3 instanceof ScalarTypeEnumStandard.OrdinalEnum);
|
||||
assertThat(type3).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class);
|
||||
}
|
||||
|
||||
private DefaultTypeManager createTypeManager() {
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.setDatabasePlatform(new H2Platform());
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setDatabasePlatform(new H2Platform());
|
||||
|
||||
BootupClasses bootupClasses = new BootupClasses();
|
||||
bootupClasses.getAttributeConverters().add(MoneyTypeConverter.class);
|
||||
|
||||
return new DefaultTypeManager(serverConfig, bootupClasses);
|
||||
return new DefaultTypeManager(config, bootupClasses);
|
||||
}
|
||||
|
||||
private DefaultTypeManager createTypeManagerDefaultEnumTypeString() {
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.setDatabasePlatform(new H2Platform());
|
||||
serverConfig.setDefaultEnumType(EnumType.STRING);
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setDatabasePlatform(new H2Platform());
|
||||
config.setDefaultEnumType(EnumType.STRING);
|
||||
|
||||
BootupClasses bootupClasses = new BootupClasses();
|
||||
bootupClasses.getAttributeConverters().add(MoneyTypeConverter.class);
|
||||
|
||||
return new DefaultTypeManager(serverConfig, bootupClasses);
|
||||
return new DefaultTypeManager(config, bootupClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.tests.basic;
|
||||
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.EbeanServerFactory;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
import org.tests.model.basic.TOne;
|
||||
@@ -13,8 +13,8 @@ import org.tests.model.basic.TSMaster;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Used to run some tests manually on a specific Database type.
|
||||
@@ -22,13 +22,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
public class MainDbBoolean {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
MainDbBoolean me = new MainDbBoolean();
|
||||
|
||||
EbeanServer server = me.createEbeanServer();
|
||||
Database server = me.createEbeanServer();
|
||||
me.simpleCheck(server);
|
||||
|
||||
EbeanServer oraServer = me.createOracleEbeanServer();
|
||||
Database oraServer = me.createOracleEbeanServer();
|
||||
me.simpleCheck(oraServer);
|
||||
}
|
||||
|
||||
@@ -36,9 +35,8 @@ public class MainDbBoolean {
|
||||
* Create a server for running small oracle specific tests manually.
|
||||
* DDL generation etc.
|
||||
*/
|
||||
private EbeanServer createOracleEbeanServer() {
|
||||
|
||||
ServerConfig c = new ServerConfig();
|
||||
private Database createOracleEbeanServer() {
|
||||
DatabaseConfig c = new DatabaseConfig();
|
||||
c.setName("ora");
|
||||
c.setDdlExtra(false);
|
||||
|
||||
@@ -67,13 +65,11 @@ public class MainDbBoolean {
|
||||
c.addClass(TSMaster.class);
|
||||
c.addClass(TSDetail.class);
|
||||
|
||||
return EbeanServerFactory.create(c);
|
||||
|
||||
return DatabaseFactory.create(c);
|
||||
}
|
||||
|
||||
private EbeanServer createEbeanServer() {
|
||||
|
||||
ServerConfig c = new ServerConfig();
|
||||
private Database createEbeanServer() {
|
||||
DatabaseConfig c = new DatabaseConfig();
|
||||
c.setName("pgtest");
|
||||
c.setDdlExtra(false);
|
||||
|
||||
@@ -98,15 +94,11 @@ public class MainDbBoolean {
|
||||
c.setDatabaseBooleanFalse("F");
|
||||
|
||||
c.setDatabasePlatform(new PostgresPlatform());
|
||||
|
||||
c.addClass(TOne.class);
|
||||
|
||||
return EbeanServerFactory.create(c);
|
||||
|
||||
return DatabaseFactory.create(c);
|
||||
}
|
||||
|
||||
private void simpleCheck(EbeanServer server) {
|
||||
|
||||
private void simpleCheck(Database server) {
|
||||
TOne o = new TOne();
|
||||
o.setName("banan");
|
||||
o.setDescription("this one is true");
|
||||
@@ -127,27 +119,24 @@ public class MainDbBoolean {
|
||||
.order("id")
|
||||
.findList();
|
||||
|
||||
assertTrue(list.size() == 2);
|
||||
assertThat(list).hasSize(2);
|
||||
assertTrue(list.get(0).isActive());
|
||||
assertFalse(!list.get(0).isActive());
|
||||
|
||||
String sql = "select id, name, active from t_oneb order by id";
|
||||
List<SqlRow> sqlRows = server.sqlQuery(sql).findList();
|
||||
assertTrue(sqlRows.size() == 2);
|
||||
assertThat(sqlRows).hasSize(2);
|
||||
Object active0 = sqlRows.get(0).get("active");
|
||||
Object active1 = sqlRows.get(1).get("active");
|
||||
|
||||
assertTrue("T".equals(active0));
|
||||
assertTrue("F".equals(active1));
|
||||
|
||||
assertEquals("T", active0);
|
||||
assertEquals("F", active1);
|
||||
|
||||
Query<TOne> query = server.find(TOne.class)
|
||||
.setAutoTune(false)
|
||||
.order("id");
|
||||
|
||||
int rc = query.findCount();
|
||||
assertTrue(rc > 0);
|
||||
|
||||
assertThat(rc).isGreaterThan(0);
|
||||
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.tests.unitinternal;
|
||||
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.EbeanServerFactory;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -16,7 +16,7 @@ public class HelloMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// ### Configuration Objects ###
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
DatabaseConfig serverConfig = new DatabaseConfig();
|
||||
DataSourceConfig dataSourceConfig = new DataSourceConfig();
|
||||
|
||||
// ### Configuration Settings ###
|
||||
@@ -37,7 +37,7 @@ public class HelloMain {
|
||||
serverConfig.addClass(TOne.class);
|
||||
}
|
||||
|
||||
EbeanServer eServer = EbeanServerFactory.createWithContextClassLoader(serverConfig, HelloMain.class.getClassLoader());
|
||||
Database eServer = DatabaseFactory.createWithContextClassLoader(serverConfig, HelloMain.class.getClassLoader());
|
||||
|
||||
long id = 1;
|
||||
TOne data = eServer.find(TOne.class, id);
|
||||
@@ -49,7 +49,7 @@ public class HelloMain {
|
||||
System.out.println(String.format("############\n%s############", data.getName()));
|
||||
}
|
||||
|
||||
EbeanServerFactory.shutdown();
|
||||
DatabaseFactory.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user