Removed DOCUMENT ME comments that were generated and applied source code
[utils] / security / src / test / java / org / wamblee / usermgt / UsermgtTestUtils.java
1 /*
2  * Copyright 2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.usermgt;
17
18 import org.wamblee.security.encryption.Md5HexMessageDigester;
19
20 import org.wamblee.usermgt.UserMgtException.Reason;
21
22 /**
23  * User management test utilities.
24  * 
25  * @author Erik Brakkee
26  */
27 public class UsermgtTestUtils {
28     private static final String DUMMY_GROUP = "dummygroup";
29
30     private static final String DUMMY_PASSWD = "dummypasswd";
31
32     public static Group createGroup(String aName) {
33         return new Group(aName);
34     }
35
36     public static User createUser(String aUsername) throws UserMgtException {
37         return createUser(aUsername, DUMMY_GROUP);
38     }
39
40     public static User createUser(String aUsername, String aGroup)
41         throws UserMgtException {
42         return createUser(aUsername, createGroup(aGroup));
43     }
44
45     public static User createUser(String aUsername, Group aGroup)
46         throws UserMgtException {
47         return createUser(aUsername, DUMMY_PASSWD, aGroup);
48     }
49
50     public static User createUser(String aName, String aPassword, Group aGroup)
51         throws UserMgtException {
52         return new User(aName, aPassword, aGroup, new RegexpNameValidator(
53             RegexpNameValidator.PASSWORD_PATTERN, Reason.INVALID_PASSWORD,
54             "Password must be at least 6 chars"), new Md5HexMessageDigester());
55     }
56
57     public static void addUserToGroup(User aUser, Group aGroup)
58         throws UserMgtException {
59         aUser.addGroup(aGroup);
60     }
61
62     public static void removeUserFromGroup(User aUser, Group aGroup)
63         throws UserMgtException {
64         aUser.removeGroup(aGroup);
65     }
66 }