KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > handler > commands > LoginTest


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.handler.commands;
21
22 import org.apache.james.imapserver.ImapSessionState;
23 import org.apache.james.imapserver.ProtocolException;
24
25
26
27 public class LoginTest extends AbstractCommandTest
28 {
29
30     public void testValidUserStateNonAuth() throws ProtocolException {
31         mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.NON_AUTHENTICATED));
32         mockSession.expects(atLeastOnce()).method("getUsers").will(returnValue(mockUsersRepository.proxy()));
33         
34         mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(true));
35         mockUsersRepository.expects(once()).method("getUserByName").with( eq("joachim2")).will(returnValue(mockUser.proxy()));
36         
37         mockSession.expects(once()).method("setAuthenticated").with( same(mockUser.proxy()));
38
39         String JavaDoc response = handleRequest("1 LOGIN joachim2 abc\n");
40
41         assertEquals("1 OK LOGIN completed.\r\n",response);
42     }
43     public void testInvalidUserStateNonAuth() throws ProtocolException {
44         mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.NON_AUTHENTICATED));
45         mockSession.expects(atLeastOnce()).method("getUsers").will(returnValue(mockUsersRepository.proxy()));
46         
47         mockUsersRepository.expects(once()).method("test").with( eq("joachim2"),eq("abc")).will(returnValue(false));
48
49         String JavaDoc response = handleRequest("1 LOGIN joachim2 abc\n");
50
51         assertEquals("1 NO LOGIN failed. Invalid login/password\r\n",response);
52     }
53     public void testValidUserStateAuth() throws ProtocolException {
54         mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.AUTHENTICATED));
55
56         String JavaDoc response = handleRequest("1 LOGIN joachim2 abc\n");
57         assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
58     }
59
60     public void testValidUserStateLogout() throws ProtocolException {
61         mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.LOGOUT));
62
63         String JavaDoc response = handleRequest("1 LOGIN joachim2 abc\n");
64         assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
65     }
66     public void testValidUserStateSelected() throws ProtocolException {
67         mockSession.expects(atLeastOnce()).method("getState").will(returnValue(ImapSessionState.SELECTED));
68
69         String JavaDoc response = handleRequest("1 LOGIN joachim2 abc\n");
70         assertEquals("1 NO LOGIN failed. Command not valid in this state\r\n",response);
71     }
72 }
73
Popular Tags