diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-08-03 18:00:10 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-08-03 18:00:10 +0200 |
commit | e1cf8889628d2d31cf7067b8c002f229fc22007d (patch) | |
tree | b6fda3f7f23f445ca0030e88368cb39e27badb96 /container-compiler-plugin/src/test/java/io/trygvis | |
parent | 054cfb131292893d100a43ea2cb20c591c17c810 (diff) | |
download | container-playground-e1cf8889628d2d31cf7067b8c002f229fc22007d.tar.gz container-playground-e1cf8889628d2d31cf7067b8c002f229fc22007d.tar.bz2 container-playground-e1cf8889628d2d31cf7067b8c002f229fc22007d.tar.xz container-playground-e1cf8889628d2d31cf7067b8c002f229fc22007d.zip |
wip
Diffstat (limited to 'container-compiler-plugin/src/test/java/io/trygvis')
-rw-r--r-- | container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java | 47 | ||||
-rw-r--r-- | container-compiler-plugin/src/test/java/io/trygvis/persistence/test/PersonTypeHandler.java | 5 |
2 files changed, 52 insertions, 0 deletions
diff --git a/container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java b/container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java new file mode 100644 index 0000000..33db82b --- /dev/null +++ b/container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java @@ -0,0 +1,47 @@ +package io.trygvis.persistence; + +import io.trygvis.container.compiler.model.TypeRef; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static io.trygvis.persistence.FieldMirror.PrimitiveFieldMirror; +import static java.lang.String.format; +import static org.testng.Assert.assertEquals; + +public class EntityMirrorTest { + + static FieldMirror idLong = new PrimitiveFieldMirror(new TypeRef(Long.class), "id", "id", true, false); + static FieldMirror idString = new PrimitiveFieldMirror(new TypeRef(String.class), "id", "id", true, false); + + @DataProvider(name = "insertIntoSql", parallel = true) + public static Object[][] insertIntoProvider() { + return new Object[][]{ + new Object[]{ + new FieldMirror[]{idString}, + "INSERT INTO my_table(id) VALUES(?);", + "DELETE FROM my_table WHERE id=?;", format( + "CREATE TABLE my_table(%n" + + " id VARCHAR(1000) PRIMARY KEY%n" + + ");")}, + new Object[]{ + new FieldMirror[]{idLong}, + "INSERT INTO my_table(id) VALUES(?);", + "DELETE FROM my_table WHERE id=?;", format( + "CREATE TABLE my_table(%n" + + " id BIGINT PRIMARY KEY%n" + + ");")}, + }; + } + + @Test(dataProvider = "insertIntoSql") + public void testInsertIntoSql(FieldMirror[] fields, String insert, String delete, String create) throws Exception { + EntityMirror myTable = new EntityMirror(new GeneratorSupport(), new TypeRef("Wat"), "my_table"); + for (FieldMirror field : fields) { + myTable.add(field); + } + + assertEquals(myTable.insertIntoSql(), insert); + assertEquals(myTable.deleteFromSql(), delete); + assertEquals(myTable.createTableSql(), create); + } +} diff --git a/container-compiler-plugin/src/test/java/io/trygvis/persistence/test/PersonTypeHandler.java b/container-compiler-plugin/src/test/java/io/trygvis/persistence/test/PersonTypeHandler.java index 68e17c3..fa803da 100644 --- a/container-compiler-plugin/src/test/java/io/trygvis/persistence/test/PersonTypeHandler.java +++ b/container-compiler-plugin/src/test/java/io/trygvis/persistence/test/PersonTypeHandler.java @@ -8,4 +8,9 @@ public class PersonTypeHandler implements TypeHandler { public String resultSetSetter(int i, String o, FieldMirror field) { return "setLong(" + i + ", o." + field.javaName + ".id)"; } + + @Override + public String sqlType(FieldMirror field) { + return "LONG"; + } } |