1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * @author tcurdt
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 }