1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jci.compilers;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.apache.commons.jci.readers.ResourceReader;
24 import org.apache.commons.jci.stores.MemoryResourceStore;
25
26
27
28
29
30 public final class RhinoJavaCompilerTestCase extends AbstractCompilerTestCase {
31
32 public JavaCompiler createJavaCompiler() {
33 return new RhinoJavaCompiler();
34 }
35
36 public String getCompilerName() {
37 return "rhino";
38 }
39
40 public void testSimpleCompile() throws Exception {
41 final JavaCompiler compiler = createJavaCompiler();
42
43 final ResourceReader reader = new ResourceReader() {
44 final private Map sources = new HashMap() {
45 private static final long serialVersionUID = 1L;
46 {
47 put("jci/Simple.js", (
48 " var i = 0;\n" +
49 "\n"
50 ).getBytes());
51 }};
52
53 public byte[] getBytes( final String pResourceName ) {
54 return (byte[]) sources.get(pResourceName);
55 }
56
57 public boolean isAvailable( final String pResourceName ) {
58 return sources.containsKey(pResourceName);
59 }
60
61 };
62
63 final MemoryResourceStore store = new MemoryResourceStore();
64 final CompilationResult result = compiler.compile(
65 new String[] {
66 "jci/Simple.js"
67 }, reader, store);
68
69 assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
70 assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
71
72 final byte[] clazzBytes = store.read("jci/Simple.class");
73 assertNotNull(clazzBytes);
74 assertTrue(clazzBytes.length > 0);
75 }
76
77 public void testExtendedCompile() throws Exception {
78 }
79
80 public void testInternalClassCompile() throws Exception {
81 }
82
83 public void testUppercasePackageNameCompile() throws Exception {
84 final JavaCompiler compiler = createJavaCompiler();
85
86 final ResourceReader reader = new ResourceReader() {
87 final private Map sources = new HashMap() {
88 private static final long serialVersionUID = 1L;
89 {
90 put("Jci/Simple.js", (
91 " var i = 0;\n" +
92 "\n"
93 ).getBytes());
94 }};
95
96 public byte[] getBytes( final String pResourceName ) {
97 return (byte[]) sources.get(pResourceName);
98 }
99
100 public boolean isAvailable( final String pResourceName ) {
101 return sources.containsKey(pResourceName);
102 }
103
104 };
105
106 final MemoryResourceStore store = new MemoryResourceStore();
107 final CompilationResult result = compiler.compile(
108 new String[] {
109 "Jci/Simple.js"
110 }, reader, store);
111
112 assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
113 assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
114
115 final byte[] clazzBytes = store.read("Jci/Simple.class");
116 assertNotNull(clazzBytes);
117 assertTrue(clazzBytes.length > 0);
118 }
119
120
121
122 }