diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-08-03 20:21:19 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-08-03 20:21:19 +0200 |
commit | df92538ab3d83da9839f08b28fc8a67317565463 (patch) | |
tree | a958d3cce1d3a9045c79371b182adb1ea6cf5a73 /container-compiler-plugin/src/test/java/io/trygvis/persistence | |
parent | e1cf8889628d2d31cf7067b8c002f229fc22007d (diff) | |
download | container-playground-df92538ab3d83da9839f08b28fc8a67317565463.tar.gz container-playground-df92538ab3d83da9839f08b28fc8a67317565463.tar.bz2 container-playground-df92538ab3d83da9839f08b28fc8a67317565463.tar.xz container-playground-df92538ab3d83da9839f08b28fc8a67317565463.zip |
wip
Diffstat (limited to 'container-compiler-plugin/src/test/java/io/trygvis/persistence')
-rw-r--r-- | container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java | 31 | ||||
-rw-r--r-- | container-compiler-plugin/src/test/java/io/trygvis/persistence/test/PersonTypeHandler.java | 10 |
2 files changed, 32 insertions, 9 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 index 33db82b..9d90eef 100644 --- a/container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java +++ b/container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java @@ -1,5 +1,6 @@ package io.trygvis.persistence; +import io.trygvis.container.compiler.SqlUnitModel; import io.trygvis.container.compiler.model.TypeRef; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -10,8 +11,11 @@ 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); + static TypeRef entityType = new TypeRef("Wat"); + static FieldMirror idLong = new PrimitiveFieldMirror(new TypeRef(Long.class), "id", "id", true, false, true); + static FieldMirror idString = new PrimitiveFieldMirror(new TypeRef(String.class), "id", "id", true, false, true); + static FieldMirror name = new PrimitiveFieldMirror(new TypeRef(String.class), "name", "name", false, false, false); + static FieldMirror ref = new FieldMirror.ReferenceFieldMirror(entityType, "parent", "parent", false, false); @DataProvider(name = "insertIntoSql", parallel = true) public static Object[][] insertIntoProvider() { @@ -30,18 +34,37 @@ public class EntityMirrorTest { "CREATE TABLE my_table(%n" + " id BIGINT PRIMARY KEY%n" + ");")}, + new Object[]{ + new FieldMirror[]{idLong, name}, + "INSERT INTO my_table(id, name) VALUES(?, ?);", + "DELETE FROM my_table WHERE id=?;", format( + "CREATE TABLE my_table(%n" + + " id BIGINT PRIMARY KEY,%n" + + " name VARCHAR(1000)%n" + + ");")}, + new Object[]{ + new FieldMirror[]{idLong, ref}, + "INSERT INTO my_table(id, parent) VALUES(?, ?);", + "DELETE FROM my_table WHERE id=?;", format( + "CREATE TABLE my_table(%n" + + " id BIGINT PRIMARY KEY,%n" + + " parent BIGINT REFERENCES my_table(id)%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"); + EntityMirror myTable = new EntityMirror(new GeneratorConfiguration(), entityType, "my_table"); for (FieldMirror field : fields) { myTable.add(field); } + SqlUnitModel unit = new SqlUnitModel(); + unit.add(myTable); + assertEquals(myTable.insertIntoSql(), insert); assertEquals(myTable.deleteFromSql(), delete); - assertEquals(myTable.createTableSql(), create); + assertEquals(myTable.createTableSql(unit), 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 fa803da..a872271 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 @@ -1,11 +1,10 @@ package io.trygvis.persistence.test; -import io.trygvis.persistence.FieldMirror; -import io.trygvis.persistence.TypeHandler; - -public class PersonTypeHandler implements TypeHandler { +@SuppressWarnings("UnusedDeclaration") +public class PersonTypeHandler /*implements TypeHandler*/ { + /* @Override - public String resultSetSetter(int i, String o, FieldMirror field) { + public String setter(int i, String o, FieldMirror field) { return "setLong(" + i + ", o." + field.javaName + ".id)"; } @@ -13,4 +12,5 @@ public class PersonTypeHandler implements TypeHandler { public String sqlType(FieldMirror field) { return "LONG"; } + */ } |