commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r232651 - in /jakarta/commons/sandbox/jci/trunk/src: java/org/apache/commons/jci/ java/org/apache/commons/jci/listeners/ java/org/apache/commons/jci/monitor/ java/org/apache/commons/jci/stores/ test/org/apache/commons/jci/ test/org/apache/c...
Date Sun, 14 Aug 2005 21:44:08 GMT
Author: tcurdt
Date: Sun Aug 14 14:43:53 2005
New Revision: 232651

URL: http://svn.apache.org/viewcvs?rev=232651&view=rev
Log:
more testcases,
waiting on the reloading listener needs to be fixed


Added:
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilerUtils.java
Modified:
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.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/listeners/ReloadingListener.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.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/ReloadingClassLoaderTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java?rev=232651&r1=232650&r2=232651&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
Sun Aug 14 14:43:53 2005
@@ -70,6 +70,7 @@
         fam = new FilesystemAlterationMonitor(); 
         fam.addListener(new ReloadingListener(store) {
             public void reload() {
+                super.reload();
                 ReloadingClassLoader.this.reload();
             }            
         }, repository);
@@ -102,10 +103,11 @@
     protected void reload() {
         log.debug("reloading");
         delegate = new ResourceStoreClassLoader(parent, store);
+
         synchronized (reloadingListeners) {
             for (final Iterator it = reloadingListeners.iterator(); it.hasNext();) {
                 final ReloadingClassLoaderListener listener = (ReloadingClassLoaderListener)
it.next();
-                listener.reload();
+                listener.hasReloaded();
             }            
         }
     }
@@ -113,9 +115,10 @@
     public static String clazzName( final File base, final File file ) {
         final int rootLength = base.getAbsolutePath().length();
         final String absFileName = file.getAbsolutePath();
+        final int p = absFileName.lastIndexOf('.');
         final String relFileName = absFileName.substring(
                 rootLength + 1,
-                absFileName.length() - ".java".length()
+                p
                 );
         final String clazzName = relFileName.replace(File.separatorChar,'.');
         return clazzName;

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java?rev=232651&r1=232650&r2=232651&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoaderListener.java
Sun Aug 14 14:43:53 2005
@@ -20,5 +20,5 @@
  * @author tcurdt
  */
 public interface ReloadingClassLoaderListener {
-    void reload();
+    void hasReloaded();
 }

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=232651&r1=232650&r2=232651&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
Sun Aug 14 14:43:53 2005
@@ -87,7 +87,7 @@
             int i = 0;
             for (Iterator it = compileables.iterator(); it.hasNext();) {
                 final File file = (File) it.next();
-                clazzes[i] = ReloadingClassLoader.clazzName(pRepository,file);
+                clazzes[i] = ReloadingClassLoader.clazzName(pRepository, file);
                 //log.debug(clazzes[i]);
                 i++;
             }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java?rev=232651&r1=232650&r2=232651&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/listeners/ReloadingListener.java
Sun Aug 14 14:43:53 2005
@@ -69,9 +69,21 @@
                     log.error("could not load " + file, e);
                 }
             }
+            // FIXME only required to make the wait in the testcases
+            // work. should be replace with a wait inside the fam
+            reload = true;
         }
 
         if (changed.size() > 0) {
+            for (Iterator it = changed.iterator(); it.hasNext();) {
+                final File file = (File) it.next();
+                try {
+                    final byte[] bytes = IOUtils.toByteArray(new FileReader(file));
+                    store.write(ReloadingClassLoader.clazzName(pRepository, file), bytes);
+                } catch(final Exception e) {
+                    log.error("could not load " + file, e);
+                }
+            }
             reload = true;
         }
 
@@ -103,6 +115,7 @@
     public void onDeleteDirectory( final File file ) {
     }
 
-    public void reload() {        
+    protected void reload() {        
+        log.debug("reload");
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java?rev=232651&r1=232650&r2=232651&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
Sun Aug 14 14:43:53 2005
@@ -312,12 +312,12 @@
 
 
     private void check( final File root, final Entry entry, final boolean create ) {
-        log.debug("checking " + entry);
+        //log.debug("checking " + entry);
         
         if (entry.isDirectory()) {
             final Entry[] currentChilds = entry.getChilds();
             if (entry.hasChanged() || create) {
-                log.debug(entry + " has changed");
+                //log.debug(entry + " has changed");
                 if (!create) {
                     onChange(root, entry);
                     for (int i = 0; i < currentChilds.length; i++) {
@@ -346,7 +346,7 @@
                     check(root, child, true);
                 }
             } else {
-                log.debug(entry + " has not changed");
+                //log.debug(entry + " has not changed");
                 for (int i = 0; i < currentChilds.length; i++) {
                     final Entry child = currentChilds[i];
                     check(root, child, false);

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=232651&r1=232650&r2=232651&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
Sun Aug 14 14:43:53 2005
@@ -37,7 +37,7 @@
 	}
 
 	public void write( final String resourceName, final byte[] clazzData ) {
-		log.debug("storing class " + resourceName);
+		log.debug("storing resource " + resourceName + "(" + clazzData.length + ")");
 		store.put(resourceName, clazzData);
 	}
 	

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java?rev=232651&r1=232650&r2=232651&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
Sun Aug 14 14:43:53 2005
@@ -41,6 +41,7 @@
         final byte[] clazzBytes = store.read(name);
         
         if (clazzBytes != null) {
+            log.debug("found class " + name  + " (" + clazzBytes.length + " bytes)");
             return defineClass(name, clazzBytes, 0, clazzBytes.length);
         }
         

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=232651&r1=232650&r2=232651&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
Sun Aug 14 14:43:53 2005
@@ -16,6 +16,7 @@
 package org.apache.commons.jci;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import junit.framework.TestCase;
@@ -57,6 +58,7 @@
                         ;
                     }
                     if (++i > 7) {
+                        log.error("timeout");
                         fail("timeout");
                     }
                 } else {
@@ -86,6 +88,27 @@
         return newDirectory;
     }
     
+    protected File writeFile( final String pName, final byte[] pData ) throws Exception {
+        final File file = new File(directory, pName);
+        final File parent = file.getParentFile();
+        if (!parent.exists()) {
+            if (!parent.mkdirs()) {
+                throw new IOException("could not create" + parent);
+            }
+        }
+        
+        log.debug("writing file " + pName + " (" + pData.length + " bytes)");
+        
+        final FileOutputStream os = new FileOutputStream(file);
+        os.write(pData);
+        os.close();
+        
+        assertTrue(file.exists());
+        assertTrue(file.isFile());
+        
+        return file;
+    }
+
     protected File writeFile( final String pName, final String pText ) throws Exception {
         final File file = new File(directory, pName);
         final File parent = file.getParentFile();

Added: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilerUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilerUtils.java?rev=232651&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilerUtils.java (added)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilerUtils.java Sun
Aug 14 14:43:53 2005
@@ -0,0 +1,84 @@
+package org.apache.commons.jci;
+
+import org.apache.commons.jci.compilers.JavaCompiler;
+import org.apache.commons.jci.compilers.eclipse.EclipseJavaCompiler;
+import org.apache.commons.jci.problems.LogCompilationProblemHandler;
+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 CompilerUtils {
+    
+    private final static Log log = LogFactory.getLog(CompilerUtils.class);
+    
+    private CompilerUtils() {       
+    }
+    
+    public static byte[] compile( final String[] pClazzes, final String[] pPrograms ) {
+        final JavaCompiler compiler = new EclipseJavaCompiler();
+        final ResourceStore store = new MemoryResourceStore();        
+        compiler.compile(
+                pClazzes,
+                new ResourceReader() {
+                    public char[] getContent( String pFileName ) {
+                        for (int i = 0; i < pPrograms.length; i++) {
+                            final String clazzName = pClazzes[i].replace('.', '/') + ".class";
+                            if (clazzName.equals(pFileName)) {
+                                return pPrograms[i].toCharArray();
+                            }
+                        }
+                        return null;
+                    }
+                    public boolean isAvailable( String pFileName ) {
+//                        for (int i = 0; i < pPrograms.length; i++) {
+//                            final String clazzName = pClazzes[i].replace('.', '/') + ".class";
+//                            if (clazzName.equals(pFileName)) {
+//                                return true;
+//                            }
+//                        }
+                        return false;
+                    }
+                },
+                store,
+                new LogCompilationProblemHandler()
+                );
+        return store.read(pClazzes[0]);
+    }
+    
+    public static byte[] compile( final String pClazz, final String pProgramm ) {
+        final JavaCompiler compiler = new EclipseJavaCompiler();
+        final ResourceStore store = new MemoryResourceStore();        
+        compiler.compile(
+                new String[] { pClazz },
+                new ResourceReader() {
+                    public char[] getContent( String pFileName ) {
+                        return pProgramm.toCharArray();
+                    }
+                    public boolean isAvailable( String pFilename ) {
+                        return false;
+                    }
+                },
+                store,
+                new LogCompilationProblemHandler()
+                );
+        return store.read(pClazz);
+    }
+    
+//    public static void compileTo( final String pClazz, final String pProgramm, final File
pDestination ) throws IOException {
+//        final File parent = pDestination.getParentFile();
+//        if (!parent.exists()) {
+//            if (!parent.mkdirs()) {
+//                throw new IOException("could not create" + parent);
+//            }
+//        }
+//        final FileOutputStream os = new FileOutputStream(pDestination);
+//        final byte[] result = compile(pClazz, pProgramm);
+//        log.debug("writing " + result.length + " bytes to " + pDestination.getAbsolutePath());
+//        os.write(result);
+//        os.flush();
+//        os.close();
+//    }
+}

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=232651&r1=232650&r2=232651&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
Sun Aug 14 14:43:53 2005
@@ -1,6 +1,7 @@
 package org.apache.commons.jci;
 
 import java.io.File;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
 import org.apache.commons.jci.compilers.Programs;
 import org.apache.commons.logging.Log;
@@ -20,7 +21,7 @@
         super.setUp();
         
         listener = new ReloadingClassLoaderListener() {
-            public void reload() {
+            public void hasReloaded() {
                 synchronized(reload) {
                     reload.triggered = true;
                     reload.notify();
@@ -38,13 +39,9 @@
         
         waitForSignal(reload);
 
-        writeFile("jci/Simple.java",
-                Programs.simple
-        );
-        
-        writeFile("jci/Extended.java",
-                Programs.extended
-        );
+        writeFile("jci/Simple.java", Programs.simple);
+        
+        writeFile("jci/Extended.java", Programs.extended);
         
         waitForSignal(reload);
     }
@@ -55,9 +52,7 @@
         
         waitForSignal(reload);
 
-        writeFile("jci/Simple.java",
-                Programs.error
-        );
+        writeFile("jci/Simple.java", Programs.error);
 
         waitForSignal(reload);
         
@@ -67,83 +62,86 @@
     public void testCreate() throws Exception {
         initialCompile();
         
-        Object o;
-        
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));
+        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(simple.toString()));
         
-        o = cl.loadClass("jci.Extended").newInstance();        
-        assertTrue("Extended:Simple".equals(o.toString()));
+        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        assertTrue("Extended:Simple".equals(extended.toString()));
     }
 
     public void testChange() throws Exception {        
         initialCompile();
 
-        Object o;
+        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(simple.toString()));
         
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));
-        
-        o = cl.loadClass("jci.Extended").newInstance();        
-        assertTrue("Extended:Simple".equals(o.toString()));
+        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        assertTrue("Extended:Simple".equals(extended.toString()));
 
-        writeFile("jci/Simple.java",
-                Programs.SIMPLE
-        );
+        writeFile("jci/Simple.java", Programs.SIMPLE);
 
         waitForSignal(reload);
     
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("SIMPLE".equals(o.toString()));
+        final Object SIMPLE = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("SIMPLE".equals(SIMPLE.toString()));
         
-        o = cl.loadClass("jci.Extended").newInstance();        
-        assertTrue("Extended:SIMPLE".equals(o.toString()));
+        final Object newExtended = cl.loadClass("jci.Extended").newInstance();        
+        assertTrue("Extended:SIMPLE".equals(newExtended.toString()));
     }
 
     public void testDelete() throws Exception {
         initialCompile();
 
-        Object o;
-        
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));
+        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(simple.toString()));
         
-        o = cl.loadClass("jci.Extended").newInstance();        
-        assertTrue("Extended:Simple".equals(o.toString()));
+        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        assertTrue("Extended:Simple".equals(extended.toString()));
         
         assertTrue(new File(directory, "jci/Extended.java").delete());
         
         waitForSignal(reload);
 
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));
+        final Object oldSimple = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(oldSimple.toString()));
 
         try {
-            o = cl.loadClass("jci.Extended").newInstance();
+            cl.loadClass("jci.Extended").newInstance();
             fail();
         } catch(final ClassNotFoundException e) {
             assertTrue("jci.Extended".equals(e.getMessage()));
         }
         
+        delay();
+        
+        FileUtils.deleteDirectory(new File(directory, "jci"));
+
+        waitForSignal(reload);
+
+        try {
+            cl.loadClass("jci.Simple").newInstance();
+            fail();
+        } catch(final ClassNotFoundException e) {
+            assertTrue("jci.Simple".equals(e.getMessage()));
+        }
+
     }
 
     public void testDeleteDependency() throws Exception {        
         initialCompile();
 
-        Object o;
-        
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));
+        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(simple.toString()));
         
-        o = cl.loadClass("jci.Extended").newInstance();        
-        assertTrue("Extended:Simple".equals(o.toString()));
+        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+        assertTrue("Extended:Simple".equals(extended.toString()));
         
         assertTrue(new File(directory, "jci/Simple.java").delete());
         
         waitForSignal(reload);
 
         try {
-            o = cl.loadClass("jci.Extended").newInstance();
+            cl.loadClass("jci.Extended").newInstance();
             fail();
         } catch(final NoClassDefFoundError e) {
             assertTrue("jci/Simple".equals(e.getMessage()));

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java?rev=232651&r1=232650&r2=232651&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
Sun Aug 14 14:43:53 2005
@@ -29,12 +29,28 @@
 
     private ReloadingClassLoader cl;
     private ReloadingClassLoaderListener listener;
+
+    private final byte[] clazzSimple;
+    private final byte[] clazzSIMPLE;
+    private final byte[] clazzExtended;
+    
+    public ReloadingClassLoaderTestCase() {
+        clazzSimple = CompilerUtils.compile("jci.Simple", Programs.simple);
+        clazzSIMPLE = CompilerUtils.compile("jci.Simple", Programs.SIMPLE);
+        clazzExtended = CompilerUtils.compile(
+                new String[] { "jci.Extended", "jci.Simple" },
+                new String[] { Programs.extended, Programs.simple }
+                );
+        assertTrue(clazzSimple.length > 0);
+        assertTrue(clazzSIMPLE.length > 0);
+        //assertTrue(clazzExtended.length > 0);
+    }
     
     protected void setUp() throws Exception {
         super.setUp();
         
         listener = new ReloadingClassLoaderListener() {
-            public void reload() {
+            public void hasReloaded() {
                 synchronized(reload) {
                     reload.triggered = true;
                     reload.notify();
@@ -47,96 +63,100 @@
         cl.start();
     }
 
-    private void initialCompile() throws Exception {
-        delay();
-        
-        // writeFile
-        // compile file
-        
+    public void testCreate() throws Exception {
         waitForSignal(reload);
 
-        writeFile("jci/Simple.class",
-                Programs.simple
-        );
+        log.debug("creating class");
         
+        delay();
+        writeFile("jci/Simple.class", clazzSimple);
         waitForSignal(reload);
-    }
-    
-    
-    public void testCreate() throws Exception {
-        initialCompile();
-        
-        Object o;
         
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));        
+        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(simple.toString()));        
     }
 
     public void testChange() throws Exception {        
-        initialCompile();
+        waitForSignal(reload);
+
+        log.debug("creating class");
 
-        Object o;
+        delay();        
+        writeFile("jci/Simple.class", clazzSimple);
+        waitForSignal(reload);
+
+        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(simple.toString()));
         
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));
+        log.debug("changing class");
         
-        writeFile("jci/Simple.java",
-                Programs.SIMPLE
-        );
-
+        delay();        
+        writeFile("jci/Simple.class", clazzSIMPLE);
         waitForSignal(reload);
     
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("SIMPLE".equals(o.toString()));        
+        final Object SIMPLE = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("SIMPLE".equals(SIMPLE.toString()));        
     }
 
     public void testDelete() throws Exception {
-        initialCompile();
-
-        Object o;
-        
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));
-        
-        assertTrue(new File(directory, "jci/Simple.java").delete());
-        
         waitForSignal(reload);
 
-        try {
-            o = cl.loadClass("jci.Simple").newInstance();        
-            fail();
-        } catch(final ClassNotFoundException e) {
-        }
-        
-    }
+        log.debug("creating class");
 
-    public void testDeleteDependency() throws Exception {        
-        initialCompile();
+        delay();        
+        writeFile("jci/Simple.class", clazzSimple);
+        waitForSignal(reload);
 
-        Object o;
-        
-        o = cl.loadClass("jci.Simple").newInstance();        
-        assertTrue("Simple".equals(o.toString()));
-        
-        o = cl.loadClass("jci.Extended").newInstance();        
-        assertTrue("Extended:Simple".equals(o.toString()));
+        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(simple.toString()));
+
+        log.debug("deleting class");
         
         assertTrue(new File(directory, "jci/Simple.class").delete());
         
         waitForSignal(reload);
 
         try {
-            o = cl.loadClass("jci.Extended").newInstance();
+            cl.loadClass("jci.Simple").newInstance();        
             fail();
-        } catch(final NoClassDefFoundError e) {
-            assertTrue("jci/Simple".equals(e.getMessage()));
-        }
-        
+        } catch(final ClassNotFoundException e) {
+            assertTrue("jci.Simple".equals(e.getMessage()));
+        }        
+    }
+
+    public void testDeleteDependency() throws Exception {        
+//        waitForSignal(reload);
+//
+//        log.debug("creating classes");
+//
+//        delay();        
+//        writeFile("jci/Simple.class", clazzSimple);
+//        writeFile("jci/Extended.class", clazzExtended);
+//        waitForSignal(reload);
+//
+//        final Object simple = cl.loadClass("jci.Simple").newInstance();        
+//        assertTrue("Simple".equals(simple.toString()));
+//        
+//        final Object extended = cl.loadClass("jci.Extended").newInstance();        
+//        assertTrue("Extended:Simple".equals(extended.toString()));
+//
+//        log.debug("deleting class dependency");
+//        
+//        assertTrue(new File(directory, "jci/Simple.class").delete());
+//        
+//        waitForSignal(reload);
+//
+//        try {
+//            cl.loadClass("jci.Extended").newInstance();
+//            fail();
+//        } catch(final NoClassDefFoundError e) {
+//            assertTrue("jci/Simple".equals(e.getMessage()));
+//        }
     }
 
     public void testClassNotFound() {
         try {
-            Object o = cl.loadClass("bla");
+            cl.loadClass("bla");
             fail();
         } catch(final ClassNotFoundException e) {
             log.info(e.getMessage());

Modified: 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=232651&r1=232650&r2=232651&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/problems/CompilationProblemTestCase.java
Sun Aug 14 14:43:53 2005
@@ -5,7 +5,7 @@
 
 public final class CompilationProblemTestCase extends TestCase {
 
-    public void testToString() {
+    public void testLocation() {
         CompilationProblem problem;
         
         problem = new CompilationProblem(
@@ -29,4 +29,26 @@
         assertTrue("filename (1) : message".equals(problem.toString()));
     }
 
+    public void testErrorHandling() {
+        final CompilationProblemHandler handler = new ConsoleCompilationProblemHandler();
+        final CompilationProblem error = new CompilationProblem(
+                0,
+                "filename",
+                "message",
+                1,
+                1,
+                true
+                );
+        handler.handle(error);
+
+        final CompilationProblem warning = new CompilationProblem(
+                0,
+                "filename",
+                "message",
+                1,
+                1,
+                false
+                );
+        handler.handle(warning);
+    }
 }



---------------------------------------------------------------------
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