01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
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: ****************************************************************/package org.apache.james;
19:
20: import org.apache.avalon.cornerstone.services.store.Store;
21: import org.apache.james.services.MailServer;
22: import org.apache.james.services.MailServerTestAllImplementations;
23: import org.apache.james.services.UsersRepository;
24: import org.apache.james.services.UsersStore;
25: import org.apache.james.test.mock.avalon.MockContext;
26: import org.apache.james.test.mock.avalon.MockLogger;
27: import org.apache.james.test.mock.avalon.MockServiceManager;
28: import org.apache.james.test.mock.avalon.MockStore;
29: import org.apache.james.test.mock.james.MockUsersStore;
30: import org.apache.james.test.mock.james.MockMailRepository;
31: import org.apache.james.userrepository.MockUsersRepository;
32:
33: import java.io.File;
34:
35: public class JamesTest extends MailServerTestAllImplementations {
36:
37: public MailServer createMailServer() {
38: James james = new James();
39: james.service(setUpServiceManager());
40: MockLogger mockLogger = new MockLogger();
41: mockLogger.disableDebug();
42: james.enableLogging(mockLogger);
43: try {
44: JamesTestConfiguration conf = new JamesTestConfiguration();
45: conf.init();
46: james.configure(conf);
47: james.contextualize(new MockContext(File.createTempFile(
48: "james_test", "tmp")));
49: james.initialize();
50: } catch (Exception e) {
51: e.printStackTrace();
52: fail("James.initialize() failed");
53: }
54: return james;
55: }
56:
57: private MockServiceManager setUpServiceManager() {
58: MockServiceManager serviceManager = new MockServiceManager();
59: MockUsersRepository mockUsersRepository = new MockUsersRepository();
60: serviceManager.put(UsersRepository.ROLE, mockUsersRepository);
61: serviceManager.put(UsersStore.ROLE, new MockUsersStore(
62: mockUsersRepository));
63: MockStore mockStore = new MockStore();
64: mockStore.add(EXISTING_USER_NAME, new MockMailRepository());
65: serviceManager.put(Store.ROLE, mockStore);
66: return serviceManager;
67: }
68:
69: public boolean allowsPasswordlessUser() {
70: return false;
71: }
72:
73: public boolean canTestUserExists() {
74: return true;
75: }
76:
77: public boolean isUserExisting(MailServer mailServerImpl,
78: String username) {
79: return ((James) mailServerImpl).isLocalUser(username);
80: }
81: }
|