1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.groovy;
18
19 import java.lang.reflect.Field;
20 import java.lang.reflect.Method;
21
22 import junit.framework.TestCase;
23
24 import com.fatwire.gst.foundation.DebugHelper;
25 import com.fatwire.gst.foundation.controller.action.Action;
26 import com.fatwire.gst.foundation.controller.annotation.InjectForRequest;
27
28 public class GroovyLoaderTest extends TestCase {
29
30 public void testLoad() {
31 DiskGroovyLoader loader = new DiskGroovyLoader();
32 loader.bootEngine("./src/test/groovy");
33 loader.precompile();
34 Object a;
35 try {
36 long t = System.nanoTime();
37 a = loader.load("test/MyAction");
38 System.out.println(DebugHelper.microToHuman((System.nanoTime() - t) / 1000L));
39
40 if (a instanceof Action) {
41 Action action = (Action) a;
42 action.handleRequest(null);
43 for (Field field : action.getClass().getFields()) {
44
45 InjectForRequest anno = field.getAnnotation(InjectForRequest.class);
46 if ("foo".equals(field.getName()))
47 assertNotNull(anno);
48 }
49 for (Method method : action.getClass().getMethods()) {
50 if ("setSomething".equalsIgnoreCase(method.getName())) {
51 InjectForRequest anno = method.getAnnotation(InjectForRequest.class);
52 assertNotNull(anno);
53 }
54 }
55 } else {
56 fail("not an Action");
57 }
58 } catch (Exception e) {
59 e.printStackTrace();
60 fail(e.getMessage());
61 }
62 }
63
64 public void testJavaClass() {
65
66 DiskGroovyLoader loader = new DiskGroovyLoader();
67 loader.bootEngine("./src/test/groovy");
68 Object a;
69 try {
70 a = loader.load("com.fatwire.gst.foundation.groovy.action.GroovyActionLocator");
71 assertNotNull(a);
72
73 } catch (Exception e) {
74 e.printStackTrace();
75 fail(e.getMessage());
76 }
77
78 }
79 }