KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > users > BaseUserTest


1 /*
2  * Created on Oct 11, 2006
3  */

4 package com.openedit.users;
5
6 import java.io.File JavaDoc;
7 import java.io.IOException JavaDoc;
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 JavaDoc inName)
19         {
20             super( inName);
21         }
22         
23         /**
24          * DOCUMENT ME!
25          *
26          * @return
27          *
28          * @throws IOException
29          */

30         public UserManager createUserManager() throws IOException JavaDoc
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         /**
41          * DOCUMENT ME!
42          *
43          * @param inUserManager
44          *
45          * @throws IOException
46          */

47         public void deleteUserManager(UserManager inUserManager)
48             throws IOException JavaDoc
49         {
50             FileSystemUserManager userManager = (FileSystemUserManager) inUserManager;
51             deleteRecursively(userManager.getUserDirectory());
52             deleteRecursively(userManager.getGroupDirectory());
53         }
54
55         /**
56          * Create an empty directory in a temporary location with a random name.
57          *
58          * @return The new directory
59          *
60          * @throws IOException DOCUMENT ME!
61          */

62         protected File JavaDoc createTempDir() throws IOException JavaDoc
63         {
64             File JavaDoc file = File.createTempFile("FileSystemUserManagerTest", null);
65             file.delete();
66             file.mkdir();
67
68             return file;
69         }
70
71         /**
72          * Delete the given file or directory and all its sub-directories.
73          *
74          * @param inFile The file or directory to delete
75          */

76         protected void deleteRecursively(File JavaDoc inFile)
77         {
78             if (inFile.isDirectory())
79             {
80                 File JavaDoc[] 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