-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
1,401 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integration-test/src/test/java/ch/ergon/adam/integrationtest/AbstractDbTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
.../src/test/java/ch/ergon/adam/integrationtest/oracle/AbstractOracleSchemaCoverageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package ch.ergon.adam.integrationtest.oracle; | ||
|
||
import ch.ergon.adam.core.db.SchemaDiffExtractor; | ||
import ch.ergon.adam.core.db.interfaces.SchemaSource; | ||
import ch.ergon.adam.core.db.schema.Schema; | ||
import ch.ergon.adam.core.db.schema.View; | ||
import ch.ergon.adam.core.helper.FileHelper; | ||
import ch.ergon.adam.integrationtest.AssertAnyChangeStrategy; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static ch.ergon.adam.core.helper.CollectorsHelper.createSchemaItemNameArray; | ||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
public abstract class AbstractOracleSchemaCoverageTest extends AbstractOracleTestBase { | ||
|
||
private static Path tempFolder; | ||
|
||
@BeforeAll | ||
public static void setupTempFolder() throws IOException { | ||
tempFolder = Files.createTempDirectory("ADAMTableTest"); | ||
tempFolder.toFile().deleteOnExit(); | ||
} | ||
|
||
@AfterAll | ||
public static void cleanupTempFolder() throws IOException { | ||
FileHelper.deleteFolderRecursively(tempFolder); | ||
} | ||
|
||
private static final String CREATE_TABLE_SQL = | ||
"CREATE TABLE test_table (" + | ||
"id INTEGER GENERATED BY DEFAULT ON NULL AS IDENTITY, " + | ||
"col1 INTEGER NOT NULL, " + | ||
"col2 NUMBER(10,2) DEFAULT 10 NULL, " + | ||
"col3 CLOB NULL, " + | ||
"col4 VARCHAR2(10) NOT NULL, " + | ||
"CONSTRAINT test_table_pkey PRIMARY KEY (id), " + | ||
"CONSTRAINT test_table_col1_key UNIQUE (col1)" + | ||
")"; | ||
|
||
private static final String CREATE_TABLE_WITH_FK_SQL = | ||
"CREATE TABLE test_fktable (" + | ||
"id INTEGER REFERENCES test_table(id), " + | ||
"CONSTRAINT test_fktable_pkey PRIMARY KEY (id) " + | ||
")"; | ||
|
||
private static final String CREATE_VIEW = | ||
"CREATE VIEW test_view AS (" + | ||
"SELECT * FROM test_table " + | ||
")"; | ||
|
||
private static final String CREATE_SEQUENCE = | ||
"CREATE SEQUENCE test_sequence"; | ||
|
||
private static final String CREATE_VIEW2 = | ||
"CREATE VIEW depending_view AS (" + | ||
"SELECT * FROM test_view " + | ||
")"; | ||
|
||
|
||
@Test | ||
public void testSchemaCoverage() throws Exception { | ||
getSourceDbConnection().createStatement().execute(CREATE_TABLE_SQL); | ||
getSourceDbConnection().createStatement().execute(CREATE_TABLE_WITH_FK_SQL); | ||
getSourceDbConnection().createStatement().execute(CREATE_VIEW); | ||
getSourceDbConnection().createStatement().execute(CREATE_VIEW2); | ||
getSourceDbConnection().createStatement().execute(CREATE_SEQUENCE); | ||
SchemaSource source = getSourceDbSource(); | ||
Schema finalSchema = executeTransformation(source); | ||
|
||
assertSchemaEquals(source.getSchema(), finalSchema); | ||
} | ||
|
||
protected abstract Schema executeTransformation(SchemaSource source) throws Exception; | ||
|
||
private void assertSchemaEquals(Schema sourceSchema, Schema targetSchema) { | ||
SchemaDiffExtractor diffExtractor = new SchemaDiffExtractor(sourceSchema, targetSchema); | ||
diffExtractor.process(new AssertAnyChangeStrategy()); | ||
|
||
sourceSchema.getViews().forEach(sourceView -> { | ||
View targetView = targetSchema.getView(sourceView.getName()); | ||
String[] sourceDependencies = createSchemaItemNameArray(sourceView.getBaseRelations()); | ||
String[] targetDependencies = createSchemaItemNameArray(targetView.getBaseRelations()); | ||
assertArrayEquals(targetDependencies, sourceDependencies); | ||
}); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ation-test/src/test/java/ch/ergon/adam/integrationtest/oracle/AbstractOracleTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ch.ergon.adam.integrationtest.oracle; | ||
|
||
import ch.ergon.adam.integrationtest.AbstractDbTestBase; | ||
|
||
public class AbstractOracleTestBase extends AbstractDbTestBase { | ||
|
||
|
||
public AbstractOracleTestBase() { | ||
super(new OracleTestDbUrlProvider()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
integration-test/src/test/java/ch/ergon/adam/integrationtest/oracle/OracleAddFieldTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ch.ergon.adam.integrationtest.oracle; | ||
|
||
import ch.ergon.adam.integrationtest.testcases.AddFieldTests; | ||
|
||
public class OracleAddFieldTests extends AddFieldTests { | ||
public OracleAddFieldTests() { | ||
super(new OracleTestDbUrlProvider()); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ion-test/src/test/java/ch/ergon/adam/integrationtest/oracle/OracleCastFieldTypeTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ch.ergon.adam.integrationtest.oracle; | ||
|
||
import ch.ergon.adam.core.db.schema.Field; | ||
import ch.ergon.adam.core.db.schema.Schema; | ||
import ch.ergon.adam.core.db.schema.Table; | ||
import ch.ergon.adam.integrationtest.DummySink; | ||
import ch.ergon.adam.integrationtest.testcases.CastFieldTypeTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.ResultSet; | ||
|
||
import static ch.ergon.adam.core.db.schema.DataType.INTEGER; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class OracleCastFieldTypeTests extends CastFieldTypeTest { | ||
public OracleCastFieldTypeTests() { | ||
super(new OracleTestDbUrlProvider()); | ||
} | ||
|
||
@Test | ||
public void testCastVarcharToSerial() throws Exception { | ||
|
||
// Setup db | ||
getTargetDbConnection().createStatement().execute(getCreateTableStatement()); | ||
getTargetDbConnection().createStatement().execute(INSERT_DATA_SQL); | ||
DummySink dummySink = targetToDummy(); | ||
Schema schema = dummySink.getTargetSchema(); | ||
|
||
// Apply change | ||
Table table = schema.getTable("test_table"); | ||
Field field = table.getField("col1"); | ||
field.setDataType(INTEGER); | ||
field.setSequence(true); | ||
migrateTargetWithSchema(schema); | ||
dummySink = targetToDummy(); | ||
schema = dummySink.getTargetSchema(); | ||
|
||
// Verify | ||
table = schema.getTable("test_table"); | ||
assertNotNull(table); | ||
|
||
// Data still present? | ||
ResultSet result = getTargetDbConnection().createStatement().executeQuery("select sum(\"col1\") from \"test_table\""); | ||
assertTrue(result.next()); | ||
assertThat(result.getInt(1), is(2)); | ||
} | ||
|
||
@Override | ||
protected String getCreateTableStatement() { | ||
return "create table \"test_table\" (" + | ||
"\"col1\" varchar2(100), " + | ||
"\"col2\" int " + | ||
")"; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...on-test/src/test/java/ch/ergon/adam/integrationtest/oracle/OracleChangeFieldTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ch.ergon.adam.integrationtest.oracle; | ||
|
||
import ch.ergon.adam.integrationtest.testcases.ChangeFieldTypeTest; | ||
import org.junit.jupiter.api.Disabled; | ||
|
||
public class OracleChangeFieldTypeTest extends ChangeFieldTypeTest { | ||
public OracleChangeFieldTypeTest() { | ||
super(new OracleTestDbUrlProvider()); | ||
} | ||
|
||
protected String getCreateTableNotNullSql() { | ||
return "create table \"test_table\" (" + | ||
"\"test_field\" varchar(10) not null " + | ||
")"; | ||
} | ||
|
||
protected String getCreateTableNullSql() { | ||
return "create table \"test_table\" (" + | ||
"\"test_field\" numeric(10,2) null " + | ||
")"; | ||
} | ||
|
||
protected String getCreateTableTwoFieldsSql() { | ||
return "create table \"test_table\" (" + | ||
"\"col1\" clob null, " + | ||
"\"col2\" clob null " + | ||
")"; | ||
} | ||
|
||
@Override | ||
@Disabled | ||
public void changeFromSerialToClob() { | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ration-test/src/test/java/ch/ergon/adam/integrationtest/oracle/OracleConstraintTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ch.ergon.adam.integrationtest.oracle; | ||
|
||
import ch.ergon.adam.core.db.schema.Schema; | ||
import ch.ergon.adam.integrationtest.DummySink; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
public class OracleConstraintTests extends AbstractOracleTestBase { | ||
|
||
private static final String CREATE_TABLE_SQL = | ||
"create table test_table (" + | ||
"id integer null CHECK (id > 0) " + | ||
")"; | ||
|
||
@Test | ||
public void testCreateConstraint() throws Exception { | ||
|
||
// Setup db | ||
getSourceDbConnection().createStatement().execute(CREATE_TABLE_SQL); | ||
sourceToTarget(); | ||
DummySink dummySink = targetToDummy(); | ||
|
||
// Verify | ||
Schema schema = dummySink.getTargetSchema(); | ||
assertThat(schema.getTable("TEST_TABLE").getConstraints().size(), is(1)); | ||
} | ||
|
||
@Test | ||
public void testRecreateConstraintAfterTableChange() throws Exception { | ||
|
||
// Setup db | ||
getSourceDbConnection().createStatement().execute(CREATE_TABLE_SQL); | ||
sourceToTarget(); | ||
DummySink dummySink = targetToDummy(); | ||
Schema schema = dummySink.getTargetSchema(); | ||
|
||
// Apply change | ||
schema.getTable("TEST_TABLE").getField("ID").setNullable(false); | ||
migrateTargetWithSchema(schema); | ||
dummySink = targetToDummy(); | ||
schema = dummySink.getTargetSchema(); | ||
|
||
// Verify | ||
assertFalse(schema.getTable("TEST_TABLE").getField("ID").isNullable()); | ||
assertThat(schema.getTable("TEST_TABLE").getConstraints().size(), is(1)); | ||
} | ||
} |
Oops, something went wrong.