commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r232412 - in /jakarta/commons/sandbox/jci/trunk: ./ src/java/org/apache/commons/jci/ src/java/org/apache/commons/jci/compilers/eclipse/ src/java/org/apache/commons/jci/compilers/groovy/ src/java/org/apache/commons/jci/compilers/janino/ src/...
Date Sat, 13 Aug 2005 02:50:07 GMT
Author: tcurdt
Date: Fri Aug 12 19:49:43 2005
New Revision: 232412

URL: http://svn.apache.org/viewcvs?rev=232412&view=rev
Log:
improved testcase coverage


Added:
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java
Modified:
    jakarta/commons/sandbox/jci/trunk/project.xml
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java

Modified: jakarta/commons/sandbox/jci/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/project.xml?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/project.xml (original)
+++ jakarta/commons/sandbox/jci/trunk/project.xml Fri Aug 12 19:49:43 2005
@@ -120,6 +120,9 @@
       <includes>
         <include>**/*TestCase.java</include>
       </includes>
+      <excludes>
+        <exclude>**/Abstract*</exclude>
+      </excludes>
     </unitTest>
   </build>
 

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
Fri Aug 12 19:49:43 2005
@@ -68,6 +68,7 @@
                 new ConsoleCompilationProblemHandler()
                 ) {
             public void reload() {
+                super.reload();
                 CompilingClassLoader.this.reload();
             }
         }, repository);

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
Fri Aug 12 19:49:43 2005
@@ -25,10 +25,7 @@
 import org.apache.commons.jci.compilers.JavaCompiler;
 import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
-import org.apache.commons.jci.problems.ConsoleCompilationProblemHandler;
-import org.apache.commons.jci.readers.FileResourceReader;
 import org.apache.commons.jci.readers.ResourceReader;
-import org.apache.commons.jci.stores.MemoryResourceStore;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
@@ -261,45 +258,41 @@
         final ICompilerRequestor compilerRequestor = new ICompilerRequestor() {
 
             public void acceptResult(CompilationResult result) {
-                try {
-                    if (result.hasProblems()) {
-                        if (pProblemHandler != null) {
-	                        final IProblem[] problems = result.getProblems();
-	                        for (int i = 0; i < problems.length; i++) {
-	                            final IProblem problem = problems[i];
-	                            pProblemHandler.handle(
-	                                    new CompilationProblem(
-	                                            problem.getID(),
-	                                            new String(problem.getOriginatingFileName()),
-	                                            problem.getMessage(),
-	                                            problem.getSourceLineNumber(),
-	                                            problem.getSourceLineNumber(),
-	                                            problem.isError()
-	                                            ));
-	                        }
+                if (result.hasProblems()) {
+                    if (pProblemHandler != null) {
+                        final IProblem[] problems = result.getProblems();
+                        for (int i = 0; i < problems.length; i++) {
+                            final IProblem problem = problems[i];
+                            pProblemHandler.handle(
+                                    new CompilationProblem(
+                                            problem.getID(),
+                                            new String(problem.getOriginatingFileName()),
+                                            problem.getMessage(),
+                                            problem.getSourceLineNumber(),
+                                            problem.getSourceLineNumber(),
+                                            problem.isError()
+                                            ));
                         }
                     }
-                    
-                    if (!result.hasErrors()) {
+                }
+                
+                if (!result.hasErrors()) {
 
-                        final ClassFile[] clazzFiles = result.getClassFiles();
-                        for (int i = 0; i < clazzFiles.length; i++) {
-                            final ClassFile clazzFile = clazzFiles[i];
-
-                            final char[][] compoundName = clazzFile.getCompoundName();
-                            final StringBuffer clazzName = new StringBuffer();
-                            for (int j = 0; j < compoundName.length; j++) {
-                                if (j != 0) {
-                                    clazzName.append('.');
-                                }
-                                clazzName.append(compoundName[j]);
+                    final ClassFile[] clazzFiles = result.getClassFiles();
+                    for (int i = 0; i < clazzFiles.length; i++) {
+                        final ClassFile clazzFile = clazzFiles[i];
+
+                        final char[][] compoundName = clazzFile.getCompoundName();
+                        final StringBuffer clazzName = new StringBuffer();
+                        for (int j = 0; j < compoundName.length; j++) {
+                            if (j != 0) {
+                                clazzName.append('.');
                             }
-
-                            pStore.write(clazzName.toString(), clazzFile.getBytes());
+                            clazzName.append(compoundName[j]);
                         }
+
+                        pStore.write(clazzName.toString(), clazzFile.getBytes());
                     }
-                } catch (Exception exc) {
-                    exc.printStackTrace();
                 }
             }
 
@@ -309,23 +302,5 @@
 
         compiler.compile(compilationUnits);
 
-    }
-
-    public static void main(String[] args) throws Exception {
-
-        final JavaCompiler compiler = new EclipseJavaCompiler();
-        final ConsoleCompilationProblemHandler problemHandler = new ConsoleCompilationProblemHandler();
-        
-        compiler.compile(
-                args,
-                new FileResourceReader("classes"),
-                new MemoryResourceStore(),
-                problemHandler
-                );
-        
-        log.debug(
-                problemHandler.getErrorCount() + " errors, " +
-                problemHandler.getWarningCount() + " warnings"
-                );
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java
Fri Aug 12 19:49:43 2005
@@ -12,7 +12,7 @@
     public EclipseJavaCompilerSettings() {
         map.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
         map.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
-        map.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
+        map.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.GENERATE);
         map.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
         map.put(CompilerOptions.OPTION_Encoding, "UTF-8");
         map.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
Fri Aug 12 19:49:43 2005
@@ -1,14 +1,11 @@
 package org.apache.commons.jci.compilers.groovy;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.commons.jci.compilers.JavaCompiler;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
-import org.apache.commons.jci.problems.ConsoleCompilationProblemHandler;
-import org.apache.commons.jci.readers.FileResourceReader;
 import org.apache.commons.jci.readers.ResourceReader;
-import org.apache.commons.jci.stores.MemoryResourceStore;
 import org.apache.commons.jci.stores.ResourceStore;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public final class GroovyJavaCompiler implements JavaCompiler {
 
@@ -21,23 +18,5 @@
             final CompilationProblemHandler problemHandler
             ) {
         throw new RuntimeException("NYI");
-    }
-
-    public static void main(String[] args) throws Exception {
-
-        final JavaCompiler compiler = new GroovyJavaCompiler();
-        final ConsoleCompilationProblemHandler problemHandler = new ConsoleCompilationProblemHandler();
-        
-        compiler.compile(
-                args,
-                new FileResourceReader("classes"),
-                new MemoryResourceStore(),
-                problemHandler
-                );
-        
-        log.debug(
-                problemHandler.getErrorCount() + " errors, " +
-                problemHandler.getWarningCount() + " warnings"
-                );
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
Fri Aug 12 19:49:43 2005
@@ -21,14 +21,10 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-
 import org.apache.commons.jci.compilers.JavaCompiler;
 import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
-import org.apache.commons.jci.problems.ConsoleCompilationProblemHandler;
-import org.apache.commons.jci.readers.FileResourceReader;
 import org.apache.commons.jci.readers.ResourceReader;
-import org.apache.commons.jci.stores.MemoryResourceStore;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -146,23 +142,4 @@
             store.write(name,bytes);
         }
     }
-    
-    public static void main(String[] args) throws Exception {
-        final JavaCompiler compiler = new JaninoJavaCompiler();
-        final ConsoleCompilationProblemHandler problemHandler = new ConsoleCompilationProblemHandler();
-        
-        compiler.compile(
-                args,
-                new FileResourceReader("classes"),
-                new MemoryResourceStore(),
-                problemHandler
-                );
-        
-        log.debug(
-                problemHandler.getErrorCount() + " errors, " +
-                problemHandler.getWarningCount() + " warnings"
-                );
-    }
-
-
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/CompilingListener.java
Fri Aug 12 19:49:43 2005
@@ -146,5 +146,6 @@
     }
 
     protected void reload() {
+        log.debug("reload");
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java
Fri Aug 12 19:49:43 2005
@@ -26,10 +26,6 @@
 public final class FileResourceReader implements ResourceReader {
 
     private final File base;
-    
-    public FileResourceReader( final String pBase ) {
-        base = new File(pBase);        
-    }
 
     public FileResourceReader( final File pBase ) {
         base = pBase;        
@@ -44,7 +40,6 @@
             return FileUtils.readFileToString(
                     new File(base,fileName), "UTF-8").toCharArray();
         } catch(Exception e) {
-            e.printStackTrace();
         }
         return null;
     }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java
Fri Aug 12 19:49:43 2005
@@ -15,6 +15,15 @@
  */
 package org.apache.commons.jci.stores;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import org.apache.commons.io.IOUtils;
+
 
 /**
  * @author tcurdt
@@ -22,13 +31,50 @@
  */
 public final class FileResourceStore implements ResourceStore {
 
+    private final File root;
+    
+    public FileResourceStore(final File pFile) {
+        root = pFile;
+    }
     public byte[] read( final String resourceName ) {
-        throw new RuntimeException("NYI");
+        InputStream is = null;
+        try {
+            is = new FileInputStream(new File(root, resourceName));
+            final byte[] data = IOUtils.toByteArray(is);
+            return data;
+        } catch (FileNotFoundException e) {
+        } catch (IOException e) {
+        } finally {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+        
+        return null;
     }
+
     public void write( final String resourceName, final byte[] clazzData ) {
-        throw new RuntimeException("NYI");
+        OutputStream os = null;
+        try {
+            os = new FileOutputStream(new File(root, resourceName));
+            os.write(clazzData);
+        } catch (FileNotFoundException e) {
+        } catch (IOException e) {
+        } finally {
+            if (os != null) {
+                try {
+                    os.close();
+                } catch (IOException e) {
+                }
+            }
+        }
     }    
+
     public void remove( final String resourceName ) {
-        throw new RuntimeException("NYI");
+        final File file = new File(root, resourceName);
+        file.delete();
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
Fri Aug 12 19:49:43 2005
@@ -33,7 +33,6 @@
 	private final Map store = new HashMap();
 	
 	public byte[] read( final String resourceName ) {
-		//log.debug("looking up class " + resourceName);
 		return (byte[]) store.get(resourceName);
 	}
 

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/AbstractTestCase.java
Fri Aug 12 19:49:43 2005
@@ -106,7 +106,7 @@
     
     protected void delay() {
         try {
-            Thread.sleep(1000);
+            Thread.sleep(1500);
         } catch (final InterruptedException e) {
             ;
         }

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
Fri Aug 12 19:49:43 2005
@@ -1,11 +1,13 @@
 package org.apache.commons.jci;
 
 import java.io.File;
+import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
+import org.apache.commons.jci.compilers.Programs;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 
-public final class CompilingClassLoaderTestCase extends AbstractTestCase {
+public final class CompilingClassLoaderTestCase extends AbstractCompilerTestCase {
 
     private final static Log log = LogFactory.getLog(CompilingClassLoaderTestCase.class);
     
@@ -37,21 +39,11 @@
         waitForSignal(reload);
 
         writeFile("jci/Simple.java",
-                "package jci;\n"
-                + "public class Simple { \n"
-                + "  public String toString() { \n"
-                + "    return \"Simple\"; \n"
-                + "  } \n"
-                + "} \n"
+                Programs.simple
         );
         
         writeFile("jci/Extended.java",
-                "package jci;\n"
-                + "public class Extended extends Simple { \n"
-                + "  public String toString() { \n"
-                + "    return \"Extended:\" + super.toString(); \n"
-                + "  } \n"
-                + "} \n"
+                Programs.extended
         );
         
         waitForSignal(reload);
@@ -64,17 +56,12 @@
         waitForSignal(reload);
 
         writeFile("jci/Simple.java",
-                "package jci;\n"
-                + "public class Simple { \n"
-                + "  public String toString() { \n"
-                + "    return 1; \n"
-                + "  } \n"
-                + "} \n"
+                Programs.error
         );
 
         waitForSignal(reload);
         
-        
+        // FIXME
     }
     
     public void testCreate() throws Exception {
@@ -101,12 +88,7 @@
         assertTrue("Extended:Simple".equals(o.toString()));
 
         writeFile("jci/Simple.java",
-                "package jci;\n"
-                + "public class Simple { \n"
-                + "  public String toString() { \n"
-                + "    return \"SIMPLE\"; \n"
-                + "  } \n"
-                + "} \n"
+                Programs.SIMPLE
         );
 
         waitForSignal(reload);

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java?rev=232412&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java
Fri Aug 12 19:49:43 2005
@@ -0,0 +1,37 @@
+package org.apache.commons.jci.compilers;
+
+import java.io.File;
+import org.apache.commons.jci.AbstractTestCase;
+import org.apache.commons.jci.problems.CompilationProblemHandler;
+import org.apache.commons.jci.problems.LogCompilationProblemHandler;
+import org.apache.commons.jci.readers.FileResourceReader;
+import org.apache.commons.jci.stores.FileResourceStore;
+
+
+public abstract class AbstractCompilerTestCase extends AbstractTestCase {
+
+        
+    protected CompilationProblemHandler compileWith( final JavaCompiler pCompiler, final
String pSource ) throws Exception {
+        final File srcDir = new File(directory, "src");
+        final File dstDir = new File(directory, "dst");
+        
+        assertTrue(srcDir.mkdir());
+        assertTrue(dstDir.mkdir());
+        
+        final FileResourceReader src = new FileResourceReader(srcDir);
+        final FileResourceStore dst = new FileResourceStore(dstDir);
+        
+        final CompilationProblemHandler handler = new LogCompilationProblemHandler();
+
+        writeFile("src/jci/Simple.java", pSource);
+        
+        pCompiler.compile(
+                new String[] { "jci.Simple"},
+                src,
+                dst,
+                handler
+                );
+        
+        return handler;
+    }
+}

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java?rev=232412&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/Programs.java
Fri Aug 12 19:49:43 2005
@@ -0,0 +1,47 @@
+package org.apache.commons.jci.compilers;
+
+
+public interface Programs {
+    
+    String simple =
+        "package jci;\n"
+        + "public class Simple { \n"
+        + "  public String toString() { \n"
+        + "    return \"Simple\"; \n"
+        + "  } \n"
+        + "} \n";
+
+    String SIMPLE = "package jci;\n"
+        + "public class Simple { \n"
+        + "  public String toString() { \n"
+        + "    return \"SIMPLE\"; \n"
+        + "  } \n"
+        + "} \n";
+    
+    String extended =
+        "package jci;\n"
+        + "public class Extended extends Simple { \n"
+        + "  public String toString() { \n"
+        + "    return \"Extended:\" + super.toString(); \n"
+        + "  } \n"
+        + "} \n";
+
+    String warning =
+        "package jci;\n"
+        + "public class Simple { \n"
+        + "  public int generateWarning() { \n"
+        + "    return new java.util.Date().getHours(); \n"
+        + "  }\n"
+        + "  public String toString() { \n"
+        + "    return \"Simple\"; \n"
+        + "  } \n"
+        + "} \n";
+
+    String error =
+        "package jci;\n"
+        + "public class Simple { \n"
+        + "  public String toString() { \n"
+        + "    return 1; \n"
+        + "  } \n"
+        + "} \n";
+}

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java?rev=232412&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerTestCase.java
Fri Aug 12 19:49:43 2005
@@ -0,0 +1,30 @@
+package org.apache.commons.jci.compilers.eclipse;
+
+import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
+import org.apache.commons.jci.compilers.JavaCompiler;
+import org.apache.commons.jci.compilers.Programs;
+import org.apache.commons.jci.problems.CompilationProblemHandler;
+
+
+public final class EclipseJavaCompilerTestCase extends AbstractCompilerTestCase {
+    public void testSimpleCompilation() throws Exception {
+        final JavaCompiler compiler = new EclipseJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, Programs.simple);
+        assertTrue(handler.getWarningCount() == 0);
+        assertTrue(handler.getErrorCount() == 0);
+    }
+    
+    public void testCompilationError() throws Exception {
+        final JavaCompiler compiler = new EclipseJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, Programs.error);
+        assertTrue(handler.getWarningCount() == 0);
+        assertTrue(handler.getErrorCount() == 1);
+    }
+
+    public void testCompilationWarning() throws Exception {
+        final JavaCompiler compiler = new EclipseJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, Programs.warning);
+        assertTrue(handler.getWarningCount() == 1);
+        assertTrue(handler.getErrorCount() == 0);
+    }    
+}

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java?rev=232412&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/groovy/GroovyJavaCompilerTestCase.java
Fri Aug 12 19:49:43 2005
@@ -0,0 +1,15 @@
+package org.apache.commons.jci.compilers.groovy;
+
+import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
+
+
+public final class GroovyJavaCompilerTestCase extends AbstractCompilerTestCase {
+    public void testSimpleCompilation() throws Exception {
+    }
+    
+    public void testCompilationError() throws Exception {
+    }
+
+    public void testCompilationWarning() throws Exception {
+    }
+}

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java?rev=232412&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/compilers/janino/JaninoJavaCompilerTestCase.java
Fri Aug 12 19:49:43 2005
@@ -0,0 +1,30 @@
+package org.apache.commons.jci.compilers.janino;
+
+import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
+import org.apache.commons.jci.compilers.JavaCompiler;
+import org.apache.commons.jci.compilers.Programs;
+import org.apache.commons.jci.problems.CompilationProblemHandler;
+
+
+public final class JaninoJavaCompilerTestCase extends AbstractCompilerTestCase {
+    public void testSimpleCompilation() throws Exception {
+        final JavaCompiler compiler = new JaninoJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, Programs.simple);
+        assertTrue(handler.getWarningCount() == 0);
+        assertTrue(handler.getErrorCount() == 0);
+    }
+    
+    public void testCompilationError() throws Exception {
+        final JavaCompiler compiler = new JaninoJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, Programs.error);
+        assertTrue(handler.getWarningCount() == 0);
+        assertTrue(handler.getErrorCount() == 1);
+    }
+
+    public void testCompilationWarning() throws Exception {
+        final JavaCompiler compiler = new JaninoJavaCompiler();
+        final CompilationProblemHandler handler = compileWith(compiler, Programs.warning);
+        //assertTrue(handler.getWarningCount() == 1);
+        assertTrue(handler.getErrorCount() == 0);
+    }
+}

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java?rev=232412&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java
Fri Aug 12 19:49:43 2005
@@ -0,0 +1,32 @@
+package org.apache.commons.jci.problems;
+
+import junit.framework.TestCase;
+
+
+public final class CompilationProblemTestCase extends TestCase {
+
+    public void testToString() {
+        CompilationProblem problem;
+        
+        problem = new CompilationProblem(
+                0,
+                "filename",
+                "message",
+                1,
+                2,
+                true
+                );
+        assertTrue("filename (1-2) : message".equals(problem.toString()));
+
+        problem = new CompilationProblem(
+                0,
+                "filename",
+                "message",
+                1,
+                1,
+                true
+                );
+        assertTrue("filename (1) : message".equals(problem.toString()));
+    }
+
+}

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java?rev=232412&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java
Fri Aug 12 19:49:43 2005
@@ -0,0 +1,34 @@
+package org.apache.commons.jci.stores;
+
+import org.apache.commons.jci.AbstractTestCase;
+import org.apache.commons.lang.ArrayUtils;
+
+
+public abstract class AbstractStoreTestCase extends AbstractTestCase {
+
+    protected void testStore(final ResourceStore pStore) {
+        final byte[] data = { 1, 2, 3 };
+        pStore.write("key", data);
+        
+        final byte[] read = pStore.read("key");
+        
+        assertTrue(read != null);
+        assertTrue(ArrayUtils.isEquals(data, read));
+    }
+
+    protected void testRemove(final ResourceStore pStore) {
+        final byte[] data = { 1, 2, 3 };
+        pStore.write("key", data);
+        
+        final byte[] read = pStore.read("key");
+        
+        assertTrue(read != null);
+        assertTrue(ArrayUtils.isEquals(data, read));
+
+        pStore.remove("key");
+
+        final byte[] empty = pStore.read("key");
+        
+        assertTrue(empty == null);
+    }
+}

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java?rev=232412&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java
Fri Aug 12 19:49:43 2005
@@ -0,0 +1,31 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.stores;
+
+
+
+public final class FileResourceStoreTestCase extends AbstractStoreTestCase {
+
+    public void testStore() {
+        final ResourceStore store = new FileResourceStore(directory);
+        super.testStore(store);
+    }
+    
+    public void testRemove() {
+        final ResourceStore store = new FileResourceStore(directory);
+        super.testRemove(store);
+    }
+}

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java?rev=232412&r1=232411&r2=232412&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java
Fri Aug 12 19:49:43 2005
@@ -15,38 +15,18 @@
  */
 package org.apache.commons.jci.stores;
 
-import junit.framework.TestCase;
 
 
-public final class MemoryResourceStoreTestCase extends TestCase {
+public final class MemoryResourceStoreTestCase extends AbstractStoreTestCase {
 
-    public void testStoring() {
+    public void testStore() {
         final ResourceStore store = new MemoryResourceStore();
-
-        final byte[] data = { 1, 2, 3 };
-        store.write("key", data);
-        
-        final byte[] read = store.read("key");
-        
-        assertTrue(read == data);
-        assertTrue(read.equals(data));
+        super.testStore(store);
+        assertTrue("[key]".equals(store.toString()));
     }
     
-    public void testRemoving() {
+    public void testRemove() {
         final ResourceStore store = new MemoryResourceStore();
-
-        final byte[] data = { 1, 2, 3 };
-        store.write("key", data);
-        
-        final byte[] read = store.read("key");
-        
-        assertTrue(read == data);
-        assertTrue(read.equals(data));
-
-        store.remove("key");
-
-        final byte[] empty = store.read("key");
-        
-        assertTrue(empty == null);
+        super.testRemove(store);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message