1 4 package com.openedit.users; 5 6 import java.io.File ; 7 import java.io.IOException ; 8 9 import com.openedit.BaseTestCase; 10 import com.openedit.users.authenticate.FileSystemAuthenticator; 11 import com.openedit.users.filesystem.FileSystemUserManager; 12 13 public class BaseUserTest extends BaseTestCase 14 { 15 protected UserManager fieldUserManager; 16 17 18 public BaseUserTest(String inName) 19 { 20 super( inName); 21 } 22 23 30 public UserManager createUserManager() throws IOException 31 { 32 FileSystemUserManager userManager = new FileSystemUserManager(); 33 userManager.setUserDirectory(createTempDir()); 34 userManager.setGroupDirectory(createTempDir()); 35 userManager.setAuthenticator(new FileSystemAuthenticator()); 36 userManager.setPageManager(getFixture().getPageManager()); 37 return userManager; 38 } 39 40 47 public void deleteUserManager(UserManager inUserManager) 48 throws IOException 49 { 50 FileSystemUserManager userManager = (FileSystemUserManager) inUserManager; 51 deleteRecursively(userManager.getUserDirectory()); 52 deleteRecursively(userManager.getGroupDirectory()); 53 } 54 55 62 protected File createTempDir() throws IOException 63 { 64 File file = File.createTempFile("FileSystemUserManagerTest", null); 65 file.delete(); 66 file.mkdir(); 67 68 return file; 69 } 70 71 76 protected void deleteRecursively(File inFile) 77 { 78 if (inFile.isDirectory()) 79 { 80 File [] files = inFile.listFiles(); 81 82 for (int i = 0; i < files.length; i++) 83 { 84 deleteRecursively(files[i]); 85 } 86 } 87 88 inFile.delete(); 89 } 90 } 91 92 93 | Popular Tags |