001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.jci.compilers;
019
020 import java.util.HashMap;
021 import java.util.Map;
022
023 import org.apache.commons.jci.readers.ResourceReader;
024 import org.apache.commons.jci.stores.MemoryResourceStore;
025
026 /**
027 *
028 * @author tcurdt
029 */
030 public final class RhinoJavaCompilerTestCase extends AbstractCompilerTestCase {
031
032 @Override
033 public JavaCompiler createJavaCompiler() {
034 return new RhinoJavaCompiler();
035 }
036
037 @Override
038 public String getCompilerName() {
039 return "rhino";
040 }
041
042 @Override
043 public void testSimpleCompile() throws Exception {
044 final JavaCompiler compiler = createJavaCompiler();
045
046 final ResourceReader reader = new ResourceReader() {
047 final private Map<String, byte[]> sources = new HashMap<String, byte[]>() {
048 private static final long serialVersionUID = 1L;
049 {
050 put("jci/Simple.js", (
051 " var i = 0;\n" +
052 "\n"
053 ).getBytes());
054 }};
055
056 public byte[] getBytes( final String pResourceName ) {
057 return sources.get(pResourceName);
058 }
059
060 public boolean isAvailable( final String pResourceName ) {
061 return sources.containsKey(pResourceName);
062 }
063
064 };
065
066 final MemoryResourceStore store = new MemoryResourceStore();
067 final CompilationResult result = compiler.compile(
068 new String[] {
069 "jci/Simple.js"
070 }, reader, store);
071
072 assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
073 assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
074
075 final byte[] clazzBytes = store.read("jci/Simple.class");
076 assertNotNull(clazzBytes);
077 assertTrue(clazzBytes.length > 0);
078 }
079
080 @Override
081 public void testExtendedCompile() throws Exception {
082 }
083
084 @Override
085 public void testInternalClassCompile() throws Exception {
086 }
087
088 @Override
089 public void testUppercasePackageNameCompile() throws Exception {
090 final JavaCompiler compiler = createJavaCompiler();
091
092 final ResourceReader reader = new ResourceReader() {
093 final private Map<String, byte[]> sources = new HashMap<String, byte[]>() {
094 private static final long serialVersionUID = 1L;
095 {
096 put("Jci/Simple.js", (
097 " var i = 0;\n" +
098 "\n"
099 ).getBytes());
100 }};
101
102 public byte[] getBytes( final String pResourceName ) {
103 return sources.get(pResourceName);
104 }
105
106 public boolean isAvailable( final String pResourceName ) {
107 return sources.containsKey(pResourceName);
108 }
109
110 };
111
112 final MemoryResourceStore store = new MemoryResourceStore();
113 final CompilationResult result = compiler.compile(
114 new String[] {
115 "Jci/Simple.js"
116 }, reader, store);
117
118 assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
119 assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
120
121 final byte[] clazzBytes = store.read("Jci/Simple.class");
122 assertNotNull(clazzBytes);
123 assertTrue(clazzBytes.length > 0);
124 }
125
126 @Override
127 public void testCrossReferenceCompilation() throws Exception {
128 // NA
129 }
130
131 @Override
132 public void testAdditionalTopLevelClassCompile() throws Exception {
133 // NA
134 }
135
136 }