Skip to content

Commit

Permalink
for #601: InItCreateSchema => DatabaseEnvironmentManager
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed May 4, 2018
1 parent f4e09ae commit e11860c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.shardingjdbc.dbtest.asserts.AssertEngine;
import io.shardingjdbc.dbtest.config.bean.AssertDefinition;
import io.shardingjdbc.dbtest.config.bean.AssertsDefinition;
import io.shardingjdbc.dbtest.init.InItCreateSchema;
import io.shardingjdbc.dbtest.init.DatabaseEnvironmentManager;
import lombok.RequiredArgsConstructor;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -71,7 +71,7 @@ public static Collection<String[]> getParameters() throws IOException, JAXBExcep
AssertsDefinition assertsDefinition = unmarshal(each);
String[] dbs = assertsDefinition.getBaseConfig().split(",");
for (String db : dbs) {
InItCreateSchema.addDatabase(db);
DatabaseEnvironmentManager.addDatabase(db);
}
result.addAll(getParameters(each, assertsDefinition.getAssertDQL()));
result.addAll(getParameters(each, assertsDefinition.getAssertDML()));
Expand All @@ -81,9 +81,9 @@ public static Collection<String[]> getParameters() throws IOException, JAXBExcep
return result;
}

private static Collection<String[]> getParameters(final String path, final List<? extends AssertDefinition> asserts) {
private static Collection<String[]> getParameters(final String path, final List<? extends AssertDefinition> assertDefinitions) {
Collection<String[]> result = new LinkedList<>();
for (AssertDefinition each : asserts) {
for (AssertDefinition each : assertDefinitions) {
result.add(new String[] {path, each.getId()});
}
return result;
Expand Down Expand Up @@ -114,13 +114,13 @@ private static AssertsDefinition unmarshal(final String assertFilePath) throws I
@BeforeClass
public static void beforeClass() {
if (isInitialized) {
InItCreateSchema.createDatabase();
InItCreateSchema.createTable();
DatabaseEnvironmentManager.createDatabase();
DatabaseEnvironmentManager.createTable();
isInitialized = false;
} else {
InItCreateSchema.dropDatabase();
InItCreateSchema.createDatabase();
InItCreateSchema.createTable();
DatabaseEnvironmentManager.dropDatabase();
DatabaseEnvironmentManager.createDatabase();
DatabaseEnvironmentManager.createTable();
}
}

Expand All @@ -132,7 +132,7 @@ public void test() {
@AfterClass
public static void afterClass() {
if (isCleaned) {
InItCreateSchema.dropDatabase();
DatabaseEnvironmentManager.dropDatabase();
isCleaned = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import io.shardingjdbc.dbtest.config.bean.DatasetDefinition;
import io.shardingjdbc.dbtest.config.bean.ParameterDefinition;
import io.shardingjdbc.dbtest.exception.DbTestException;
import io.shardingjdbc.dbtest.init.InItCreateSchema;
import io.shardingjdbc.dbtest.init.DatabaseEnvironmentManager;
import io.shardingjdbc.test.sql.SQLCasesLoader;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
Expand Down Expand Up @@ -106,7 +106,7 @@ private static void onlyDatabaseRun(final String dbName, final String path, fina
for (DatabaseType each : IntegrateTestEnvironment.getInstance().getDatabaseTypes()) {
Map<String, DataSource> dataSourceMaps = new HashMap<>();
for (String db : dbs) {
DataSource subDataSource = InItCreateSchema.buildDataSource(db, each);
DataSource subDataSource = DatabaseEnvironmentManager.buildDataSource(db, each);
dataSourceMaps.put(db, subDataSource);
}
if ("true".equals(assertsDefinition.getMasterslave())) {
Expand All @@ -132,7 +132,7 @@ private static void onlyDatabaseRun(final String dbName, final String path, fina
private static void ddlRun(final DatabaseType databaseType, final String id, final String dbName, final AssertsDefinition assertsDefinition, final String rootPath, final String msg, final DataSource dataSource) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException {
for (AssertDDLDefinition each : assertsDefinition.getAssertDDL()) {
if (id.equals(each.getId())) {
List<DatabaseType> databaseTypes = InItCreateSchema.getDatabaseTypes(each.getDatabaseConfig());
List<DatabaseType> databaseTypes = DatabaseEnvironmentManager.getDatabaseTypes(each.getDatabaseConfig());
if (!databaseTypes.contains(databaseType)) {
break;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ private static void ddlRun(final DatabaseType databaseType, final String id, fin

private static void ddlSubRun(final DatabaseType databaseType, final String dbName, final String rootPath, final String msg, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String expectedDataFile, final List<AssertSubDefinition> subAsserts) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException {
for (AssertSubDefinition subAssert : subAsserts) {
List<DatabaseType> databaseSubTypes = InItCreateSchema.getDatabaseTypes(subAssert.getDatabaseConfig());
List<DatabaseType> databaseSubTypes = DatabaseEnvironmentManager.getDatabaseTypes(subAssert.getDatabaseConfig());

if (!databaseSubTypes.contains(databaseType)) {
break;
Expand Down Expand Up @@ -230,7 +230,7 @@ private static void ddlSubRun(final DatabaseType databaseType, final String dbNa
private static void dmlRun(final DatabaseType databaseType, final String initDataFile, final String dbName, final String path, final String id, final AssertsDefinition assertsDefinition, final String rootPath, final String msg, final DataSource dataSource, final Map<String, DataSource> dataSourceMaps, final List<String> dbs) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, SQLException, ParseException {
for (AssertDMLDefinition each : assertsDefinition.getAssertDML()) {
if (id.equals(each.getId())) {
List<DatabaseType> databaseTypes = InItCreateSchema.getDatabaseTypes(each.getDatabaseConfig());
List<DatabaseType> databaseTypes = DatabaseEnvironmentManager.getDatabaseTypes(each.getDatabaseConfig());
if (!databaseTypes.contains(databaseType)) {
break;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ private static void dmlRun(final DatabaseType databaseType, final String initDat
resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(expectedDataFile, dataSource, dataSourceMaps, each, rootSQL, mapDatasetDefinition, sqls, msg);
} else {
for (AssertSubDefinition subAssert : subAsserts) {
List<DatabaseType> databaseSubTypes = InItCreateSchema.getDatabaseTypes(subAssert.getDatabaseConfig());
List<DatabaseType> databaseSubTypes = DatabaseEnvironmentManager.getDatabaseTypes(subAssert.getDatabaseConfig());
if (!databaseSubTypes.contains(databaseType)) {
break;
}
Expand Down Expand Up @@ -330,7 +330,7 @@ private static void dmlRun(final DatabaseType databaseType, final String initDat
List<AssertSubDefinition> subAsserts = each.getSubAsserts();
if (!subAsserts.isEmpty()) {
for (AssertSubDefinition subAssert : subAsserts) {
List<DatabaseType> databaseSubTypes = InItCreateSchema.getDatabaseTypes(subAssert.getDatabaseConfig());
List<DatabaseType> databaseSubTypes = DatabaseEnvironmentManager.getDatabaseTypes(subAssert.getDatabaseConfig());
if (!databaseSubTypes.contains(databaseType)) {
break;
}
Expand Down Expand Up @@ -391,7 +391,7 @@ private static void dqlRun(final DatabaseType databaseType, final String initDat
for (AssertDQLDefinition each : assertsDefinition.getAssertDQL()) {

if (id.equals(each.getId())) {
List<DatabaseType> databaseTypes = InItCreateSchema.getDatabaseTypes(each.getDatabaseConfig());
List<DatabaseType> databaseTypes = DatabaseEnvironmentManager.getDatabaseTypes(each.getDatabaseConfig());
if (!databaseTypes.contains(databaseType)) {
break;
}
Expand Down Expand Up @@ -455,7 +455,7 @@ private static void dqlRun(final DatabaseType databaseType, final String initDat

private static void dqlSubRun(final DatabaseType databaseType, final String dbName, final String rootPath, final String msg, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootSQL, final String expectedDataFile, final List<AssertSubDefinition> subAsserts) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException {
for (AssertSubDefinition subAssert : subAsserts) {
List<DatabaseType> databaseSubTypes = InItCreateSchema.getDatabaseTypes(subAssert.getDatabaseConfig());
List<DatabaseType> databaseSubTypes = DatabaseEnvironmentManager.getDatabaseTypes(subAssert.getDatabaseConfig());
if (!databaseSubTypes.contains(databaseType)) {
break;
}
Expand Down Expand Up @@ -525,10 +525,10 @@ private static void doUpdateUsePreparedStatementToExecuteDDL(final DatabaseType
try {
try (Connection con = dataSource.getConnection()) {
if (StringUtils.isNotBlank(anAssert.getCleanSql())) {
InItCreateSchema.dropTable(databaseType, anAssert.getCleanSql(), dbName);
DatabaseEnvironmentManager.dropTable(databaseType, anAssert.getCleanSql(), dbName);
}
if (StringUtils.isNotBlank(anAssert.getInitSql())) {
InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName);
DatabaseEnvironmentManager.createTable(databaseType, anAssert.getInitSql(), dbName);
}
DatabaseUtil.updateUsePreparedStatementToExecute(con, rootsql,
anAssert.getParameter());
Expand All @@ -540,10 +540,10 @@ private static void doUpdateUsePreparedStatementToExecuteDDL(final DatabaseType
}
} finally {
if (StringUtils.isNotBlank(anAssert.getCleanSql())) {
InItCreateSchema.dropTable(databaseType, anAssert.getCleanSql(), dbName);
DatabaseEnvironmentManager.dropTable(databaseType, anAssert.getCleanSql(), dbName);
}
if (StringUtils.isNotBlank(anAssert.getInitSql())) {
InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName);
DatabaseEnvironmentManager.createTable(databaseType, anAssert.getInitSql(), dbName);
}
}
}
Expand Down Expand Up @@ -576,10 +576,10 @@ private static void doUpdateUsePreparedStatementToExecuteUpdateDDL(final Databas
try {
try (Connection con = dataSource.getConnection()) {
if (StringUtils.isNotBlank(anAssert.getCleanSql())) {
InItCreateSchema.dropTable(databaseType, anAssert.getCleanSql(), dbName);
DatabaseEnvironmentManager.dropTable(databaseType, anAssert.getCleanSql(), dbName);
}
if (StringUtils.isNotBlank(anAssert.getInitSql())) {
InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName);
DatabaseEnvironmentManager.createTable(databaseType, anAssert.getInitSql(), dbName);
}
DatabaseUtil.updateUsePreparedStatementToExecuteUpdate(con, rootsql,
anAssert.getParameter());
Expand All @@ -590,10 +590,10 @@ private static void doUpdateUsePreparedStatementToExecuteUpdateDDL(final Databas
}
} finally {
if (StringUtils.isNotBlank(anAssert.getCleanSql())) {
InItCreateSchema.dropTable(databaseType, anAssert.getCleanSql(), dbName);
DatabaseEnvironmentManager.dropTable(databaseType, anAssert.getCleanSql(), dbName);
}
if (StringUtils.isNotBlank(anAssert.getInitSql())) {
InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName);
DatabaseEnvironmentManager.createTable(databaseType, anAssert.getInitSql(), dbName);
}
}
}
Expand Down Expand Up @@ -623,10 +623,10 @@ private static void doUpdateUseStatementToExecuteDDL(final DatabaseType database
try {
try (Connection con = dataSource.getConnection()) {
if (StringUtils.isNotBlank(anAssert.getCleanSql())) {
InItCreateSchema.dropTable(databaseType, anAssert.getCleanSql(), dbName);
DatabaseEnvironmentManager.dropTable(databaseType, anAssert.getCleanSql(), dbName);
}
if (StringUtils.isNotBlank(anAssert.getInitSql())) {
InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName);
DatabaseEnvironmentManager.createTable(databaseType, anAssert.getInitSql(), dbName);
}
DatabaseUtil.updateUseStatementToExecute(con, rootsql, anAssert.getParameter());
DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data");
Expand All @@ -636,10 +636,10 @@ private static void doUpdateUseStatementToExecuteDDL(final DatabaseType database
}
} finally {
if (StringUtils.isNotBlank(anAssert.getCleanSql())) {
InItCreateSchema.dropTable(databaseType, anAssert.getCleanSql(), dbName);
DatabaseEnvironmentManager.dropTable(databaseType, anAssert.getCleanSql(), dbName);
}
if (StringUtils.isNotBlank(anAssert.getInitSql())) {
InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName);
DatabaseEnvironmentManager.createTable(databaseType, anAssert.getInitSql(), dbName);
}
}
}
Expand Down Expand Up @@ -669,10 +669,10 @@ private static void doUpdateUseStatementToExecuteUpdateDDL(final DatabaseType da
try {
try (Connection con = dataSource.getConnection()) {
if (StringUtils.isNotBlank(anAssert.getCleanSql())) {
InItCreateSchema.dropTable(databaseType, anAssert.getCleanSql(), dbName);
DatabaseEnvironmentManager.dropTable(databaseType, anAssert.getCleanSql(), dbName);
}
if (StringUtils.isNotBlank(anAssert.getInitSql())) {
InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName);
DatabaseEnvironmentManager.createTable(databaseType, anAssert.getInitSql(), dbName);
}
DatabaseUtil.updateUseStatementToExecuteUpdate(con, rootsql, anAssert.getParameter());
DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data");
Expand All @@ -683,10 +683,10 @@ private static void doUpdateUseStatementToExecuteUpdateDDL(final DatabaseType da
}
} finally {
if (StringUtils.isNotBlank(anAssert.getCleanSql())) {
InItCreateSchema.dropTable(databaseType, anAssert.getCleanSql(), dbName);
DatabaseEnvironmentManager.dropTable(databaseType, anAssert.getCleanSql(), dbName);
}
if (StringUtils.isNotBlank(anAssert.getInitSql())) {
InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName);
DatabaseEnvironmentManager.createTable(databaseType, anAssert.getInitSql(), dbName);
}
}
}
Expand Down
Loading

0 comments on commit e11860c

Please sign in to comment.