mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#636 - ENH: Add DB Migration runner (as alternative to running via FlywayDB etc)
This commit is contained in:
@@ -1,10 +1,27 @@
|
||||
package com.avaje.ebean.dbmigration;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.config.DbMigrationConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Created by rob on 1/04/16.
|
||||
*/
|
||||
public class MigrationRunnerTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
DbMigrationConfig config = new DbMigrationConfig();
|
||||
config.setMigrationPath("test-dbmigration");
|
||||
config.setRunMigration(true);
|
||||
config.setDbUser("sa");
|
||||
config.setDbPassword("");
|
||||
|
||||
MigrationRunner runner = new MigrationRunner(server, config);
|
||||
|
||||
runner.run();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,87 @@
|
||||
package com.avaje.ebean.dbmigration.runner;
|
||||
|
||||
import org.assertj.core.data.MapEntry;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Created by rob on 1/04/16.
|
||||
*/
|
||||
public class PlaceholderBuilderTest {
|
||||
@Test
|
||||
public void build() throws Exception {
|
||||
|
||||
@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"));
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,31 @@ package com.avaje.ebean.dbmigration.runner;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by rob on 1/04/16.
|
||||
*/
|
||||
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