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.controller.action.Action;
25 import com.fatwire.gst.foundation.controller.annotation.InjectForRequest;
26
27 public class GroovyLoaderTest extends TestCase {
28
29 public void testLoad() {
30 DiskGroovyLoader loader = new DiskGroovyLoader();
31 loader.bootEngine("./src/test/groovy");
32 loader.precompile();
33 Object a;
34 try {
35 a = loader.load(null,"test/MyAction");
36 if (a instanceof Action) {
37 Action action = (Action) a;
38 action.handleRequest(null);
39 for (Field field : action.getClass().getFields()) {
40 InjectForRequest anno = field.getAnnotation(InjectForRequest.class);
41 if ("foo".equals(field.getName()))
42 assertNotNull(anno);
43 }
44 for (Method method : action.getClass().getMethods()) {
45 if ("setSomething".equalsIgnoreCase(method.getName())) {
46 InjectForRequest anno = method.getAnnotation(InjectForRequest.class);
47 assertNotNull(anno);
48 }
49 }
50 } else {
51 fail("not an Action");
52 }
53 } catch (Exception e) {
54 e.printStackTrace();
55 fail(e.getMessage());
56 }
57 }
58
59 public void testJavaClass() {
60
61 DiskGroovyLoader loader = new DiskGroovyLoader();
62 loader.bootEngine("./src/test/groovy");
63 Object a;
64 try {
65 a = loader.load(null,"com.fatwire.gst.foundation.groovy.action.GroovyActionLocator");
66 assertNotNull(a);
67
68 } catch (Exception e) {
69 e.printStackTrace();
70 fail(e.getMessage());
71 }
72
73 }
74 }