mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#711 - Refactor: Extract DB Migration runner as separate module (called avaje-dbmigration)
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
package com.avaje.ebean.dbmigration;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class DdlParserTest {
|
||||
|
||||
DdlParser parser = new DdlParser();
|
||||
|
||||
@Test
|
||||
public void parse_ignoresEmptyLines() throws Exception {
|
||||
|
||||
List<String> stmts = parser.parse(new StringReader("\n\none;\n\ntwo;\n\n"));
|
||||
|
||||
assertThat(stmts).hasSize(2);
|
||||
assertThat(stmts).contains("one;","two;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_ignoresComments_whenFirst() throws Exception {
|
||||
|
||||
List<String> stmts = parser.parse(new StringReader("-- comment\ntwo;"));
|
||||
|
||||
assertThat(stmts).hasSize(1);
|
||||
assertThat(stmts).contains("two;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_ignoresEmptyLines_whenFirst() throws Exception {
|
||||
|
||||
List<String> stmts = parser.parse(new StringReader("\n\n-- comment\ntwo;\n\n"));
|
||||
assertThat(stmts).hasSize(1);
|
||||
assertThat(stmts).contains("two;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_inlineEmptyLines_replacedWithSpace() throws Exception {
|
||||
|
||||
List<String> stmts = parser.parse(new StringReader("\n\n-- comment\none\ntwo;\n\n"));
|
||||
assertThat(stmts).hasSize(1);
|
||||
assertThat(stmts).contains("one two;");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void parse_ignoresComments() throws Exception {
|
||||
|
||||
List<String> stmts = parser.parse(new StringReader("one;\n-- comment\ntwo;"));
|
||||
|
||||
assertThat(stmts).hasSize(2);
|
||||
assertThat(stmts).contains("one;","two;");
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.avaje.ebean.dbmigration;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.config.DbMigrationConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class MigrationRunnerTest extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (!isH2()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
DbMigrationConfig config = new DbMigrationConfig();
|
||||
config.setMigrationPath("test-dbmigration");
|
||||
config.setRunMigration(true);
|
||||
config.setDbUser("sa");
|
||||
config.setDbPassword("");
|
||||
|
||||
new MigrationRunner(server, config).run();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.avaje.ebean.dbmigration.runner;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ChecksumTest {
|
||||
|
||||
@Test
|
||||
public void test_calculate() throws Exception {
|
||||
|
||||
int checkFoo = Checksum.calculate("foo");
|
||||
|
||||
assertThat(Checksum.calculate("foo")).isEqualTo(checkFoo);
|
||||
assertThat(Checksum.calculate("Foo")).isNotEqualTo(checkFoo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.avaje.ebean.dbmigration.runner;
|
||||
|
||||
import org.assertj.core.data.MapEntry;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class PlaceholderBuilderTest {
|
||||
|
||||
@Test
|
||||
public void empty() throws Exception {
|
||||
|
||||
assertThat(PlaceholderBuilder.build(null, null)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void comma() throws Exception {
|
||||
|
||||
assertThat(PlaceholderBuilder.build("a=1", null))
|
||||
.containsExactly(MapEntry.entry("a","1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void comma_withSpace() throws Exception {
|
||||
|
||||
assertThat(PlaceholderBuilder.build(" a=1 ", null))
|
||||
.containsExactly(MapEntry.entry("a","1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void comma_withSpace_withSemi() throws Exception {
|
||||
|
||||
assertThat(PlaceholderBuilder.build(" a=1 ; ", null))
|
||||
.containsExactly(MapEntry.entry("a","1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void commaPair() throws Exception {
|
||||
|
||||
assertThat(PlaceholderBuilder.build("a=1;b=2", null))
|
||||
.containsExactly(MapEntry.entry("a","1"),MapEntry.entry("b","2"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void mapPair() throws Exception {
|
||||
|
||||
Map<String,String> in = new HashMap<String,String>();
|
||||
in.put("a", "1");
|
||||
in.put("b", "2");
|
||||
|
||||
assertThat(PlaceholderBuilder.build(null, in))
|
||||
.containsExactly(MapEntry.entry("a","1"),MapEntry.entry("b","2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void mapPair_override() throws Exception {
|
||||
|
||||
Map<String,String> in = new HashMap<String,String>();
|
||||
in.put("a", "1");
|
||||
in.put("b", "2");
|
||||
|
||||
assertThat(PlaceholderBuilder.build("a=11;b=12", in))
|
||||
.containsExactly(MapEntry.entry("a","1"),MapEntry.entry("b","2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void mapPair_join() throws Exception {
|
||||
|
||||
Map<String,String> in = new HashMap<String,String>();
|
||||
in.put("c", "3");
|
||||
|
||||
assertThat(PlaceholderBuilder.build("a=1;b=2", in))
|
||||
.containsExactly(MapEntry.entry("a","1"),MapEntry.entry("b","2"), MapEntry.entry("c","3"));
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.avaje.ebean.dbmigration.runner;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ScriptTransformTest {
|
||||
|
||||
@Test
|
||||
public void transform() throws Exception {
|
||||
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("one", "PLACE1");
|
||||
map.put("two", "PLACE2");
|
||||
|
||||
ScriptTransform transform = new ScriptTransform(map);
|
||||
|
||||
assertEquals(transform.transform("${one}"), "PLACE1");
|
||||
assertEquals(transform.transform("${two}"), "PLACE2");
|
||||
assertEquals(transform.transform("${one}${two}"), "PLACE1PLACE2");
|
||||
assertEquals(transform.transform("${two}${one}"), "PLACE2PLACE1");
|
||||
assertEquals(transform.transform("A${one}B${two}C"), "APLACE1BPLACE2C");
|
||||
assertEquals(transform.transform(" ${one} ${two} "), " PLACE1 PLACE2 ");
|
||||
|
||||
assertEquals(transform.transform("$${one}"), "$PLACE1");
|
||||
assertEquals(transform.transform("$${one}}"), "$PLACE1}");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user