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
031: AbstractCompilerTestCase {
032:
033: public JavaCompiler createJavaCompiler() {
034: return new RhinoJavaCompiler();
035: }
036:
037: public String getCompilerName() {
038: return "rhino";
039: }
040:
041: public void testSimpleCompile() throws Exception {
042: final JavaCompiler compiler = createJavaCompiler();
043:
044: final ResourceReader reader = new ResourceReader() {
045: final private Map sources = new HashMap() {
046: private static final long serialVersionUID = 1L;
047: {
048: put("jci/Simple.js", (" var i = 0;\n" + "\n")
049: .getBytes());
050: }
051: };
052:
053: public byte[] getBytes(final String pResourceName) {
054: return (byte[]) sources.get(pResourceName);
055: }
056:
057: public boolean isAvailable(final String pResourceName) {
058: return sources.containsKey(pResourceName);
059: }
060:
061: };
062:
063: final MemoryResourceStore store = new MemoryResourceStore();
064: final CompilationResult result = compiler.compile(
065: new String[] { "jci/Simple.js" }, reader, store);
066:
067: assertEquals(toString(result.getErrors()), 0, result
068: .getErrors().length);
069: assertEquals(toString(result.getWarnings()), 0, result
070: .getWarnings().length);
071:
072: final byte[] clazzBytes = store.read("jci/Simple.class");
073: assertNotNull(clazzBytes);
074: assertTrue(clazzBytes.length > 0);
075: }
076:
077: public void testExtendedCompile() throws Exception {
078: }
079:
080: public void testInternalClassCompile() throws Exception {
081: }
082:
083: public void testUppercasePackageNameCompile() throws Exception {
084: final JavaCompiler compiler = createJavaCompiler();
085:
086: final ResourceReader reader = new ResourceReader() {
087: final private Map sources = new HashMap() {
088: private static final long serialVersionUID = 1L;
089: {
090: put("Jci/Simple.js", (" var i = 0;\n" + "\n")
091: .getBytes());
092: }
093: };
094:
095: public byte[] getBytes(final String pResourceName) {
096: return (byte[]) sources.get(pResourceName);
097: }
098:
099: public boolean isAvailable(final String pResourceName) {
100: return sources.containsKey(pResourceName);
101: }
102:
103: };
104:
105: final MemoryResourceStore store = new MemoryResourceStore();
106: final CompilationResult result = compiler.compile(
107: new String[] { "Jci/Simple.js" }, reader, store);
108:
109: assertEquals(toString(result.getErrors()), 0, result
110: .getErrors().length);
111: assertEquals(toString(result.getWarnings()), 0, result
112: .getWarnings().length);
113:
114: final byte[] clazzBytes = store.read("Jci/Simple.class");
115: assertNotNull(clazzBytes);
116: assertTrue(clazzBytes.length > 0);
117: }
118:
119: }
|