diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-08-10 18:28:36 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-08-10 18:28:36 +0200 |
commit | 46cb0cef9303940ade51ffe16831f55ee9cd8e1f (patch) | |
tree | a89a3538ff0d3fd56b6d401cd296940b2336657d /container-compiler-plugin/src/test/java | |
parent | 5a1256a8ed931f7a5ba05c4328353411bae31f2b (diff) | |
download | container-playground-46cb0cef9303940ade51ffe16831f55ee9cd8e1f.tar.gz container-playground-46cb0cef9303940ade51ffe16831f55ee9cd8e1f.tar.bz2 container-playground-46cb0cef9303940ade51ffe16831f55ee9cd8e1f.tar.xz container-playground-46cb0cef9303940ade51ffe16831f55ee9cd8e1f.zip |
o Start of loading referenced (singular) entities.
Diffstat (limited to 'container-compiler-plugin/src/test/java')
-rw-r--r-- | container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java | 79 |
1 files changed, 43 insertions, 36 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 c513157..dc69a03 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 @@ -13,10 +13,10 @@ import java.io.CharArrayWriter; import java.io.PrintWriter; import static io.trygvis.container.compiler.Utils.EOL; -import static io.trygvis.persistence.FieldMirror.AccessorType.FIELD; -import static io.trygvis.persistence.FieldMirror.AccessorType.METHOD; import static io.trygvis.persistence.FieldMirror.FieldType.PRIMITIVE; import static io.trygvis.persistence.FieldMirror.FieldType.REFERENCE; +import static io.trygvis.persistence.FieldMirror.GetterType; +import static io.trygvis.persistence.FieldMirror.SetterType; import static java.lang.String.format; import static org.testng.Assert.assertEquals; @@ -25,13 +25,20 @@ public class EntityMirrorTest { GeneratorConfiguration generatorConfiguration = new GeneratorConfiguration(); static TypeRef entityType = new TypeRef("Wat"); - static FieldMirror idLong = new FieldMirror(PRIMITIVE, FIELD, new TypeRef(Long.class), "id", "id", true, false, true); - static FieldMirror idString = new FieldMirror(PRIMITIVE, FIELD, new TypeRef(String.class), "id", "id", true, false, true); - static FieldMirror idMethod = new FieldMirror(PRIMITIVE, METHOD, new TypeRef(Long.class), "id", "id", true, false, true); - static FieldMirror name = new FieldMirror(PRIMITIVE, FIELD, new TypeRef(String.class), "name", "name", false, false, false); - static FieldMirror age = new FieldMirror(PRIMITIVE, FIELD, new TypeRef(Integer.class), "age", "age", false, true, false); - static FieldMirror year = new FieldMirror(PRIMITIVE, METHOD, new TypeRef(Integer.class), "year", "year", false, true, false); - static FieldMirror ref = new FieldMirror(REFERENCE, FIELD, entityType, "parent", "parent", false, false, false); + static FieldMirror idLong = new FieldMirror(PRIMITIVE, SetterType.CONSTRUCTOR, GetterType.FIELD, + new TypeRef(Long.class), "id", "id", true, false, true); + static FieldMirror idString = new FieldMirror(PRIMITIVE, SetterType.CONSTRUCTOR, GetterType.FIELD, + new TypeRef(String.class), "id", "id", true, false, true); + static FieldMirror idMethod = new FieldMirror(PRIMITIVE, SetterType.CONSTRUCTOR, GetterType.METHOD, + new TypeRef(Long.class), "id", "id", true, false, true); + static FieldMirror name = new FieldMirror(PRIMITIVE, SetterType.CONSTRUCTOR, GetterType.FIELD, + new TypeRef(String.class), "name", "name", false, false, false); + static FieldMirror age = new FieldMirror(PRIMITIVE, SetterType.CONSTRUCTOR, GetterType.FIELD, + new TypeRef(Integer.class), "age", "age", false, true, false); + static FieldMirror year = new FieldMirror(PRIMITIVE, SetterType.CONSTRUCTOR, GetterType.METHOD, + new TypeRef(Integer.class), "year", "year", false, true, false); + static FieldMirror ref = new FieldMirror(REFERENCE, SetterType.CONSTRUCTOR, GetterType.FIELD, + entityType, "parent", "parent", false, false, false); @DataProvider(name = "insertIntoSql", parallel = true) public static Object[][] insertIntoProvider() { @@ -180,33 +187,33 @@ public class EntityMirrorTest { return new DaoUtilsGenerator(unit, generatorConfiguration, myTable).deleteById(new Imports()); } - @Test - public void testFromResultSet() { - eq(fromResultSet(age), - "java.lang.Integer age = rs.getInt(1);", - "Wat returnValue = new Wat(age);", - "return returnValue;"); - - eq(fromResultSet(age, year), - "java.lang.Integer age = rs.getInt(1);", - "Wat returnValue = new Wat(age);", - "returnValue.setYear(rs.getInt(2));", - "return returnValue;"); - - eq(fromResultSet(age, year, name), - "java.lang.Integer age = rs.getInt(1);", - "java.lang.String name = rs.getString(3);", - "Wat returnValue = new Wat(age, name);", - "returnValue.setYear(rs.getInt(2));", - "return returnValue;"); - } - - private MethodRef fromResultSet(FieldMirror... fields) { - EntityMirror myTable = new EntityMirror(new GeneratorConfiguration(), entityType, "my_table"); - myTable.add(fields); - SqlUnitModel unit = new SqlUnitModel().add(myTable); - return new DaoUtilsGenerator(unit, generatorConfiguration, myTable).fromResultSet(new Imports()); - } +// @Test +// public void testFromResultSet() { +// eq(fromResultSet(age), +// "java.lang.Integer age = rs.getInt(1);", +// "Wat returnValue = new Wat(age);", +// "return returnValue;"); +// +// eq(fromResultSet(age, year), +// "java.lang.Integer age = rs.getInt(1);", +// "Wat returnValue = new Wat(age);", +// "returnValue.setYear(rs.getInt(2));", +// "return returnValue;"); +// +// eq(fromResultSet(age, year, name), +// "java.lang.Integer age = rs.getInt(1);", +// "java.lang.String name = rs.getString(3);", +// "Wat returnValue = new Wat(age, name);", +// "returnValue.setYear(rs.getInt(2));", +// "return returnValue;"); +// } + +// private MethodRef fromResultSet(FieldMirror... fields) { +// EntityMirror myTable = new EntityMirror(new GeneratorConfiguration(), entityType, "my_table"); +// myTable.add(fields); +// SqlUnitModel unit = new SqlUnitModel().add(myTable); +// return new DaoUtilsGenerator(unit, generatorConfiguration, myTable).fromResultSet(new Imports()); +// } private void eq(MethodRef m, String... expected) { CharArrayWriter actual = new CharArrayWriter(); |