You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by tc...@apache.org on 2006/04/25 02:57:53 UTC
svn commit: r396752 [3/3] - in /jakarta/commons/sandbox/jci/trunk: ./
classes/ compilers/ compilers/commons-jci-eclipse/
compilers/commons-jci-eclipse/src/ compilers/commons-jci-eclipse/src/java/
compilers/commons-jci-eclipse/src/java/org/ compilers/co...
Added: jakarta/commons/sandbox/jci/trunk/tests/pom.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/pom.xml?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/pom.xml (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/pom.xml Mon Apr 24 17:57:46 2006
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-tests</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>Jakarta Commons JCI Tests</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-eclipse</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-janino</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-groovy</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-groovy</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+
+ </dependencies>
+</project>
Propchange: jakarta/commons/sandbox/jci/trunk/tests/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/AbstractTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/AbstractTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/AbstractTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/AbstractTestCase.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,129 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import junit.framework.TestCase;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public abstract class AbstractTestCase extends TestCase {
+
+ private final static Log log = LogFactory.getLog(AbstractTestCase.class);
+
+ protected String extension = "java";
+
+ protected File directory;
+
+ /*
+ public void runBare() throws Throwable {
+ try {
+ setUp();
+ runTest();
+ } finally {
+ tearDown();
+ }
+ }
+ */
+
+ protected void setUp() throws Exception {
+ directory = createTempDirectory();
+ assertTrue(directory.exists());
+ assertTrue(directory.isDirectory());
+ }
+
+
+ protected File createDirectory( final String pName ) throws Exception {
+ final File newDirectory = new File(directory, pName);
+ assertTrue(newDirectory.mkdir());
+ assertTrue(newDirectory.exists());
+ assertTrue(newDirectory.isDirectory());
+ 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();
+ if (!parent.exists()) {
+ if (!parent.mkdirs()) {
+ throw new IOException("could not create" + parent);
+ }
+ }
+ log.debug("writing " + file);
+ final FileWriter writer = new FileWriter(file);
+ writer.write(pText);
+ writer.close();
+
+ assertTrue(file.exists());
+ assertTrue(file.isFile());
+
+ return file;
+ }
+
+ protected void delay() {
+ try {
+ Thread.sleep(1500);
+ } catch (final InterruptedException e) {
+ }
+ }
+
+ protected File createTempDirectory() throws IOException {
+ final File tempFile = File.createTempFile("jci", null);
+
+ if (!tempFile.delete()) {
+ throw new IOException();
+ }
+
+ if (!tempFile.mkdir()) {
+ throw new IOException();
+ }
+
+ return tempFile;
+ }
+
+
+ protected void tearDown() throws Exception {
+ FileUtils.deleteDirectory(directory);
+ }
+
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/AbstractTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/AbstractTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,81 @@
+package org.apache.commons.jci;
+
+import org.apache.commons.jci.compilers.JavaCompiler;
+import org.apache.commons.jci.compilers.JavaCompilerFactory;
+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 = JavaCompilerFactory.getInstance().createCompiler("eclipse");
+ 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('.', '/') + ".java";
+ 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
+ );
+ return store.read(pClazzes[0]);
+ }
+
+ public static byte[] compile( final String pClazz, final String pProgramm ) {
+ final JavaCompiler compiler = JavaCompilerFactory.getInstance().createCompiler("eclipse");
+ 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
+ );
+ 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();
+// }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,259 @@
+package org.apache.commons.jci;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.jci.compilers.AbstractCompilerTestCase;
+import org.apache.commons.jci.compilers.JavaSources;
+import org.apache.commons.jci.listeners.CompilingListener;
+import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public final class CompilingClassLoaderTestCase extends AbstractCompilerTestCase {
+
+ private final static Log log = LogFactory.getLog(CompilingClassLoaderTestCase.class);
+
+ private ReloadingClassLoader classloader;
+ private CompilingListener listener;
+ private FilesystemAlterationMonitor fam;
+
+ private final static class BeanUtils {
+
+ public static void setProperty( Object object, String property, Object value) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+ final Class clazz = object.getClass();
+
+ final Method setter = clazz.getMethod("set" + property, new Class[]{ value.getClass()});
+ setter.invoke(object, new Object[]{ value });
+ }
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ classloader = new ReloadingClassLoader(this.getClass().getClassLoader());
+ listener = new CompilingListener(directory);
+ classloader.addListener(listener);
+
+ fam = new FilesystemAlterationMonitor();
+ fam.addListener(listener);
+ fam.start();
+ }
+
+ private void initialCompile() throws Exception {
+ delay();
+ writeFile("jci/Simple.java", JavaSources.simple);
+ writeFile("jci/Extended.java", JavaSources.extended);
+ listener.waitForNotification();
+ }
+
+
+ public void testCompileProblems() throws Exception {
+ delay();
+ writeFile("jci/Simple.java", JavaSources.error);
+ listener.waitForNotification();
+
+ // FIXME
+ }
+
+ public void testCreate() throws Exception {
+ initialCompile();
+
+ final Object simple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(simple.toString()));
+
+ final Object extended = classloader.loadClass("jci.Extended").newInstance();
+ assertTrue("Extended:Simple".equals(extended.toString()));
+ }
+
+ public void testChange() throws Exception {
+ initialCompile();
+
+ final Object simple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(simple.toString()));
+
+ final Object extended = classloader.loadClass("jci.Extended").newInstance();
+ assertTrue("Extended:Simple".equals(extended.toString()));
+
+ delay();
+ writeFile("jci/Simple.java", JavaSources.SIMPLE);
+ listener.waitForNotification();
+
+ final Object SIMPLE = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("SIMPLE".equals(SIMPLE.toString()));
+
+ final Object newExtended = classloader.loadClass("jci.Extended").newInstance();
+ assertTrue("Extended:SIMPLE".equals(newExtended.toString()));
+ }
+
+ public void testDelete() throws Exception {
+ initialCompile();
+
+ final Object simple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(simple.toString()));
+
+ final Object extended = classloader.loadClass("jci.Extended").newInstance();
+ assertTrue("Extended:Simple".equals(extended.toString()));
+
+ delay();
+ assertTrue(new File(directory, "jci/Extended.java").delete());
+ listener.waitForNotification();
+
+ final Object oldSimple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(oldSimple.toString()));
+
+ try {
+ classloader.loadClass("jci.Extended").newInstance();
+ fail();
+ } catch(final ClassNotFoundException e) {
+ assertTrue("jci.Extended".equals(e.getMessage()));
+ }
+
+ delay();
+ FileUtils.deleteDirectory(new File(directory, "jci"));
+ listener.waitForNotification();
+
+ try {
+ classloader.loadClass("jci.Simple").newInstance();
+ fail();
+ } catch(final ClassNotFoundException e) {
+ assertTrue("jci.Simple".equals(e.getMessage()));
+ }
+
+ }
+
+ public void testDeleteDependency() throws Exception {
+ initialCompile();
+
+ final Object simple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(simple.toString()));
+
+ final Object extended = classloader.loadClass("jci.Extended").newInstance();
+ assertTrue("Extended:Simple".equals(extended.toString()));
+
+ delay();
+ assertTrue(new File(directory, "jci/Simple.java").delete());
+ listener.waitForNotification();
+
+ try {
+ classloader.loadClass("jci.Extended").newInstance();
+ fail();
+ } catch(final NoClassDefFoundError e) {
+ assertTrue("jci/Simple".equals(e.getMessage()));
+ }
+
+ }
+
+
+ public void testReference1() throws Exception {
+ delay();
+ writeFile("jci/Foo.java",
+ "package jci;\n" +
+ "\n" +
+ "public class Foo {\n" +
+ " public String toString() {\n" +
+ " return \"foo1\";\n" +
+ " }\n" +
+ "}"
+ );
+ writeFile("jci/Bar.java",
+ "package jci;\n" +
+ "\n" +
+ "public class Bar {\n" +
+ " \n" +
+ " private Foo foo;\n" +
+ " \n" +
+ " public void setFoo( Foo foo) {\n" +
+ " this.foo = foo;\n" +
+ " }\n" +
+ " \n" +
+ " public String toString() {\n" +
+ " return \"bar1\";\n" +
+ " }\n" +
+ "}"
+ );
+ listener.waitForNotification();
+
+ final Object foo1 = classloader.loadClass("jci.Foo").newInstance();
+ assertTrue("foo1".equals(foo1.toString()));
+
+ final Object bar1 = classloader.loadClass("jci.Bar").newInstance();
+ assertTrue("bar1".equals(bar1.toString()));
+
+ BeanUtils.setProperty(bar1, "Foo", foo1);
+
+ delay();
+ writeFile("jci/Foo.java",
+ "package jci;\n" +
+ "\n" +
+ "public class Foo {\n" +
+ " public String toString() {\n" +
+ " return \"foo2\";\n" +
+ " }\n" +
+ "}"
+ );
+ listener.waitForNotification();
+
+ final Object foo2 = classloader.loadClass("jci.Foo").newInstance();
+ assertTrue("foo2".equals(foo2.toString()));
+
+ final Object bar2 = classloader.loadClass("jci.Bar").newInstance();
+ // has not change -> still bar1
+ assertTrue("bar1".equals(bar2.toString()));
+
+ BeanUtils.setProperty(bar2, "Foo", foo2);
+ BeanUtils.setProperty(bar1, "Foo", foo2);
+
+ }
+
+ public void testReference2() throws Exception {
+ delay();
+ writeFile("jci/Foo.java",
+ "package jci;\n" +
+ "\n" +
+ "public class Foo implements org.apache.commons.jci.MyFoo {\n" +
+ " public String toString() {\n" +
+ " return \"foo1\";\n" +
+ " }\n" +
+ "}"
+ );
+ listener.waitForNotification();
+
+ final MyFoo foo1 = (MyFoo) classloader.loadClass("jci.Foo").newInstance();
+ assertTrue("foo1".equals(foo1.toString()));
+
+
+ final MyBar bar1 = new MyBar();
+ bar1.setFoo(foo1);
+
+ delay();
+ writeFile("jci/Foo.java",
+ "package jci;\n" +
+ "\n" +
+ "public class Foo implements org.apache.commons.jci.MyFoo {\n" +
+ " public String toString() {\n" +
+ " return \"foo2\";\n" +
+ " }\n" +
+ "}"
+ );
+ listener.waitForNotification();
+
+ final MyFoo foo2 = (MyFoo) classloader.loadClass("jci.Foo").newInstance();
+ assertTrue("foo2".equals(foo2.toString()));
+
+ bar1.setFoo(foo2);
+ }
+
+
+
+
+ protected void tearDown() throws Exception {
+ fam.removeListener(listener);
+ fam.stop();
+ super.tearDown();
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,11 @@
+package org.apache.commons.jci;
+
+
+public class MyBar {
+
+ private MyFoo foo;
+
+ public void setFoo( MyFoo foo) {
+ this.foo = foo;
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyFoo.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyFoo.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyFoo.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyFoo.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,5 @@
+package org.apache.commons.jci;
+
+
+public interface MyFoo {
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyFoo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyFoo.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,178 @@
+/*
+ * 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;
+
+import java.io.File;
+import org.apache.commons.jci.compilers.JavaSources;
+import org.apache.commons.jci.listeners.ReloadingListener;
+import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public final class ReloadingClassLoaderTestCase extends AbstractTestCase {
+
+ private final static Log log = LogFactory.getLog(ReloadingClassLoaderTestCase.class);
+
+ private ReloadingClassLoader classloader;
+ private ReloadingListener listener;
+ private FilesystemAlterationMonitor fam;
+
+ private final byte[] clazzSimple;
+ private final byte[] clazzSIMPLE;
+ private final byte[] clazzExtended;
+
+ public ReloadingClassLoaderTestCase() {
+ clazzSimple = CompilerUtils.compile("jci.Simple", JavaSources.simple);
+ clazzSIMPLE = CompilerUtils.compile("jci.Simple", JavaSources.SIMPLE);
+ clazzExtended = CompilerUtils.compile(
+ new String[] { "jci.Extended", "jci.Simple" },
+ new String[] { JavaSources.extended, JavaSources.simple }
+ );
+ assertTrue(clazzSimple.length > 0);
+ assertTrue(clazzSIMPLE.length > 0);
+ assertTrue(clazzExtended.length > 0);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ classloader = new ReloadingClassLoader(this.getClass().getClassLoader());
+ listener = new ReloadingListener(directory);
+
+ // listener.addListener(classloader);
+ classloader.addListener(listener);
+
+ fam = new FilesystemAlterationMonitor();
+ fam.addListener(listener);
+ fam.start();
+ }
+
+ public void testCreate() throws Exception {
+ listener.waitForCheck();
+
+ log.debug("creating class");
+
+ delay();
+ writeFile("jci/Simple.class", clazzSimple);
+ listener.waitForCheck();
+
+ final Object simple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(simple.toString()));
+ }
+
+ public void testChange() throws Exception {
+ listener.waitForCheck();
+
+ log.debug("creating class");
+
+ delay();
+ writeFile("jci/Simple.class", clazzSimple);
+ listener.waitForCheck();
+
+ final Object simple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(simple.toString()));
+
+ log.debug("changing class");
+
+ delay();
+ writeFile("jci/Simple.class", clazzSIMPLE);
+ listener.waitForNotification();
+
+ final Object SIMPLE = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("SIMPLE".equals(SIMPLE.toString()));
+ }
+
+ public void testDelete() throws Exception {
+ listener.waitForCheck();
+
+ log.debug("creating class");
+
+ delay();
+ writeFile("jci/Simple.class", clazzSimple);
+ listener.waitForCheck();
+
+ final Object simple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(simple.toString()));
+
+ log.debug("deleting class");
+
+ assertTrue(new File(directory, "jci/Simple.class").delete());
+
+ listener.waitForNotification();
+
+ try {
+ classloader.loadClass("jci.Simple").newInstance();
+ fail();
+ } catch(final ClassNotFoundException e) {
+ assertTrue("jci.Simple".equals(e.getMessage()));
+ }
+ }
+
+ public void testDeleteDependency() throws Exception {
+ listener.waitForCheck();
+
+ log.debug("creating classes");
+
+ delay();
+ writeFile("jci/Simple.class", clazzSimple);
+ writeFile("jci/Extended.class", clazzExtended);
+ listener.waitForCheck();
+
+ final Object simple = classloader.loadClass("jci.Simple").newInstance();
+ assertTrue("Simple".equals(simple.toString()));
+
+ final Object extended = classloader.loadClass("jci.Extended").newInstance();
+ assertTrue("Extended:Simple".equals(extended.toString()));
+
+ log.debug("deleting class dependency");
+
+ assertTrue(new File(directory, "jci/Simple.class").delete());
+
+ listener.waitForNotification();
+
+ try {
+ classloader.loadClass("jci.Extended").newInstance();
+ fail();
+ } catch(final NoClassDefFoundError e) {
+ assertTrue("jci/Simple".equals(e.getMessage()));
+ }
+ }
+
+ public void testClassNotFound() {
+ try {
+ classloader.loadClass("bla");
+ fail();
+ } catch(final ClassNotFoundException e) {
+ log.info(e.getMessage());
+ }
+ }
+
+ public void testDelegation() {
+ classloader.clearAssertionStatus();
+ classloader.setClassAssertionStatus("org.apache.commons.jci.ReloadingClassLoader",true);
+ classloader.setDefaultAssertionStatus(false);
+ classloader.setPackageAssertionStatus("org.apache.commons.jci", true);
+ // FIXME: compare with delegation
+ }
+
+ protected void tearDown() throws Exception {
+ fam.removeListener(listener);
+ fam.stop();
+ super.tearDown();
+ }
+
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,33 @@
+package org.apache.commons.jci.compilers;
+
+import java.io.File;
+import org.apache.commons.jci.AbstractTestCase;
+import org.apache.commons.jci.readers.FileResourceReader;
+import org.apache.commons.jci.stores.FileResourceStore;
+
+
+public abstract class AbstractCompilerTestCase extends AbstractTestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected CompilationResult 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);
+
+ writeFile("src/jci/Simple." + extension, pSource);
+
+ return pCompiler.compile(
+ new String[] { "jci.Simple"},
+ src,
+ dst
+ );
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/GroovySources.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/GroovySources.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/GroovySources.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/GroovySources.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,48 @@
+package org.apache.commons.jci.compilers;
+
+
+public interface GroovySources {
+
+ 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 clss Simple { \n"
+ + " public String toString() { \n"
+ + " return 1; \n"
+ + " } \n"
+ + "} \n";
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/GroovySources.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/GroovySources.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaCompilerFactoryTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaCompilerFactoryTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaCompilerFactoryTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaCompilerFactoryTestCase.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,28 @@
+/*
+ * 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.compilers;
+
+import junit.framework.TestCase;
+
+
+public final class JavaCompilerFactoryTestCase extends TestCase {
+ public void testEclipseCompilerCreation() {
+ }
+ public void testJaninoCompilerCreation() {
+ }
+ public void testGroovyCompilerCreation() {
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaCompilerFactoryTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaCompilerFactoryTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaSources.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaSources.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaSources.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaSources.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,60 @@
+package org.apache.commons.jci.compilers;
+
+
+public interface JavaSources {
+
+ 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 warning1 =
+ "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 warning2 =
+ "package jci;\n"
+ + "public class Simple { \n"
+ + " public static void generate() { \n"
+ + " }\n"
+ + " public static void generate2() { \n"
+ + " generate();\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";
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaSources.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/compilers/JavaSources.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,311 @@
+/*
+ * 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.monitor;
+
+import java.io.File;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.jci.AbstractTestCase;
+import org.apache.commons.jci.listeners.NotifyingListener;
+import org.apache.commons.jci.stores.ResourceStore;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+
+public final class FilesystemAlterationMonitorTestCase extends AbstractTestCase {
+
+ private final static Log log = LogFactory.getLog(FilesystemAlterationMonitorTestCase.class);
+
+ private FilesystemAlterationMonitor fam;
+ private MyFilesystemAlterationListener listener;
+
+ private class MyFilesystemAlterationListener extends NotifyingListener {
+ private int started;
+ private int stopped;
+ private int createdFiles;
+ private int changedFiles;
+ private int deletedFiles;
+ private int createdDirs;
+ private int changedDirs;
+ private int deletedDirs;
+ private boolean changed;
+
+ public MyFilesystemAlterationListener(final File pRepository) {
+ super(pRepository);
+ }
+
+ public ResourceStore getStore() {
+ return null;
+ }
+
+ public int getChangedDirs() {
+ return changedDirs;
+ }
+ public int getChangedFiles() {
+ return changedFiles;
+ }
+ public int getCreatedDirs() {
+ return createdDirs;
+ }
+ public int getCreatedFiles() {
+ return createdFiles;
+ }
+ public int getDeletedDirs() {
+ return deletedDirs;
+ }
+ public int getDeletedFiles() {
+ return deletedFiles;
+ }
+ public int getStarted() {
+ return started;
+ }
+ public int getStopped() {
+ return stopped;
+ }
+
+ public void onStart() {
+ changed = false;
+ ++started;
+ log.debug("onStart");
+ }
+ public void onStop() {
+ ++stopped;
+ log.debug("onStop");
+
+ checked(changed);
+ }
+ public void onCreateFile( final File file ) {
+ ++createdFiles;
+ changed = true;
+ log.debug("onCreateFile " + file);
+ }
+ public void onChangeFile( final File file ) {
+ ++changedFiles;
+ changed = true;
+ log.debug("onChangeFile " + file);
+ }
+ public void onDeleteFile( final File file ) {
+ ++deletedFiles;
+ changed = true;
+ log.debug("onDeleteFile " + file);
+ }
+ public void onCreateDirectory( final File file ) {
+ ++createdDirs;
+ changed = true;
+ log.debug("onCreateDirectory " + file);
+ }
+ public void onChangeDirectory( final File file ) {
+ ++changedDirs;
+ changed = true;
+ log.debug("onChangeDirectory " + file);
+ }
+ public void onDeleteDirectory( final File file ) {
+ ++deletedDirs;
+ changed = true;
+ log.debug("onDeleteDirectory " + file);
+ }
+ }
+
+ private void start() throws Exception {
+ fam = new FilesystemAlterationMonitor();
+ listener = new MyFilesystemAlterationListener(directory);
+ fam.addListener(listener);
+ fam.start();
+ listener.waitForFirstCheck();
+ }
+
+ private void stop() {
+ fam.stop();
+ }
+
+ public void testListenerDoublication() throws Exception {
+ fam = new FilesystemAlterationMonitor();
+ listener = new MyFilesystemAlterationListener(directory);
+
+ fam.addListener(listener);
+ log.debug(fam);
+ assertTrue(fam.getListeners().size() == 1);
+
+ fam.addListener(listener);
+ log.debug(fam);
+ assertTrue(fam.getListeners().size() == 1);
+ }
+
+ public void testDirectoryDoublication() throws Exception {
+ fam = new FilesystemAlterationMonitor();
+
+ fam.addListener(new MyFilesystemAlterationListener(directory));
+ log.debug(fam);
+ assertTrue(fam.getListenersFor(directory).size() == 1);
+
+ fam.addListener(new MyFilesystemAlterationListener(directory));
+ log.debug(fam);
+ assertTrue(fam.getListenersFor(directory).size() == 2);
+ }
+
+ public void testListener() throws Exception {
+ start();
+ log.debug(fam);
+ fam.removeListener(listener);
+ log.debug(fam);
+ stop();
+ }
+
+ public void testCreateFileDetection() throws Exception {
+ start();
+
+ delay();
+
+ writeFile("file", "file");
+
+ listener.waitForNotification();
+
+ assertTrue(listener.createdFiles == 1);
+
+ stop();
+ }
+
+ public void testCreateDirectoryDetection() throws Exception {
+ start();
+
+ delay();
+
+ createDirectory("dir");
+
+ listener.waitForNotification();
+
+ assertTrue(listener.createdDirs == 1);
+
+ stop();
+ }
+
+ public void testDeleteFileDetection() throws Exception {
+ start();
+
+ delay();
+
+ final File file = writeFile("file", "file");
+
+ listener.waitForNotification();
+
+ assertTrue(listener.createdFiles == 1);
+
+ file.delete();
+ assertTrue(!file.exists());
+
+ listener.waitForNotification();
+
+ assertTrue(listener.deletedFiles == 1);
+
+ stop();
+ }
+
+ public void testDeleteDirectoryDetection() throws Exception {
+ start();
+
+ delay();
+
+ final File dir = createDirectory("dir");
+ createDirectory("dir/sub");
+
+ listener.waitForNotification();
+
+ assertTrue(listener.createdDirs == 2);
+
+ delay();
+
+ FileUtils.deleteDirectory(dir);
+ assertTrue(!dir.exists());
+
+ listener.waitForNotification();
+
+ assertTrue(listener.deletedDirs == 2);
+
+ stop();
+ }
+
+ public void testModifyFileDetection() throws Exception {
+ start();
+
+ delay();
+
+ writeFile("file", "file");
+
+ listener.waitForNotification();
+
+ assertTrue(listener.createdFiles == 1);
+
+ delay();
+
+ writeFile("file", "changed file");
+
+ listener.waitForNotification();
+
+ assertTrue(listener.changedFiles == 1);
+
+ stop();
+ }
+
+ public void testCreatingLocalDirectoryChangesLastModified() throws Exception {
+ final long modified = directory.lastModified();
+
+ delay();
+
+ createDirectory("directory");
+
+ assertTrue(directory.lastModified() != modified);
+ }
+
+ public void testCreatingLocalFileChangesLastModified() throws Exception {
+ final long modified = directory.lastModified();
+
+ delay();
+
+ writeFile("file", "file");
+
+ assertTrue(directory.lastModified() != modified);
+ }
+
+ public void testCreatingSubDirectoryChangesLastModified() throws Exception {
+ createDirectory("dir");
+
+ final long modified = directory.lastModified();
+
+ delay();
+
+ createDirectory("dir/sub");
+
+ assertTrue(directory.lastModified() == modified);
+ }
+
+ public void testCreatingFileInSubDirectoryChangesLastModified() throws Exception {
+ createDirectory("dir");
+
+ final long modified = directory.lastModified();
+
+ delay();
+
+ writeFile("dir/file", "file");
+
+ assertTrue(directory.lastModified() == modified);
+ }
+
+ public void testInterval() throws Exception {
+ start();
+ fam.setInterval(100);
+ stop();
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,19 @@
+package org.apache.commons.jci.readers;
+
+import org.apache.commons.jci.AbstractTestCase;
+
+
+public final class FileResourceReaderTestCase extends AbstractTestCase {
+ public void testGetContent() throws Exception {
+ final ResourceReader reader = new FileResourceReader(directory);
+ writeFile("test", "test");
+
+ assertTrue(reader.isAvailable("test"));
+ final char[] content = reader.getContent("test");
+ assertTrue(content != null);
+ assertTrue("test".equals(new String(content)));
+
+ assertTrue(!reader.isAvailable("bla"));
+ assertTrue(reader.getContent("bla") == null);
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java Mon Apr 24 17:57:46 2006
@@ -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);
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/AbstractStoreTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java Mon Apr 24 17:57:46 2006
@@ -0,0 +1,34 @@
+/*
+ * 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 testFailedStore() {
+ }
+
+ public void testRemove() {
+ final ResourceStore store = new FileResourceStore(directory);
+ super.testRemove(store);
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/FileResourceStoreTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java Mon Apr 24 17:57:46 2006
@@ -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 MemoryResourceStoreTestCase extends AbstractStoreTestCase {
+
+ public void testStore() {
+ final ResourceStore store = new MemoryResourceStore();
+ super.testStore(store);
+ }
+
+ public void testRemove() {
+ final ResourceStore store = new MemoryResourceStore();
+ super.testRemove(store);
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/MemoryResourceStoreTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/TransactinonalResourceStoreTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/TransactinonalResourceStoreTestCase.java?rev=396752&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/TransactinonalResourceStoreTestCase.java (added)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/TransactinonalResourceStoreTestCase.java Mon Apr 24 17:57:46 2006
@@ -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 TransactinonalResourceStoreTestCase extends AbstractStoreTestCase {
+
+ public void testStore() {
+ final TransactionalResourceStore store = new TransactionalResourceStore(new MemoryResourceStore());
+ super.testStore(store);
+ }
+
+ public void testRemove() {
+ final TransactionalResourceStore store = new TransactionalResourceStore(new MemoryResourceStore());
+ super.testRemove(store);
+ }
+}
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/TransactinonalResourceStoreTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/stores/TransactinonalResourceStoreTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org