james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieu...@apache.org
Subject svn commit: r1299470 - in /james/server/trunk/filesystem-api: pom.xml src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java src/test/java/org/apache/james/filesystem/api/mock/MockFileSystem.java
Date Sun, 11 Mar 2012 22:31:29 GMT
Author: ieugen
Date: Sun Mar 11 22:31:29 2012
New Revision: 1299470

URL: http://svn.apache.org/viewvc?rev=1299470&view=rev
Log:
JAMES-1393

- updated tests to juni 4.x style
- added @Override and reformated code
Issue #JAMES-1393 - Upgrate all test suites to junit 4.10

Modified:
    james/server/trunk/filesystem-api/pom.xml
    james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java
    james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/mock/MockFileSystem.java

Modified: james/server/trunk/filesystem-api/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/filesystem-api/pom.xml?rev=1299470&r1=1299469&r2=1299470&view=diff
==============================================================================
--- james/server/trunk/filesystem-api/pom.xml (original)
+++ james/server/trunk/filesystem-api/pom.xml Sun Mar 11 22:31:29 2012
@@ -20,87 +20,78 @@
 <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>
     <parent>
-        <artifactId>james-server</artifactId>
-        <groupId>org.apache.james</groupId>
-        <version>3.0-beta5-SNAPSHOT</version>
-        <relativePath>../pom.xml</relativePath>
+	<artifactId>james-server</artifactId>
+	<groupId>org.apache.james</groupId>
+	<version>3.0-beta5-SNAPSHOT</version>
+	<relativePath>../pom.xml</relativePath>
     </parent>
     <artifactId>james-server-filesystem-api</artifactId>
     <name>Apache James Server Filesystem API</name>
     <properties>
         <!-- OSGI stuff -->
-        <james.osgi.export>
-            org.apache.james.*
-        </james.osgi.export>
-        <james.osgi.import>
-            *
-        </james.osgi.import>
+	<james.osgi.export>
+	    org.apache.james.*
+	</james.osgi.export>
+	<james.osgi.import>
+	    *
+	</james.osgi.import>
     </properties>
     <dependencies>
-        <dependency>
-            <groupId>org.apache.james</groupId>
-            <artifactId>apache-jsieve-manager-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-        </dependency>
+	<dependency>
+	    <groupId>org.apache.james</groupId>
+	    <artifactId>apache-jsieve-manager-api</artifactId>
+	</dependency>
+	<dependency>
+	    <groupId>commons-io</groupId>
+	    <artifactId>commons-io</artifactId>
+	</dependency>
+	<dependency>
+	    <groupId>junit</groupId>
+	    <artifactId>junit</artifactId>
+	</dependency>
     </dependencies>
     <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-jar-plugin</artifactId>
+	<plugins>
+	    <plugin>
+		<groupId>org.apache.maven.plugins</groupId>
+		<artifactId>maven-jar-plugin</artifactId>
                 <!--
                     Inherit configuration from parent pom.
                 -->
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>jar</goal>
+		<executions>
+		    <execution>
+			<goals>
+			    <goal>jar</goal>
                             <!--
                                 Allow tests to be used by other modules.
                                 Parent pom build failure prevents inheritance.
                             -->
-                            <goal>test-jar</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
+			    <goal>test-jar</goal>
+			</goals>
+		    </execution>
+		</executions>
+	    </plugin>
 <!--             TODO Move the SieveFileRepository and SieveFileRepositoryTestCase in
other module - See JSIEVE-86 -->
 <!--             Test are exclude (ported from junit 4.x to 3.x) -->
-            <plugin>
-              <groupId>org.apache.maven.plugins</groupId>
-              <artifactId>maven-surefire-plugin</artifactId>
-              <configuration>
-                <excludes>
-                  <exclude>**/*Test.java</exclude>
-                </excludes>
-              </configuration>
-            </plugin>
-        </plugins>
+	</plugins>
     </build>
     <profiles>
-        <profile>
-            <id>noTest</id>
-            <activation>
-              <activeByDefault>true</activeByDefault>
-            </activation>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-surefire-plugin</artifactId>
-                        <configuration>
-                            <skipTests>true</skipTests>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
+	<profile>
+	    <id>noTest</id>
+	    <activation>
+		<activeByDefault>true</activeByDefault>
+	    </activation>
+	    <build>
+		<plugins>
+		    <plugin>
+			<groupId>org.apache.maven.plugins</groupId>
+			<artifactId>maven-surefire-plugin</artifactId>
+			<configuration>
+			    <skipTests>true</skipTests>
+			</configuration>
+		    </plugin>
+		</plugins>
+	    </build>
+	</profile>
     </profiles>
 </project>

Modified: james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java
URL: http://svn.apache.org/viewvc/james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java?rev=1299470&r1=1299469&r2=1299470&view=diff
==============================================================================
--- james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java
(original)
+++ james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java
Sun Mar 11 22:31:29 2012
@@ -17,49 +17,39 @@
  *   under the License.
  *
  */
-
 package org.apache.james.filesystem.api;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.util.List;
-
-import junit.framework.TestCase;
-
 import org.apache.commons.io.FileUtils;
-import org.apache.james.managesieve.api.DuplicateException;
-import org.apache.james.managesieve.api.DuplicateUserException;
-import org.apache.james.managesieve.api.IsActiveException;
-import org.apache.james.managesieve.api.QuotaExceededException;
-import org.apache.james.managesieve.api.QuotaNotFoundException;
-import org.apache.james.managesieve.api.ScriptNotFoundException;
-import org.apache.james.managesieve.api.ScriptSummary;
-import org.apache.james.managesieve.api.SieveRepository;
-import org.apache.james.managesieve.api.StorageException;
-import org.apache.james.managesieve.api.UserNotFoundException;
+import org.apache.james.managesieve.api.*;
+import org.junit.After;
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * <code>SieveFileRepositoryTestCase</code>
  */
-public class SieveFileRepositoryTestCase extends TestCase {
+public class SieveFileRepositoryTestCase {
+
     private static final String SIEVE_ROOT = FileSystem.FILE_PROTOCOL + "sieve";
-    
     private FileSystem fs = new FileSystem() {
 
-        public File getBasedir() throws FileNotFoundException {
-             return new File(System.getProperty("java.io.tmpdir"));
-        }
-
-        public InputStream getResource(String url) throws IOException {
-            return new FileInputStream(getFile(url));
-        }
-
-        public File getFile(String fileURL) throws FileNotFoundException {
-            return new File(getBasedir(), fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
-        }
+	@Override
+	public File getBasedir() throws FileNotFoundException {
+	    return new File(System.getProperty("java.io.tmpdir"));
+	}
+
+	@Override
+	public InputStream getResource(String url) throws IOException {
+	    return new FileInputStream(getFile(url));
+	}
+
+	@Override
+	public File getFile(String fileURL) throws FileNotFoundException {
+	    return new File(getBasedir(), fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
+	}
     };
 
     /**
@@ -67,15 +57,14 @@ public class SieveFileRepositoryTestCase
      *
      * @throws java.lang.Exception
      */
-//    @Before
+    @Before
     public void setUp() throws Exception {
-        File root = fs.getFile(SIEVE_ROOT);
-        // Remove files from the previous test, if any
-        if (root.exists())
-        {
-            FileUtils.forceDelete(root);
-        }
-        root.mkdir();
+	File root = fs.getFile(SIEVE_ROOT);
+	// Remove files from the previous test, if any
+	if (root.exists()) {
+	    FileUtils.forceDelete(root);
+	}
+	root.mkdir();
     }
 
     /**
@@ -83,19 +72,19 @@ public class SieveFileRepositoryTestCase
      *
      * @throws java.lang.Exception
      */
-//    @After
+    @After
     public void tearDown() throws Exception {
-        // Files from the current run are not removed to allow post run analysis
+	// Files from the current run are not removed to allow post run analysis
     }
 
     /**
      * Test method for {@link org.apache.james.managesieve.file.SieveFileRepository#SieveFileRepository(org.apache.james.filesystem.api.FileSystem)}.
      */
-//    @Test
+    @Test
     public final void testSieveFileRepository() {
-        SieveRepository repo = new SieveFileRepository(fs);
-        assertTrue(repo instanceof SieveRepository);
-        assertTrue(repo instanceof SieveFileRepository);
+	SieveRepository repo = new SieveFileRepository(fs);
+	assertTrue(repo instanceof SieveRepository);
+	assertTrue(repo instanceof SieveFileRepository);
     }
 
     /**
@@ -108,41 +97,41 @@ public class SieveFileRepositoryTestCase
      * @throws ScriptNotFoundException 
      * @throws FileNotFoundException 
      */
-//    @Test
+    @Test
     public final void testDeleteScript() throws DuplicateUserException, StorageException,
-            UserNotFoundException, QuotaExceededException, ScriptNotFoundException,
-            IsActiveException, FileNotFoundException {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        String scriptName = "script";
-        String content = "01234567";
-
-        // Delete existent inactive script
-        repo.putScript(user, scriptName, content);
-        repo.deleteScript(user, scriptName);
-        assertTrue("Script deletion failed", !new File(fs.getFile(SIEVE_ROOT), user + '/'
-                + scriptName).exists());
-
-        // Delete existent active script
-        repo.putScript(user, scriptName, content);
-        repo.setActive(user, scriptName);
-        boolean isActiveExceptionThrown = false;
-        try {
-            repo.deleteScript(user, scriptName);
-        } catch (IsActiveException ex) {
-            isActiveExceptionThrown = true;
-        }
-        assertTrue(isActiveExceptionThrown);
-
-        // Delete non existent script
-        boolean scriptNotFoundExceptionThrown = false;
-        try {
-            repo.deleteScript(user, "nonExistent");
-        } catch (ScriptNotFoundException ex) {
-            scriptNotFoundExceptionThrown = true;
-        }
-        assertTrue(scriptNotFoundExceptionThrown);
+	    UserNotFoundException, QuotaExceededException, ScriptNotFoundException,
+	    IsActiveException, FileNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+	String scriptName = "script";
+	String content = "01234567";
+
+	// Delete existent inactive script
+	repo.putScript(user, scriptName, content);
+	repo.deleteScript(user, scriptName);
+	assertTrue("Script deletion failed", !new File(fs.getFile(SIEVE_ROOT), user + '/'
+		+ scriptName).exists());
+
+	// Delete existent active script
+	repo.putScript(user, scriptName, content);
+	repo.setActive(user, scriptName);
+	boolean isActiveExceptionThrown = false;
+	try {
+	    repo.deleteScript(user, scriptName);
+	} catch (IsActiveException ex) {
+	    isActiveExceptionThrown = true;
+	}
+	assertTrue(isActiveExceptionThrown);
+
+	// Delete non existent script
+	boolean scriptNotFoundExceptionThrown = false;
+	try {
+	    repo.deleteScript(user, "nonExistent");
+	} catch (ScriptNotFoundException ex) {
+	    scriptNotFoundExceptionThrown = true;
+	}
+	assertTrue(scriptNotFoundExceptionThrown);
     }
 
     /**
@@ -153,26 +142,27 @@ public class SieveFileRepositoryTestCase
      * @throws QuotaExceededException 
      * @throws ScriptNotFoundException 
      */
-//    @Test
-    public final void testGetScript() throws DuplicateUserException, StorageException, UserNotFoundException,
QuotaExceededException, ScriptNotFoundException {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        String scriptName = "script";
-        String content = "01234567";
-        
-        // Non existent script
-        boolean scriptNotFoundExceptionThrown = false;
-        try {
-            repo.getScript(user, scriptName);
-        } catch (ScriptNotFoundException ex) {
-            scriptNotFoundExceptionThrown = true;
-        }
-        assertTrue(scriptNotFoundExceptionThrown);
-        
-        // Existent script
-        repo.putScript(user, scriptName, content);
-        assertEquals("Script content did not match", content, repo.getScript(user, scriptName));
+    @Test
+    public final void testGetScript() throws DuplicateUserException, StorageException, UserNotFoundException,
+	    QuotaExceededException, ScriptNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+	String scriptName = "script";
+	String content = "01234567";
+
+	// Non existent script
+	boolean scriptNotFoundExceptionThrown = false;
+	try {
+	    repo.getScript(user, scriptName);
+	} catch (ScriptNotFoundException ex) {
+	    scriptNotFoundExceptionThrown = true;
+	}
+	assertTrue(scriptNotFoundExceptionThrown);
+
+	// Existent script
+	repo.putScript(user, scriptName, content);
+	assertEquals("Script content did not match", content, repo.getScript(user, scriptName));
     }
 
     /**
@@ -183,63 +173,64 @@ public class SieveFileRepositoryTestCase
      * @throws StorageException 
      * @throws ScriptNotFoundException 
      */
-//    @Test
-    public final void testHaveSpace() throws DuplicateUserException, UserNotFoundException,
QuotaExceededException, StorageException, ScriptNotFoundException {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        String scriptName = "script";
-        long defaultQuota = Long.MAX_VALUE - 1;
-        long userQuota = Long.MAX_VALUE / 2;
-        boolean quotaExceededExceptionThrown = false;
-        
-        // No quota
-        repo.haveSpace(user, scriptName, defaultQuota + 1);
-       
-        // Default quota
-        repo.setQuota(defaultQuota);        
-        // Default quota - not exceeded
-        repo.haveSpace(user, scriptName, defaultQuota);
-        // Default quota - exceeded
-        quotaExceededExceptionThrown = false;
-        try {
-            repo.haveSpace(user, scriptName, defaultQuota + 1);
-        } catch (QuotaExceededException ex) {
-            quotaExceededExceptionThrown = true;
-        }
-        assertTrue(quotaExceededExceptionThrown);
-
-        // User quota file
-        repo.setQuota(user, userQuota); 
-        // User quota - not exceeded
-        repo.haveSpace(user, scriptName, userQuota);
-        // User quota - exceeded
-        quotaExceededExceptionThrown = false;
-        try {
-            repo.haveSpace(user, scriptName, userQuota + 1);
-        } catch (QuotaExceededException ex) {
-            quotaExceededExceptionThrown = true;
-        }
-        assertTrue(quotaExceededExceptionThrown);
-       
-        // Script replacement
-        String content = "01234567";
-        repo.putScript(user, scriptName, content);
-        // Script replacement, quota not exceeded
-        repo.haveSpace(user, scriptName, userQuota);             
-        // Script replacement, quota exceeded
-        quotaExceededExceptionThrown = false;
-        try {
-            repo.haveSpace(user, scriptName, userQuota + 1);
-        } catch (QuotaExceededException ex) {
-            quotaExceededExceptionThrown = true;
-        }
-        assertTrue(quotaExceededExceptionThrown);
-        
-        // Active script
-        repo.setActive(user, scriptName);
-        // User quota - not exceeded
-        repo.haveSpace(user, scriptName, userQuota);  
+    @Test
+    public final void testHaveSpace() throws DuplicateUserException, UserNotFoundException,
QuotaExceededException,
+	    StorageException, ScriptNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+	String scriptName = "script";
+	long defaultQuota = Long.MAX_VALUE - 1;
+	long userQuota = Long.MAX_VALUE / 2;
+	boolean quotaExceededExceptionThrown = false;
+
+	// No quota
+	repo.haveSpace(user, scriptName, defaultQuota + 1);
+
+	// Default quota
+	repo.setQuota(defaultQuota);
+	// Default quota - not exceeded
+	repo.haveSpace(user, scriptName, defaultQuota);
+	// Default quota - exceeded
+	quotaExceededExceptionThrown = false;
+	try {
+	    repo.haveSpace(user, scriptName, defaultQuota + 1);
+	} catch (QuotaExceededException ex) {
+	    quotaExceededExceptionThrown = true;
+	}
+	assertTrue(quotaExceededExceptionThrown);
+
+	// User quota file
+	repo.setQuota(user, userQuota);
+	// User quota - not exceeded
+	repo.haveSpace(user, scriptName, userQuota);
+	// User quota - exceeded
+	quotaExceededExceptionThrown = false;
+	try {
+	    repo.haveSpace(user, scriptName, userQuota + 1);
+	} catch (QuotaExceededException ex) {
+	    quotaExceededExceptionThrown = true;
+	}
+	assertTrue(quotaExceededExceptionThrown);
+
+	// Script replacement
+	String content = "01234567";
+	repo.putScript(user, scriptName, content);
+	// Script replacement, quota not exceeded
+	repo.haveSpace(user, scriptName, userQuota);
+	// Script replacement, quota exceeded
+	quotaExceededExceptionThrown = false;
+	try {
+	    repo.haveSpace(user, scriptName, userQuota + 1);
+	} catch (QuotaExceededException ex) {
+	    quotaExceededExceptionThrown = true;
+	}
+	assertTrue(quotaExceededExceptionThrown);
+
+	// Active script
+	repo.setActive(user, scriptName);
+	// User quota - not exceeded
+	repo.haveSpace(user, scriptName, userQuota);
     }
 
     /**
@@ -250,41 +241,42 @@ public class SieveFileRepositoryTestCase
      * @throws QuotaExceededException 
      * @throws ScriptNotFoundException 
      */
-//    @Test
-    public final void testListScripts() throws DuplicateUserException, StorageException,
UserNotFoundException, QuotaExceededException, ScriptNotFoundException {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        String scriptName = "script";
-        String content = "01234567";
-        String scriptName1 = "script1";
-        String content1 = "abcdefgh";
-        
-        // No scripts
-        assertTrue(repo.listScripts(user).isEmpty());
-        
-        // Inactive script
-        repo.putScript(user, scriptName, content);
-        List<ScriptSummary> summaries = repo.listScripts(user);
-        assertEquals(1, summaries.size());
-        assertEquals(scriptName, summaries.get(0).getName());
-        assertTrue(!summaries.get(0).isActive());
-
-        // Active script
-        repo.setActive(user, scriptName);
-        summaries = repo.listScripts(user);
-        assertEquals(1, summaries.size());
-        assertEquals(scriptName, summaries.get(0).getName());
-        assertTrue(summaries.get(0).isActive());
-        
-        // One of each
-        repo.putScript(user, scriptName1, content1);
-        summaries = repo.listScripts(user);
-        assertEquals(2, summaries.size());
-        assertEquals(scriptName, summaries.get(0).getName());
-        assertTrue(summaries.get(0).isActive());
-        assertEquals(scriptName1, summaries.get(1).getName());
-        assertTrue(!summaries.get(1).isActive());
+    @Test
+    public final void testListScripts() throws DuplicateUserException, StorageException,
UserNotFoundException,
+	    QuotaExceededException, ScriptNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+	String scriptName = "script";
+	String content = "01234567";
+	String scriptName1 = "script1";
+	String content1 = "abcdefgh";
+
+	// No scripts
+	assertTrue(repo.listScripts(user).isEmpty());
+
+	// Inactive script
+	repo.putScript(user, scriptName, content);
+	List<ScriptSummary> summaries = repo.listScripts(user);
+	assertEquals(1, summaries.size());
+	assertEquals(scriptName, summaries.get(0).getName());
+	assertTrue(!summaries.get(0).isActive());
+
+	// Active script
+	repo.setActive(user, scriptName);
+	summaries = repo.listScripts(user);
+	assertEquals(1, summaries.size());
+	assertEquals(scriptName, summaries.get(0).getName());
+	assertTrue(summaries.get(0).isActive());
+
+	// One of each
+	repo.putScript(user, scriptName1, content1);
+	summaries = repo.listScripts(user);
+	assertEquals(2, summaries.size());
+	assertEquals(scriptName, summaries.get(0).getName());
+	assertTrue(summaries.get(0).isActive());
+	assertEquals(scriptName1, summaries.get(1).getName());
+	assertTrue(!summaries.get(1).isActive());
     }
 
     /**
@@ -295,36 +287,36 @@ public class SieveFileRepositoryTestCase
      * @throws UserNotFoundException 
      * @throws FileNotFoundException 
      */
-//    @Test
+    @Test
     public final void testPutScript() throws DuplicateUserException, UserNotFoundException,
-            StorageException, QuotaExceededException, FileNotFoundException {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        String scriptName = "script";
-        String content = "01234567";
-
-        // test new script
-        repo.putScript(user, scriptName, content);
-        assertTrue("Script creation failed", new File(fs.getFile(SIEVE_ROOT), user + '/'
-                + scriptName).exists());
-
-        // test script replacement
-        repo.putScript(user, scriptName, content);
-        assertTrue("Script replacement failed", new File(fs.getFile(SIEVE_ROOT), user + '/'
-                + scriptName).exists());
-        
-        // test quota
-        repo.setQuota(content.length());
-        repo.putScript(user, scriptName, content);
-        repo.setQuota(content.length() - 1);
-        boolean quotaExceededExceptionThrown = false;
-        try {
-            repo.putScript(user, scriptName, content);
-        } catch (QuotaExceededException ex) {
-            quotaExceededExceptionThrown = true;
-        }
-        assertTrue(quotaExceededExceptionThrown);
+	    StorageException, QuotaExceededException, FileNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+	String scriptName = "script";
+	String content = "01234567";
+
+	// test new script
+	repo.putScript(user, scriptName, content);
+	assertTrue("Script creation failed", new File(fs.getFile(SIEVE_ROOT), user + '/'
+		+ scriptName).exists());
+
+	// test script replacement
+	repo.putScript(user, scriptName, content);
+	assertTrue("Script replacement failed", new File(fs.getFile(SIEVE_ROOT), user + '/'
+		+ scriptName).exists());
+
+	// test quota
+	repo.setQuota(content.length());
+	repo.putScript(user, scriptName, content);
+	repo.setQuota(content.length() - 1);
+	boolean quotaExceededExceptionThrown = false;
+	try {
+	    repo.putScript(user, scriptName, content);
+	} catch (QuotaExceededException ex) {
+	    quotaExceededExceptionThrown = true;
+	}
+	assertTrue(quotaExceededExceptionThrown);
     }
 
     /**
@@ -337,43 +329,44 @@ public class SieveFileRepositoryTestCase
      * @throws ScriptNotFoundException 
      * @throws QuotaExceededException 
      */
-//    @Test
-    public final void testRenameScript() throws DuplicateUserException, StorageException,
UserNotFoundException, IsActiveException, DuplicateException, ScriptNotFoundException, QuotaExceededException
{
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        String scriptName = "script";
-        String content = "01234567";
-        String scriptName1 = "script1";
-        
-        // Non existent script
-        boolean scriptNotFoundExceptionThrown = false;
-        try {
-            repo.renameScript(user, scriptName, scriptName1);
-        } catch (ScriptNotFoundException ex) {
-            scriptNotFoundExceptionThrown = true;
-        }
-        assertTrue(scriptNotFoundExceptionThrown);
-        
-        // Existent script
-        repo.putScript(user, scriptName, content);
-        repo.renameScript(user, scriptName, scriptName1);
-        assertEquals("Script content did not match", content, repo.getScript(user, scriptName1));
-        
-        // Propagate active script
-        repo.setActive(user, scriptName1);
-        repo.renameScript(user, scriptName1, scriptName);
-        assertEquals("Script content did not match", content, repo.getActive(user));
-        
-        // Duplicate script
-        repo.setActive(user, "");
-        boolean duplicateExceptionThrown = false;
-        try {
-            repo.renameScript(user, scriptName, scriptName);
-        } catch (DuplicateException ex) {
-            duplicateExceptionThrown = true;
-        }
-        assertTrue(duplicateExceptionThrown);
+    @Test
+    public final void testRenameScript() throws DuplicateUserException, StorageException,
UserNotFoundException,
+	    IsActiveException, DuplicateException, ScriptNotFoundException, QuotaExceededException
{
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+	String scriptName = "script";
+	String content = "01234567";
+	String scriptName1 = "script1";
+
+	// Non existent script
+	boolean scriptNotFoundExceptionThrown = false;
+	try {
+	    repo.renameScript(user, scriptName, scriptName1);
+	} catch (ScriptNotFoundException ex) {
+	    scriptNotFoundExceptionThrown = true;
+	}
+	assertTrue(scriptNotFoundExceptionThrown);
+
+	// Existent script
+	repo.putScript(user, scriptName, content);
+	repo.renameScript(user, scriptName, scriptName1);
+	assertEquals("Script content did not match", content, repo.getScript(user, scriptName1));
+
+	// Propagate active script
+	repo.setActive(user, scriptName1);
+	repo.renameScript(user, scriptName1, scriptName);
+	assertEquals("Script content did not match", content, repo.getActive(user));
+
+	// Duplicate script
+	repo.setActive(user, "");
+	boolean duplicateExceptionThrown = false;
+	try {
+	    repo.renameScript(user, scriptName, scriptName);
+	} catch (DuplicateException ex) {
+	    duplicateExceptionThrown = true;
+	}
+	assertTrue(duplicateExceptionThrown);
     }
 
     /**
@@ -384,36 +377,37 @@ public class SieveFileRepositoryTestCase
      * @throws UserNotFoundException 
      * @throws ScriptNotFoundException 
      */
-//    @Test
-    public final void testGetActive() throws DuplicateUserException, StorageException, UserNotFoundException,
QuotaExceededException, ScriptNotFoundException {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        String scriptName = "script";
-        String content = "01234567";
-        
-        // Non existent script
-        boolean scriptNotFoundExceptionThrown = false;
-        try {
-            repo.getActive(user);
-        } catch (ScriptNotFoundException ex) {
-            scriptNotFoundExceptionThrown = true;
-        }
-        assertTrue(scriptNotFoundExceptionThrown);
-        
-        // Inactive script
-        repo.putScript(user, scriptName, content);
-        scriptNotFoundExceptionThrown = false;
-        try {
-            repo.getActive(user);
-        } catch (ScriptNotFoundException ex) {
-            scriptNotFoundExceptionThrown = true;
-        }
-        assertTrue(scriptNotFoundExceptionThrown);
-        
-        // Active script
-        repo.setActive(user, scriptName);
-        assertEquals("Script content did not match", content, repo.getActive(user));
+    @Test
+    public final void testGetActive() throws DuplicateUserException, StorageException, UserNotFoundException,
+	    QuotaExceededException, ScriptNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+	String scriptName = "script";
+	String content = "01234567";
+
+	// Non existent script
+	boolean scriptNotFoundExceptionThrown = false;
+	try {
+	    repo.getActive(user);
+	} catch (ScriptNotFoundException ex) {
+	    scriptNotFoundExceptionThrown = true;
+	}
+	assertTrue(scriptNotFoundExceptionThrown);
+
+	// Inactive script
+	repo.putScript(user, scriptName, content);
+	scriptNotFoundExceptionThrown = false;
+	try {
+	    repo.getActive(user);
+	} catch (ScriptNotFoundException ex) {
+	    scriptNotFoundExceptionThrown = true;
+	}
+	assertTrue(scriptNotFoundExceptionThrown);
+
+	// Active script
+	repo.setActive(user, scriptName);
+	assertEquals("Script content did not match", content, repo.getActive(user));
     }
 
     /**
@@ -424,221 +418,212 @@ public class SieveFileRepositoryTestCase
      * @throws ScriptNotFoundException 
      * @throws QuotaExceededException 
      */
-//    @Test
+    @Test
     public final void testSetActive() throws DuplicateUserException, StorageException,
-            UserNotFoundException, ScriptNotFoundException, QuotaExceededException {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        String scriptName = "script";
-        String content = "01234567";
-        String scriptName1 = "script1";
-        String content1 = "abcdefgh";
-
-        // Non existent script
-        boolean scriptNotFoundExceptionThrown = false;
-        try {
-            repo.setActive(user, scriptName);
-        } catch (ScriptNotFoundException ex) {
-            scriptNotFoundExceptionThrown = true;
-        }
-        assertTrue(scriptNotFoundExceptionThrown);
-
-        // Existent script
-        repo.putScript(user, scriptName, content);
-        repo.setActive(user, scriptName);
-        assertEquals("Script content did not match", content, repo.getActive(user));
-
-        // Switch active script
-        repo.putScript(user, scriptName1, content1);
-        scriptNotFoundExceptionThrown = false;
-        repo.setActive(user, scriptName1);
-        assertEquals("Script content did not match", content1, repo.getActive(user));
-
-        // Disable active script
-        repo.setActive(user, "");
-        scriptNotFoundExceptionThrown = false;
-        try {
-            repo.getActive(user);
-        } catch (ScriptNotFoundException ex) {
-            scriptNotFoundExceptionThrown = true;
-        }
-        assertTrue(scriptNotFoundExceptionThrown);
-    }
-    
-//    @Test
-    public final void testAddUser() throws DuplicateUserException, StorageException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        
-        repo.addUser(user);
-        assertTrue(repo.hasUser(user));
-    }
-    
-//    @Test
-    public final void testRemoveUser() throws StorageException, DuplicateUserException, UserNotFoundException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        
-        // Non existent user
-        boolean userNotFoundExceptionThrown = false;
-        try {
-            repo.removeUser(user);
-        } catch (UserNotFoundException ex) {
-            userNotFoundExceptionThrown = true;
-        }
-        assertTrue(userNotFoundExceptionThrown);
-        
-        // Existent user
-        repo.addUser(user);
-        repo.removeUser(user);
-        assertTrue(!repo.hasUser(user));
-    }
-    
-//    @Test
-    public final void testHasUser() throws DuplicateUserException, StorageException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-       
-        // Non existent user
-        assertTrue(!repo.hasUser(user));
-        
-        // Existent user
-        repo.addUser(user);
-        assertTrue(repo.hasUser(user));
-    }
-    
-//    @Test
-    public final void testGetQuota() throws StorageException, QuotaNotFoundException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        
-        // Non existent quota
-        boolean quotaNotFoundExceptionThrown = false;
-        try {
-            repo.getQuota();
-        } catch (QuotaNotFoundException ex) {
-            quotaNotFoundExceptionThrown = true;
-        }
-        assertTrue(quotaNotFoundExceptionThrown);
-
-        // Existent Quota
-        repo.setQuota(Long.MAX_VALUE);
-        assertEquals(Long.MAX_VALUE, repo.getQuota());
-    }
-    
-//    @Test
-    public final void testHasQuota() throws StorageException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        
-        // Non existent quota
-        assertTrue(!repo.hasQuota());
-        
-        // Existent quota
-        repo.setQuota(Long.MAX_VALUE);
-        assertTrue(repo.hasQuota());
-    }
-    
-//    @Test
-    public final void testRemoveQuota() throws StorageException, QuotaNotFoundException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        
-        // Non existent quota
-        boolean quotaNotFoundExceptionThrown = false;
-        try {
-            repo.removeQuota();
-        } catch (QuotaNotFoundException ex) {
-            quotaNotFoundExceptionThrown = true;
-        }
-        assertTrue(quotaNotFoundExceptionThrown);
-        
-        // Existent quota
-        repo.setQuota(Long.MAX_VALUE);
-        repo.removeQuota();
-        assertTrue(!repo.hasQuota());
-    } 
-    
-//    @Test
-    public final void testSetQuota() throws QuotaNotFoundException, StorageException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        
-        repo.setQuota(Long.MAX_VALUE);
-        assertEquals(Long.MAX_VALUE, repo.getQuota());   
-    }
-    
-//    @Test
-    public final void testGetUserQuota() throws StorageException, QuotaNotFoundException,
DuplicateUserException, UserNotFoundException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        
-        // Non existent quota
-        boolean quotaNotFoundExceptionThrown = false;
-        try {
-            repo.getQuota(user);
-        } catch (QuotaNotFoundException ex) {
-            quotaNotFoundExceptionThrown = true;
-        }
-        assertTrue(quotaNotFoundExceptionThrown);
-
-        // Existent Quota
-        repo.setQuota(user, Long.MAX_VALUE);
-        assertEquals(Long.MAX_VALUE, repo.getQuota(user));
-    }
-    
-//    @Test
-    public final void testHasUserQuota() throws StorageException, DuplicateUserException,
UserNotFoundException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        
-        // Non existent quota
-        assertTrue(!repo.hasQuota(user));
-        
-        // Existent quota
-        repo.setQuota(user, Long.MAX_VALUE);
-        assertTrue(repo.hasQuota(user));
-    }
-    
-//    @Test
-    public final void testRemoveUserQuota() throws StorageException, QuotaNotFoundException,
DuplicateUserException, UserNotFoundException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        
-        // Non existent quota
-        boolean quotaNotFoundExceptionThrown = false;
-        try {
-            repo.removeQuota(user);
-        } catch (QuotaNotFoundException ex) {
-            quotaNotFoundExceptionThrown = true;
-        }
-        assertTrue(quotaNotFoundExceptionThrown);
-        
-        // Existent quota
-        repo.setQuota(user, Long.MAX_VALUE);
-        repo.removeQuota(user);
-        assertTrue(!repo.hasQuota(user));
-    } 
-    
-//    @Test
-    public final void testSetUserQuota() throws QuotaNotFoundException, StorageException,
DuplicateUserException, UserNotFoundException
-    {
-        SieveRepository repo = new SieveFileRepository(fs);
-        String user = "test";
-        repo.addUser(user);
-        
-        repo.setQuota(user, Long.MAX_VALUE);
-        assertEquals(Long.MAX_VALUE, repo.getQuota(user));   
-    }
+	    UserNotFoundException, ScriptNotFoundException, QuotaExceededException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+	String scriptName = "script";
+	String content = "01234567";
+	String scriptName1 = "script1";
+	String content1 = "abcdefgh";
+
+	// Non existent script
+	boolean scriptNotFoundExceptionThrown = false;
+	try {
+	    repo.setActive(user, scriptName);
+	} catch (ScriptNotFoundException ex) {
+	    scriptNotFoundExceptionThrown = true;
+	}
+	assertTrue(scriptNotFoundExceptionThrown);
+
+	// Existent script
+	repo.putScript(user, scriptName, content);
+	repo.setActive(user, scriptName);
+	assertEquals("Script content did not match", content, repo.getActive(user));
+
+	// Switch active script
+	repo.putScript(user, scriptName1, content1);
+	scriptNotFoundExceptionThrown = false;
+	repo.setActive(user, scriptName1);
+	assertEquals("Script content did not match", content1, repo.getActive(user));
+
+	// Disable active script
+	repo.setActive(user, "");
+	scriptNotFoundExceptionThrown = false;
+	try {
+	    repo.getActive(user);
+	} catch (ScriptNotFoundException ex) {
+	    scriptNotFoundExceptionThrown = true;
+	}
+	assertTrue(scriptNotFoundExceptionThrown);
+    }
+
+    @Test
+    public final void testAddUser() throws DuplicateUserException, StorageException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+
+	repo.addUser(user);
+	assertTrue(repo.hasUser(user));
+    }
+
+    @Test
+    public final void testRemoveUser() throws StorageException, DuplicateUserException, UserNotFoundException
{
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+
+	// Non existent user
+	boolean userNotFoundExceptionThrown = false;
+	try {
+	    repo.removeUser(user);
+	} catch (UserNotFoundException ex) {
+	    userNotFoundExceptionThrown = true;
+	}
+	assertTrue(userNotFoundExceptionThrown);
+
+	// Existent user
+	repo.addUser(user);
+	repo.removeUser(user);
+	assertTrue(!repo.hasUser(user));
+    }
+
+    @Test
+    public final void testHasUser() throws DuplicateUserException, StorageException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+
+	// Non existent user
+	assertTrue(!repo.hasUser(user));
+
+	// Existent user
+	repo.addUser(user);
+	assertTrue(repo.hasUser(user));
+    }
+
+    @Test
+    public final void testGetQuota() throws StorageException, QuotaNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+
+	// Non existent quota
+	boolean quotaNotFoundExceptionThrown = false;
+	try {
+	    repo.getQuota();
+	} catch (QuotaNotFoundException ex) {
+	    quotaNotFoundExceptionThrown = true;
+	}
+	assertTrue(quotaNotFoundExceptionThrown);
+
+	// Existent Quota
+	repo.setQuota(Long.MAX_VALUE);
+	assertEquals(Long.MAX_VALUE, repo.getQuota());
+    }
+
+    @Test
+    public final void testHasQuota() throws StorageException {
+	SieveRepository repo = new SieveFileRepository(fs);
+
+	// Non existent quota
+	assertTrue(!repo.hasQuota());
+
+	// Existent quota
+	repo.setQuota(Long.MAX_VALUE);
+	assertTrue(repo.hasQuota());
+    }
+
+    @Test
+    public final void testRemoveQuota() throws StorageException, QuotaNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+
+	// Non existent quota
+	boolean quotaNotFoundExceptionThrown = false;
+	try {
+	    repo.removeQuota();
+	} catch (QuotaNotFoundException ex) {
+	    quotaNotFoundExceptionThrown = true;
+	}
+	assertTrue(quotaNotFoundExceptionThrown);
+
+	// Existent quota
+	repo.setQuota(Long.MAX_VALUE);
+	repo.removeQuota();
+	assertTrue(!repo.hasQuota());
+    }
+
+    @Test
+    public final void testSetQuota() throws QuotaNotFoundException, StorageException {
+	SieveRepository repo = new SieveFileRepository(fs);
+
+	repo.setQuota(Long.MAX_VALUE);
+	assertEquals(Long.MAX_VALUE, repo.getQuota());
+    }
+
+    @Test
+    public final void testGetUserQuota() throws StorageException, QuotaNotFoundException,
DuplicateUserException,
+	    UserNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+
+	// Non existent quota
+	boolean quotaNotFoundExceptionThrown = false;
+	try {
+	    repo.getQuota(user);
+	} catch (QuotaNotFoundException ex) {
+	    quotaNotFoundExceptionThrown = true;
+	}
+	assertTrue(quotaNotFoundExceptionThrown);
+
+	// Existent Quota
+	repo.setQuota(user, Long.MAX_VALUE);
+	assertEquals(Long.MAX_VALUE, repo.getQuota(user));
+    }
+
+    @Test
+    public final void testHasUserQuota() throws StorageException, DuplicateUserException,
UserNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+
+	// Non existent quota
+	assertTrue(!repo.hasQuota(user));
+
+	// Existent quota
+	repo.setQuota(user, Long.MAX_VALUE);
+	assertTrue(repo.hasQuota(user));
+    }
+
+    @Test
+    public final void testRemoveUserQuota() throws StorageException, QuotaNotFoundException,
DuplicateUserException,
+	    UserNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
+
+	// Non existent quota
+	boolean quotaNotFoundExceptionThrown = false;
+	try {
+	    repo.removeQuota(user);
+	} catch (QuotaNotFoundException ex) {
+	    quotaNotFoundExceptionThrown = true;
+	}
+	assertTrue(quotaNotFoundExceptionThrown);
+
+	// Existent quota
+	repo.setQuota(user, Long.MAX_VALUE);
+	repo.removeQuota(user);
+	assertTrue(!repo.hasQuota(user));
+    }
+
+    @Test
+    public final void testSetUserQuota() throws QuotaNotFoundException, StorageException,
DuplicateUserException,
+	    UserNotFoundException {
+	SieveRepository repo = new SieveFileRepository(fs);
+	String user = "test";
+	repo.addUser(user);
 
+	repo.setQuota(user, Long.MAX_VALUE);
+	assertEquals(Long.MAX_VALUE, repo.getQuota(user));
+    }
 }

Modified: james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/mock/MockFileSystem.java
URL: http://svn.apache.org/viewvc/james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/mock/MockFileSystem.java?rev=1299470&r1=1299469&r2=1299470&view=diff
==============================================================================
--- james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/mock/MockFileSystem.java
(original)
+++ james/server/trunk/filesystem-api/src/test/java/org/apache/james/filesystem/api/mock/MockFileSystem.java
Sun Mar 11 22:31:29 2012
@@ -16,48 +16,46 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.filesystem.api.mock;
 
-import org.apache.james.filesystem.api.FileSystem;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.FileInputStream;
+import java.io.*;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import org.apache.james.filesystem.api.FileSystem;
 
 public class MockFileSystem implements FileSystem {
+
+    @Override
     public File getBasedir() throws FileNotFoundException {
-        return new File(".");
+	return new File(".");
     }
 
+    @Override
     public InputStream getResource(String url) throws IOException {
-        return new FileInputStream(getFile(url));
+	return new FileInputStream(getFile(url));
     }
 
+    @Override
     public File getFile(String fileURL) throws FileNotFoundException {
-        try {
-            if (fileURL.startsWith("file://")) {
-                if (fileURL.startsWith("file://conf/")) {
-                    URL url = MockFileSystem.class.getClassLoader().getResource("./" + fileURL.substring(12));
-                    try {
-                        return new File(new URI(url.toString()));
-                    } catch (URISyntaxException e) {
-                        throw new FileNotFoundException("Unable to load file");
-                    }
-                    // return new File("./src"+fileURL.substring(6));
-                } else {
-                    return new File(fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
-                }
-            } else {
-                throw new UnsupportedOperationException("getFile: " + fileURL);
-            }
-        } catch (NullPointerException npe) {
-            throw new FileNotFoundException("NPE on: " + fileURL);
-        }
+	try {
+	    if (fileURL.startsWith("file://")) {
+		if (fileURL.startsWith("file://conf/")) {
+		    URL url = MockFileSystem.class.getClassLoader().getResource("./" + fileURL.substring(12));
+		    try {
+			return new File(new URI(url.toString()));
+		    } catch (URISyntaxException e) {
+			throw new FileNotFoundException("Unable to load file");
+		    }
+		    // return new File("./src"+fileURL.substring(6));
+		} else {
+		    return new File(fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
+		}
+	    } else {
+		throw new UnsupportedOperationException("getFile: " + fileURL);
+	    }
+	} catch (NullPointerException npe) {
+	    throw new FileNotFoundException("NPE on: " + fileURL);
+	}
     }
 }



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


Mime
View raw message