KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > mock > MockUsersRepository


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20 package org.apache.james.imapserver.mock;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import org.apache.james.imapserver.TestConstants;
26 import org.apache.james.services.User;
27 import org.apache.james.services.UsersRepository;
28
29 public class MockUsersRepository implements UsersRepository, TestConstants
30 {
31
32     public boolean addUser(User user)
33     {
34         throw new RuntimeException JavaDoc("not implemented");
35     }
36
37     public void addUser(String JavaDoc name, Object JavaDoc attributes)
38     {
39         throw new RuntimeException JavaDoc("not implemented");
40     }
41
42     public boolean addUser(String JavaDoc username, String JavaDoc password)
43     {
44         throw new RuntimeException JavaDoc("not implemented");
45     }
46
47     public User getUserByName(String JavaDoc name)
48     {
49         if (USER_NAME.equals(name)) {
50             return new MockUser();
51         }
52         return null;
53     }
54
55     public User getUserByNameCaseInsensitive(String JavaDoc name)
56     {
57         if (USER_NAME.equalsIgnoreCase(name)) {
58             return new MockUser();
59         }
60         return null;
61     }
62
63     public String JavaDoc getRealName(String JavaDoc name)
64     {
65         if (USER_NAME.equalsIgnoreCase(name)) {
66             return USER_REALNAME;
67         } else {
68             return null;
69         }
70     }
71
72     public boolean updateUser(User user)
73     {
74         throw new RuntimeException JavaDoc("not implemented");
75
76     }
77
78     public void removeUser(String JavaDoc name)
79     {
80         throw new RuntimeException JavaDoc("not implemented");
81
82     }
83
84     public boolean contains(String JavaDoc name)
85     {
86         if (USER_NAME.equals(name)) {
87             return true;
88         } else {
89             return false;
90         }
91     }
92
93     public boolean containsCaseInsensitive(String JavaDoc name)
94     {
95         if (USER_NAME.equalsIgnoreCase(name)) {
96             return true;
97         } else {
98             return false;
99         }
100     }
101
102     public boolean test(String JavaDoc name, String JavaDoc password)
103     {
104         User user=getUserByName(name);
105         if (user!=null) {
106             return user.verifyPassword(password);
107         }
108         return false;
109     }
110
111     public int countUsers()
112     {
113         return 1;
114     }
115
116     public Iterator JavaDoc list()
117     {
118         return Arrays.asList(new String JavaDoc[] { USER_NAME }).iterator();
119     }
120
121 }
122
Popular Tags