summaryrefslogtreecommitdiff
path: root/container-compiler-plugin/src/test/java/io/trygvis
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-08-03 20:21:19 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-08-03 20:21:19 +0200
commitdf92538ab3d83da9839f08b28fc8a67317565463 (patch)
treea958d3cce1d3a9045c79371b182adb1ea6cf5a73 /container-compiler-plugin/src/test/java/io/trygvis
parente1cf8889628d2d31cf7067b8c002f229fc22007d (diff)
downloadcontainer-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')
-rw-r--r--container-compiler-plugin/src/test/java/io/trygvis/container/compiler/ProcessorTest.java26
-rw-r--r--container-compiler-plugin/src/test/java/io/trygvis/persistence/EntityMirrorTest.java31
-rw-r--r--container-compiler-plugin/src/test/java/io/trygvis/persistence/test/PersonTypeHandler.java10
3 files changed, 48 insertions, 19 deletions
diff --git a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/ProcessorTest.java b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/ProcessorTest.java
index bac8209..b8d022d 100644
--- a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/ProcessorTest.java
+++ b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/ProcessorTest.java
@@ -38,21 +38,27 @@ public class ProcessorTest {
task.setProcessors(asList(new MyProcessor()));
- Boolean result = task.call();
+ boolean result = task.call();
+ if (!result) {
+ for (Diagnostic<? extends JavaFileObject> diagnostic : collector.getDiagnostics()) {
+ JavaFileObject source = diagnostic.getSource();
+ String error = "";
+ if (source != null) {
+ error += source.toUri().getPath();
+ }
+ error += ":" + diagnostic.getLineNumber() + ":" + diagnostic.getColumnNumber();
+ System.out.println(error + ":" + diagnostic.getMessage(Locale.ENGLISH));
+ }
+ }
- assertThat(fileManager.codes.keySet()).containsOnly(
- "io.trygvis.persistence.test.Daos",
- "io.trygvis.persistence.test.PersonDao");
for (Map.Entry<String, String> entry : fileManager.codes.entrySet()) {
System.out.println("=== " + entry.getKey());
System.out.println(entry.getValue());
}
- for (Diagnostic<? extends JavaFileObject> diagnostic : collector.getDiagnostics()) {
- System.out.println("diagnostic.source = ->" + diagnostic.getSource().getName() + "<-");
- System.out.println("diagnostic.message = " + diagnostic.getMessage(Locale.ENGLISH));
- }
-
+ assertThat(fileManager.codes.keySet()).containsOnly(
+ "io.trygvis.persistence.test.Session",
+ "io.trygvis.persistence.test.PersonDao");
assertThat(collector.getDiagnostics()).isEmpty();
assertThat(result).isTrue();
@@ -62,7 +68,7 @@ public class ProcessorTest {
private JavaSourceFromString loadCode(String className) throws IOException {
String path = "/" + className.replace('.', '/') + ".java";
URL resource = getClass().getResource(path);
- if(resource == null) {
+ if (resource == null) {
throw new RuntimeException("Could not load code for: " + path);
}
return new JavaSourceFromString(className, IOUtils.toString(resource, UTF_8));
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";
}
+ */
}