summaryrefslogtreecommitdiff
path: root/container-compiler-plugin/src/test
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-08-03 15:06:46 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-08-03 15:06:46 +0200
commitb5d6f23d8ac3d4bedb139fdaecc2e9dc621f385a (patch)
treeede2d0de570efcbb546fabcb2d5d050511792ae1 /container-compiler-plugin/src/test
parent34137b599dbea13c94224dff2955376b1394dbc9 (diff)
downloadcontainer-playground-b5d6f23d8ac3d4bedb139fdaecc2e9dc621f385a.tar.gz
container-playground-b5d6f23d8ac3d4bedb139fdaecc2e9dc621f385a.tar.bz2
container-playground-b5d6f23d8ac3d4bedb139fdaecc2e9dc621f385a.tar.xz
container-playground-b5d6f23d8ac3d4bedb139fdaecc2e9dc621f385a.zip
wip
Diffstat (limited to 'container-compiler-plugin/src/test')
-rw-r--r--container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java16
-rw-r--r--container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java1
-rw-r--r--container-compiler-plugin/src/test/java/io/trygvis/container/compiler/ProcessorTest.java32
-rw-r--r--container-compiler-plugin/src/test/java/io/trygvis/container/compiler/UtilsTest.java25
-rw-r--r--container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/Car.java (renamed from container-compiler-plugin/src/test/resources/Car.java)2
-rw-r--r--container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/Person.java (renamed from container-compiler-plugin/src/test/resources/Person.java)2
-rw-r--r--container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/package-info.java3
7 files changed, 67 insertions, 14 deletions
diff --git a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java
index e476d3e..60a78ae 100644
--- a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java
+++ b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/InMemoryJavaFileManager.java
@@ -13,11 +13,11 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.net.URI;
-import java.util.HashMap;
import java.util.Map;
+import java.util.TreeMap;
public class InMemoryJavaFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
- public final Map<String, String> codes = new HashMap<>();
+ public final Map<String, String> codes = new TreeMap<>();
public InMemoryJavaFileManager(StandardJavaFileManager standardFileManager) {
super(standardFileManager);
@@ -25,13 +25,11 @@ public class InMemoryJavaFileManager extends ForwardingJavaFileManager<StandardJ
@Override
public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException {
- System.out.println("io.trygvis.container.compiler.InMemoryJavaFileManager.getFileForOutput");
throw new RuntimeException("");
}
@Override
public JavaFileObject getJavaFileForOutput(Location location, final String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException {
- System.out.println("io.trygvis.container.compiler.InMemoryJavaFileManager.getJavaFileForOutput");
return new SimpleJavaFileObject(URI.create("wat://woot/" + className.replace('.', '/') + ".java"), kind) {
String code;
@@ -41,7 +39,7 @@ public class InMemoryJavaFileManager extends ForwardingJavaFileManager<StandardJ
@Override
public void close() {
super.close();
- System.out.println("Closing writer to: className = " + className);
+// System.out.println("Closing writer to: className = " + className);
code = super.toString();
codes.put(className, code);
}
@@ -71,4 +69,12 @@ public class InMemoryJavaFileManager extends ForwardingJavaFileManager<StandardJ
}
};
}
+
+ @Override
+ public boolean isSameFile(FileObject a, FileObject b) {
+ return a.toUri().compareTo(b.toUri()) == 0;
+// System.out.println("a = " + a);
+// System.out.println("b = " + b);
+// return super.isSameFile(a, b);
+ }
}
diff --git a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java
index e07a11f..b950064 100644
--- a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java
+++ b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java
@@ -1,6 +1,5 @@
package io.trygvis.container.compiler;
-import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import java.net.URI;
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 2205d52..bac8209 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
@@ -9,11 +9,13 @@ import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
+import java.io.IOException;
+import java.net.URL;
import java.nio.charset.Charset;
-import java.util.Arrays;
import java.util.Locale;
+import java.util.Map;
-import static java.util.Collections.singletonList;
+import static java.util.Arrays.asList;
import static org.fest.assertions.Assertions.assertThat;
public class ProcessorTest {
@@ -28,20 +30,25 @@ public class ProcessorTest {
InMemoryJavaFileManager fileManager = new InMemoryJavaFileManager(standardFileManager);
- JavaSourceFromString myEntity = new JavaSourceFromString("Person", IOUtils.toString(getClass().getResource("/Person.java"), UTF_8));
+ JavaSourceFromString person = loadCode("io.trygvis.persistence.test.Person");
+ JavaSourceFromString packageInfo = loadCode("io.trygvis.persistence.test.package-info");
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, collector, null,
- null, singletonList(myEntity));
+ null, asList(person, packageInfo));
- task.setProcessors(Arrays.asList(new MyProcessor()));
+ task.setProcessors(asList(new MyProcessor()));
Boolean result = task.call();
- assertThat(fileManager.codes.keySet()).containsOnly("Person_Sql");
- System.out.println(fileManager.codes.get("Person_Sql"));
+ 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 = " + diagnostic);
System.out.println("diagnostic.source = ->" + diagnostic.getSource().getName() + "<-");
System.out.println("diagnostic.message = " + diagnostic.getMessage(Locale.ENGLISH));
}
@@ -51,4 +58,13 @@ public class ProcessorTest {
fileManager.close();
}
+
+ private JavaSourceFromString loadCode(String className) throws IOException {
+ String path = "/" + className.replace('.', '/') + ".java";
+ URL resource = getClass().getResource(path);
+ 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/container/compiler/UtilsTest.java b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/UtilsTest.java
new file mode 100644
index 0000000..0dd1414
--- /dev/null
+++ b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/UtilsTest.java
@@ -0,0 +1,25 @@
+package io.trygvis.container.compiler;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import static io.trygvis.container.compiler.Utils.toFieldName;
+import static org.testng.Assert.assertEquals;
+
+public class UtilsTest {
+ @DataProvider(name = "toFieldName", parallel = true)
+ public static Object[][] SqlNameDataProvider() {
+ return new Object[][] {
+ new Object[]{"FooBar", "fooBar"},
+ new Object[]{"fooBar", "fooBar"},
+ new Object[]{"foo_bar", "fooBar"},
+ new Object[]{"_foo_bar", "fooBar"},
+ new Object[]{"foo_bar_", "fooBar"},
+ };
+ }
+
+ @Test(dataProvider = "toFieldName")
+ public void testToFieldName(String input, String output) {
+ assertEquals(toFieldName(input), output);
+ }
+}
diff --git a/container-compiler-plugin/src/test/resources/Car.java b/container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/Car.java
index 5661bc2..4b80afc 100644
--- a/container-compiler-plugin/src/test/resources/Car.java
+++ b/container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/Car.java
@@ -1,3 +1,5 @@
+package io.trygvis.persistence.test;
+
import javax.persistence.Entity;
@Entity
diff --git a/container-compiler-plugin/src/test/resources/Person.java b/container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/Person.java
index 4bdb882..131691f 100644
--- a/container-compiler-plugin/src/test/resources/Person.java
+++ b/container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/Person.java
@@ -1,3 +1,5 @@
+package io.trygvis.persistence.test;
+
import io.trygvis.persistence.SqlEntity;
import javax.persistence.Entity;
diff --git a/container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/package-info.java b/container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/package-info.java
new file mode 100644
index 0000000..9ca5e93
--- /dev/null
+++ b/container-compiler-plugin/src/test/resources/io/trygvis/persistence/test/package-info.java
@@ -0,0 +1,3 @@
+@SqlEntitySet package io.trygvis.persistence.test;
+
+import io.trygvis.persistence.SqlEntitySet;