Permalink
Browse files

Merge branch 'unitTestFixes' of https://github.com/vorbis/liquibase i…

…nto vorbis-unitTestFixes
  • Loading branch information...
nvoxland committed Apr 4, 2013
2 parents 2c277e6 + 91c50b7 commit 0078c55b3004cf29c6282fa153a36c6ca0796044
Showing with 157 additions and 236 deletions.
  1. +0 −1 liquibase-core/src/main/java/liquibase/change/core/RawSQLChange.java
  2. +1 −1 liquibase-core/src/main/java/liquibase/database/core/OracleDatabase.java
  3. +1 −1 liquibase-core/src/main/java/liquibase/database/core/PostgresDatabase.java
  4. +6 −2 liquibase-core/src/test/java/liquibase/change/AbstractChangeTest.java
  5. +7 −117 liquibase-core/src/test/java/liquibase/change/BaseSQLChangeTest.java
  6. +6 −0 liquibase-core/src/test/java/liquibase/change/ChangeFactoryTest.java
  7. +1 −1 liquibase-core/src/test/java/liquibase/change/CheckSumTest.java
  8. +27 −33 liquibase-core/src/test/java/liquibase/change/StandardChangeTest.java
  9. +1 −3 liquibase-core/src/test/java/liquibase/change/core/AddAutoIncrementChangeTest.java
  10. +1 −1 liquibase-core/src/test/java/liquibase/change/core/AddColumnChangeTest.java
  11. +1 −1 liquibase-core/src/test/java/liquibase/change/core/AddDefaultValueChangeTest.java
  12. +1 −1 liquibase-core/src/test/java/liquibase/change/core/AddForeignKeyConstraintChangeTest.java
  13. +1 −1 liquibase-core/src/test/java/liquibase/change/core/AddLookupTableChangeTest.java
  14. +1 −1 liquibase-core/src/test/java/liquibase/change/core/AddNotNullConstraintChangeTest.java
  15. +1 −1 liquibase-core/src/test/java/liquibase/change/core/AddPrimaryKeyChangeTest.java
  16. +1 −1 liquibase-core/src/test/java/liquibase/change/core/AddUniqueConstraintChangeTest.java
  17. +1 −1 liquibase-core/src/test/java/liquibase/change/core/AlterSequenceChangeTest.java
  18. +1 −1 liquibase-core/src/test/java/liquibase/change/core/CreateIndexChangeTest.java
  19. +1 −1 liquibase-core/src/test/java/liquibase/change/core/CreateProcedureChangeTest.java
  20. +1 −1 liquibase-core/src/test/java/liquibase/change/core/CreateSequenceChangeTest.java
  21. +1 −1 liquibase-core/src/test/java/liquibase/change/core/CreateTableChangeTest.java
  22. +1 −1 liquibase-core/src/test/java/liquibase/change/core/CreateViewChangeTest.java
  23. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropColumnChangeTest.java
  24. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropDefaultValueChangeTest.java
  25. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropForeignKeyConstraintChangeTest.java
  26. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropIndexChangeTest.java
  27. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropNotNullConstraintChangeTest.java
  28. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropPrimaryKeyChangeTest.java
  29. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropSequenceChangeTest.java
  30. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropTableChangeTest.java
  31. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropUniqueConstraintChangeTest.java
  32. +1 −1 liquibase-core/src/test/java/liquibase/change/core/DropViewChangeTest.java
  33. +1 −1 liquibase-core/src/test/java/liquibase/change/core/InsertDataChangeTest.java
  34. +1 −1 liquibase-core/src/test/java/liquibase/change/core/LoadDataChangeTest.java
  35. +3 −1 liquibase-core/src/test/java/liquibase/change/core/LoadUpdateDataChangeTest.java
  36. +1 −1 liquibase-core/src/test/java/liquibase/change/core/RawSQLChangeTest.java
  37. +1 −1 liquibase-core/src/test/java/liquibase/change/core/RenameColumnChangeTest.java
  38. +1 −1 liquibase-core/src/test/java/liquibase/change/core/RenameTableChangeTest.java
  39. +1 −1 liquibase-core/src/test/java/liquibase/change/core/RenameViewChangeTest.java
  40. +1 −1 liquibase-core/src/test/java/liquibase/change/core/SQLFileChangeTest.java
  41. +1 −1 liquibase-core/src/test/java/liquibase/change/core/TagDatabaseChangeTest.java
  42. +4 −1 liquibase-core/src/test/java/liquibase/changelog/ChangeSetExecuteTest.java
  43. +5 −3 liquibase-core/src/test/java/liquibase/changelog/ChangeSetTest.java
  44. +3 −0 liquibase-core/src/test/java/liquibase/changelog/visitor/UpdateVisitorTest.java
  45. +1 −1 liquibase-core/src/test/java/liquibase/database/core/DerbyDatabaseTest.java
  46. +2 −2 liquibase-core/src/test/java/liquibase/database/core/MSSQLDatabaseTest.java
  47. +2 −2 liquibase-core/src/test/java/liquibase/database/core/MySQLDatabaseTest.java
  48. +1 −2 liquibase-core/src/test/java/liquibase/lockservice/LockServiceFactoryTest.java
  49. +1 −1 liquibase-core/src/test/java/liquibase/parser/ChangeLogParserFactoryTest.java
  50. +2 −1 liquibase-core/src/test/java/liquibase/parser/core/xml/XMLChangeLogSAXParserTest.java
  51. +1 −1 liquibase-core/src/test/java/liquibase/serializer/ChangeLogSerializerFactoryTest.java
  52. +28 −6 liquibase-core/src/test/java/liquibase/serializer/core/string/StringChangeLogSerializerTest.java
  53. +2 −4 liquibase-core/src/test/java/liquibase/serializer/core/xml/XMLChangeLogSerializerTest.java
  54. +4 −4 liquibase-core/src/test/java/liquibase/sqlgenerator/core/AddAutoIncrementGeneratorDB2Test.java
  55. +14 −14 liquibase-core/src/test/java/liquibase/sqlgenerator/core/CreateTableGeneratorTest.java
  56. +1 −1 liquibase-core/src/test/java/liquibase/sqlgenerator/core/InsertOrUpdateGeneratorMSSQLTest.java
  57. +2 −2 liquibase-core/src/test/java/liquibase/sqlgenerator/core/InsertOrUpdateGeneratorOracleTest.java
@@ -3,7 +3,6 @@
import liquibase.change.AbstractSQLChange;
import liquibase.change.DatabaseChange;
import liquibase.change.ChangeMetaData;
-
/**
* Allows execution of arbitrary SQL. This change can be used when existing changes are either don't exist,
* are not flexible enough, or buggy.
@@ -144,7 +144,7 @@ public String getDefaultDriver(String url) {
@Override
public String getDefaultSchemaName() {//NOPMD
- return super.getDefaultSchemaName().toUpperCase();
+ return super.getDefaultSchemaName() == null ? null : super.getDefaultSchemaName().toUpperCase();
}
@Override
@@ -165,7 +165,7 @@ public boolean generateAutoIncrementBy(BigInteger incrementBy) {
@Override
public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType) {
- if (quotingStrategy != ObjectQuotingStrategy.LEGACY) {
+ if (objectName == null || quotingStrategy != ObjectQuotingStrategy.LEGACY) {
return super.escapeObjectName(objectName, objectType);
}
if (objectName.contains("-") || hasMixedCase(objectName) || startsWithNumeric(objectName) || isReservedWord(objectName)) {
@@ -82,7 +82,8 @@ public void createChangeMetaData() {
assertNull(null, changeMetaData.getAppliesTo());
Map<String, ChangeParameterMetaData> parameters = changeMetaData.getParameters();
- assertEquals(3, parameters.size());
+ assertEquals(4, parameters.size());
+ ChangeParameterMetaData dbmsMetaData = parameters.get("dbms");
ChangeParameterMetaData paramOneMetaData = parameters.get("paramOne");
ChangeParameterMetaData paramTwoMetaData = parameters.get("paramTwo");
ChangeParameterMetaData paramNoMetaData = parameters.get("paramNoMetadata");
@@ -105,6 +106,9 @@ public void createChangeMetaData() {
assertTrue(paramTwoMetaData.getRequiredForDatabase().contains("mysql"));
assertTrue(paramTwoMetaData.getRequiredForDatabase().contains("mssql"));
+ assertNotNull(dbmsMetaData);
+ assertTrue(dbmsMetaData.getExampleValue().toString().contains("h2"));
+
assertNotNull(paramNoMetaData);
assertNull(paramNotIncludedMetaData);
assertNull("Properties with no write method should not be included", paramNoWriteMethodMetaData);
@@ -116,7 +120,7 @@ public void createChangeMetaData_noParams() {
ChangeMetaData changeMetaData = change.createChangeMetaData();
Map<String, ChangeParameterMetaData> parameters = changeMetaData.getParameters();
- assertEquals(0, parameters.size());
+ assertEquals(1, parameters.size());
}
@Test(expected = UnexpectedLiquibaseException.class)
@@ -5,141 +5,31 @@
import org.junit.Before;
import org.junit.Test;
+import java.lang.reflect.Field;
+import java.util.Map;
+
public class BaseSQLChangeTest extends StandardChangeTest {
- private RawSQLChange refactoring;
-
@Before
public void setUp() throws Exception {
- refactoring = new RawSQLChange();
+ super.testChangeInstance = new RawSQLChange();
}
@Override
@Test
public void getRefactoringName() throws Exception {
- assertEquals("Custom SQL", new RawSQLChange().getChangeMetaData().getDescription());
+ assertEquals("sql", new RawSQLChange().getChangeMetaData().getName());
}
@Override
public void generateStatement() throws Exception {
- //To change body of implemented methods use File | Settings | File Templates.
}
- // @Test
-// public void generateStatement() throws Exception {
-// refactoring.setSql("SQL STATEMENT HERE");
-// OracleDatabase database = new OracleDatabase();
-// assertEquals("SQL STATEMENT HERE", refactoring.generateStatements(database)[0].getSqlStatement(database));
-// }
-
@Override
@Test
public void getConfirmationMessage() throws Exception {
- assertEquals("Custom SQL executed", refactoring.getConfirmationMessage());
+ assertEquals("Custom SQL executed", testChangeInstance.getConfirmationMessage());
}
-// @Test
-// public void multiLineSQLFileSemiColon() throws Exception {
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("SELECT * FROM customer;\n" +
-// "SELECT * from table;");
-// OracleDatabase database = new OracleDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-//
-// assertEquals(2,statements.length);
-// assertEquals("SELECT * FROM customer",statements[0].getSqlStatement(database));
-// assertEquals("SELECT * from table",statements[1].getSqlStatement(database));
-// }
-
-// @Test
-// public void singleLineEndInSemiColon() throws Exception {
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("SELECT * FROM customer;");
-// OracleDatabase database = new OracleDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-// assertEquals(1,statements.length);
-// assertEquals("SELECT * FROM customer",statements[0].getSqlStatement(database));
-// }
-
-// @Test
-// public void singleLineEndGo() throws Exception {
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("SELECT * FROM customer\ngo");
-// MSSQLDatabase database = new MSSQLDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-// assertEquals(1,statements.length);
-// assertEquals("SELECT * FROM customer",statements[0].getSqlStatement(database));
-// }
-
-// @Test
-// public void singleLineBeginGo() throws Exception {
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("goSELECT * FROM customer\ngo");
-// MSSQLDatabase database = new MSSQLDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-// assertEquals(1,statements.length);
-// assertEquals("goSELECT * FROM customer",statements[0].getSqlStatement(database));
-// }
-
-// @Test
-// public void multiLineSQLFileGoShouldFind() throws Exception {
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("SELECT * FROM customer\ngo\n" +
-// "SELECT * from table\ngo");
-// MSSQLDatabase database = new MSSQLDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-// assertEquals(2,statements.length);
-// assertEquals("SELECT * FROM customer",statements[0].getSqlStatement(database));
-// assertEquals("SELECT * from table",statements[1].getSqlStatement(database));
-// }
-
-// @Test
-// public void multiLineSQLFileGoShouldNotFind() throws Exception {
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("SELECT * FROM go\ngo\n" +
-// "SELECT * from gogo\ngo\n");
-// MSSQLDatabase database = new MSSQLDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-//
-// assertEquals(2,statements.length);
-// assertEquals("SELECT * FROM go",statements[0].getSqlStatement(database));
-// assertEquals("SELECT * from gogo",statements[1].getSqlStatement(database));
-// }
-
-// @Test
-// public void stripComments() throws UnsupportedChangeException, StatementNotSupportedOnDatabaseException {
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("SELECT * FROM x\n -- A comment");
-// change2.setStripComments(true);
-// MSSQLDatabase database = new MSSQLDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-//
-// assertEquals(1,statements.length);
-// assertEquals("SELECT * FROM x\n",statements[0].getSqlStatement(database));
-// }
-
-// @Test
-// public void turnOffSplitting() throws UnsupportedChangeException, StatementNotSupportedOnDatabaseException {
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("SELECT * FROM x;SELECT * FROM x;");
-// change2.setSplitStatements(false);
-// MSSQLDatabase database = new MSSQLDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-//
-// assertEquals(1,statements.length);
-// assertEquals("SELECT * FROM x;SELECT * FROM x;",statements[0].getSqlStatement(database));
-// }
-
-// @Test
-// public void defaultSplittingAndNoStripping() throws Exception{
-// SQLFileChange change2 = new SQLFileChange();
-// change2.setSql("SELECT * FROM x;\n/*A Comment*/SELECT * FROM x;");
-//
-// MSSQLDatabase database = new MSSQLDatabase();
-// SqlStatement[] statements = change2.generateStatements(database);
-//
-// assertEquals(2,statements.length);
-// assertEquals("SELECT * FROM x",statements[0].getSqlStatement(database));
-// assertEquals("/*A Comment*/SELECT * FROM x",statements[1].getSqlStatement(database));
-// }
+
}
@@ -12,6 +12,7 @@
import liquibase.change.core.DropTableChange;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.servicelocator.LiquibaseService;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,6 +32,11 @@ public void setup() {
SometimesExceptionThrowingChange.timesCalled = 0;
}
+ @After
+ public void resetRegistry() {
+ ChangeFactory.reset();
+ }
+
@Test
public void constructor() {
ChangeFactory instance = ChangeFactory.getInstance();
@@ -30,7 +30,7 @@ public void parse_v1() {
@Test
public void getCurrentVersion() {
- assertEquals(5, CheckSum.getCurrentVersion());
+ assertEquals(6, CheckSum.getCurrentVersion());
}
@Test
@@ -1,9 +1,13 @@
package liquibase.change;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import liquibase.database.Database;
+import liquibase.exception.ValidationErrors;
+import liquibase.serializer.core.string.StringChangeLogSerializer;
+import liquibase.statement.DatabaseFunction;
+import liquibase.statement.SequenceNextValueFunction;
+import liquibase.statement.SqlStatement;
+import liquibase.test.TestContext;
+import org.junit.Test;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -14,20 +18,18 @@
import java.util.List;
import java.util.Map;
-import liquibase.database.Database;
-import liquibase.exception.ValidationErrors;
-import liquibase.serializer.core.string.StringChangeLogSerializer;
-import liquibase.statement.DatabaseFunction;
-import liquibase.statement.SqlStatement;
-import liquibase.test.TestContext;
-
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Base test class for changes
*/
public abstract class StandardChangeTest {
+ protected Change testChangeInstance;
+
@Test
public abstract void getRefactoringName() throws Exception;
@@ -57,6 +59,10 @@ public void generateCheckSum() throws Exception {
} else if (field.getName().equals("associatedWith")) {
//currently not used
} else if (String.class.isAssignableFrom(field.getType())) {
+ // comment field should be ignored as it should not impact checksum
+ if (field.getName().equals("comment")) {
+ continue;
+ }
field.set(change, "asdghasdgasdg");
checkThatChecksumIsNew(change, seenCheckSums, field);
field.set(change, "gsgasdgasdggasdg sdg a");
@@ -71,6 +77,11 @@ public void generateCheckSum() throws Exception {
checkThatChecksumIsNew(change, seenCheckSums, field);
field.set(change, -52352);
checkThatChecksumIsNew(change, seenCheckSums, field);
+ } else if (SequenceNextValueFunction.class.isAssignableFrom(field.getType())) {
+ field.set(change, new SequenceNextValueFunction("Sequence1"));
+ checkThatChecksumIsNew(change, seenCheckSums, field);
+ field.set(change, new SequenceNextValueFunction("Sequence2"));
+ checkThatChecksumIsNew(change, seenCheckSums, field);
} else if (DatabaseFunction.class.isAssignableFrom(field.getType())) {
field.set(change, new DatabaseFunction("FUNC1"));
checkThatChecksumIsNew(change, seenCheckSums, field);
@@ -107,6 +118,9 @@ public void generateCheckSum() throws Exception {
}
private Change createClassUnderTest() throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
+ if (testChangeInstance != null) {
+ return testChangeInstance;
+ }
String className = getClass().getName().replaceAll("Test$", "");
if (className.indexOf("Abstract") > 0) {
return null;
@@ -125,26 +139,6 @@ protected void checkThatChecksumIsNew(Change change, Map<String, String> seenChe
seenCheckSums.put(newCheckSum.toString(), serialized);
}
-// @Test
-// public void saveStatement() throws Exception {
-// Change change = new AbstractChange("test", "Test Refactoring", ChangeMetaData.PRIORITY_DEFAULT) {
-// public SqlStatement[] generateStatements(Database database) {
-// return new SqlStatement[]{new RawSqlStatement("GENERATED STATEMENT")};
-// }
-//
-// public String getConfirmationMessage() {
-// return null;
-// }
-// };
-//
-// StringWriter stringWriter = new StringWriter();
-//
-// OracleDatabase database = new OracleDatabase();
-// database.saveStatements(change, new ArrayList<SqlVisitor>(), stringWriter);
-//
-// assertEquals("GENERATED STATEMENT;" + StreamUtil.getLineSeparator() + StreamUtil.getLineSeparator(), stringWriter.getBuffer().toString());
-// }
-
//todo: reintroduce @Test
// public void executeStatement() throws Exception {
// Change change = new AbstractChange("test", "Test Refactorign", ChangeMetaData.PRIORITY_DEFAULT) {
@@ -289,7 +283,7 @@ public void validate() throws Exception {
return;
}
for (Database database : TestContext.getInstance().getAllDatabases()) {
- if (change.supports(database)) {
+ if (!change.supports(database)) {
ValidationErrors validationErrors = change.validate(database);
assertTrue("no errors found for "+database.getClass().getName(), validationErrors.hasErrors());
}
@@ -17,8 +17,6 @@
@Test
public void constructor() {
AddAutoIncrementChange change = new AddAutoIncrementChange();
- assertEquals("addAutoIncrement", change.getChangeMetaData().getName());
- assertEquals("Set Column as Auto-Increment", change.getChangeMetaData().getDescription());
assertEquals("column", change.getChangeMetaData().getAppliesTo().iterator().next());
}
@@ -56,7 +54,7 @@ public void validate(SqlStatement[] sqlStatements, Database database) {
@Override
@Test
public void getRefactoringName() throws Exception {
- assertEquals("Set Column as Auto-Increment", new AddAutoIncrementChange().getChangeMetaData().getDescription());
+ assertEquals("addAutoIncrement", new AddAutoIncrementChange().getChangeMetaData().getName());
}
@Override
@@ -32,7 +32,7 @@ public void validate() throws Exception {
@Test
public void getRefactoringName() throws Exception {
AddColumnChange refactoring = new AddColumnChange();
- assertEquals("Add Column", refactoring.getChangeMetaData().getDescription());
+ assertEquals("addColumn", refactoring.getChangeMetaData().getName());
}
@Test
@@ -166,7 +166,7 @@ public void generateStatements_booleanDefaultValue_false() throws Exception {
@Override
public void getRefactoringName() throws Exception {
- assertEquals("Add Default Value", new AddDefaultValueChange().getChangeMetaData().getDescription());
+ assertEquals("addDefaultValue", new AddDefaultValueChange().getChangeMetaData().getName());
}
@Override
@@ -54,7 +54,7 @@ public void generateStatement() throws Exception {
@Override
public void getRefactoringName() throws Exception {
- assertEquals("Add Foreign Key Constraint", new AddForeignKeyConstraintChange().getChangeMetaData().getDescription());
+ assertEquals("addForeignKeyConstraint", new AddForeignKeyConstraintChange().getChangeMetaData().getName());
}
@Override
Oops, something went wrong.

0 comments on commit 0078c55

Please sign in to comment.