Added: james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/MockImapResponseWriter.java URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/MockImapResponseWriter.java?view=auto&rev=503406 ============================================================================== --- james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/MockImapResponseWriter.java (added) +++ james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/MockImapResponseWriter.java Sun Feb 4 05:46:22 2007 @@ -0,0 +1,233 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.imapserver; + +import java.util.ArrayList; +import java.util.List; + +public class MockImapResponseWriter implements ImapResponseWriter { + + public final List operations = new ArrayList(); + + public void commandName(String commandName) { + operations.add(new CommandNameOperation(commandName)); + + } + + public void end() { + operations.add(new EndOperation()); + } + + public void message(String message) { + operations.add(new TextMessageOperation(message)); + } + + public void message(int number) { + operations.add(new NumericMessageOperation(number)); + } + + public void responseCode(String responseCode) { + operations.add(new ResponseCodeOperation(responseCode)); + } + + public void tag(String tag) { + operations.add(new TagOperation(tag)); + } + + public void untagged() { + operations.add(new UntaggedOperation()); + } + + public static class EndOperation { + public boolean equals(Object obj) { + return obj instanceof EndOperation; + } + + public int hashCode() { + return 3; + } + + } + + public static class TextMessageOperation { + public final String text; + public TextMessageOperation(String text) { + this.text = text; + } + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((text == null) ? 0 : text.hashCode()); + return result; + } + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final TextMessageOperation other = (TextMessageOperation) obj; + if (text == null) { + if (other.text != null) + return false; + } else if (!text.equals(other.text)) + return false; + return true; + } + + } + + public static class NumericMessageOperation { + public final int number; + public NumericMessageOperation(int number) { + this.number = number; + } + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + number; + return result; + } + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final NumericMessageOperation other = (NumericMessageOperation) obj; + if (number != other.number) + return false; + return true; + } + + } + + + public static class ResponseCodeOperation { + public final String responseCode; + + public ResponseCodeOperation(final String responseCode) { + super(); + this.responseCode = responseCode; + } + + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((responseCode == null) ? 0 : responseCode.hashCode()); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final ResponseCodeOperation other = (ResponseCodeOperation) obj; + if (responseCode == null) { + if (other.responseCode != null) + return false; + } else if (!responseCode.equals(other.responseCode)) + return false; + return true; + } + + } + + public static class CommandNameOperation { + public final String commandName; + + public CommandNameOperation(final String commandName) { + super(); + this.commandName = commandName; + } + + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((commandName == null) ? 0 : commandName.hashCode()); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final CommandNameOperation other = (CommandNameOperation) obj; + if (commandName == null) { + if (other.commandName != null) + return false; + } else if (!commandName.equals(other.commandName)) + return false; + return true; + } + + } + + public static class UntaggedOperation { + public boolean equals(Object obj) { + return obj instanceof UntaggedOperation; + } + + public int hashCode() { + return 2; + } + + } + + public static class TagOperation { + + private final String tag; + public TagOperation(String tag) { + this.tag = tag; + } + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((tag == null) ? 0 : tag.hashCode()); + return result; + } + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final TagOperation other = (TagOperation) obj; + if (tag == null) { + if (other.tag != null) + return false; + } else if (!tag.equals(other.tag)) + return false; + return true; + } + + } + + +}
Added: james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/MockImapSession.java URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/MockImapSession.java?view=auto&rev=503406 ============================================================================== --- james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/MockImapSession.java (added) +++ james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/MockImapSession.java Sun Feb 4 05:46:22 2007 @@ -0,0 +1,80 @@ +package org.apache.james.imapserver; + +import org.apache.james.imapserver.store.MailboxException; +import org.apache.james.mailboxmanager.MailboxManagerException; +import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession; +import org.apache.james.mailboxmanager.manager.MailboxManager; +import org.apache.james.services.User; +import org.apache.james.services.UsersRepository; + +public class MockImapSession implements ImapSession { + + public String clientHostName = "localhost"; + public String clientIP = "127.0.0.1"; + + public String buildFullName(String mailboxName) + throws MailboxManagerException { + return mailboxName; + } + + public void closeConnection() { + } + + public void closeConnection(String byeMessage) { + } + + public void closeMailbox() throws MailboxManagerException { + } + + public void deselect() { + } + + public String getClientHostname() { + return clientHostName; + } + + public String getClientIP() { + return clientIP; + } + + public MailboxManager getMailboxManager() throws MailboxManagerException { +// TODO: mock + return null; + } + + public SelectedMailboxSession getSelected() { +// TODO: mock + return null; + } + + public ImapSessionState getState() { +// TODO: mock + return null; + } + + public User getUser() { +// TODO: mock + return null; + } + + public UsersRepository getUsers() { + // TODO: mock + return null; + } + + public void setAuthenticated(User user) { + + } + + public void setSelected(ImapMailboxSession mailbox, boolean readOnly) + throws MailboxManagerException { + } + + public void unsolicitedResponses(ImapResponse response, boolean useUid) + throws MailboxException { + } + + public void unsolicitedResponses(ImapResponse request, + boolean omitExpunged, boolean useUid) throws MailboxException { + } +} Added: james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/CommandFailedResponseMessageTest.java URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/CommandFailedResponseMessageTest.java?view=auto&rev=503406 ============================================================================== --- james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/CommandFailedResponseMessageTest.java (added) +++ james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/CommandFailedResponseMessageTest.java Sun Feb 4 05:46:22 2007 @@ -0,0 +1,92 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.imapserver.commands; + +import org.apache.james.imapserver.ImapConstants; +import org.apache.james.imapserver.ImapResponse; +import org.apache.james.imapserver.ImapSession; +import org.apache.james.imapserver.MockImapResponseWriter; +import org.apache.james.imapserver.MockImapSession; + +import junit.framework.TestCase; + +public class CommandFailedResponseMessageTest extends TestCase { + + private static final String TAG = "A Tag"; + + MockImapResponseWriter writer; + ImapResponse response; + MockCommand command; + ImapSession session; + + protected void setUp() throws Exception { + super.setUp(); + writer = new MockImapResponseWriter(); + response = new ImapResponse(writer); + response.setTag(TAG); + command = new MockCommand(); + session = new MockImapSession(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testWithResponseCode() throws Exception { + String code = "A code"; + String message = "A message"; + CommandFailedResponseMessage responseMessage + = new CommandFailedResponseMessage(command, code, message); + responseMessage.encode(response, session); + assertEquals(7, writer.operations.size()); + assertEquals(new MockImapResponseWriter.TagOperation(TAG), writer.operations.get(0)); + assertEquals(new MockImapResponseWriter.TextMessageOperation(ImapConstants.NO), + writer.operations.get(1)); + assertEquals(new MockImapResponseWriter.ResponseCodeOperation(code), + writer.operations.get(2)); + assertEquals(new MockImapResponseWriter.CommandNameOperation(MockCommand.NAME), + writer.operations.get(3)); + assertEquals(new MockImapResponseWriter.TextMessageOperation(ImapResponse.FAILED), + writer.operations.get(4)); + assertEquals(new MockImapResponseWriter.TextMessageOperation(message), + writer.operations.get(5)); + assertEquals(new MockImapResponseWriter.EndOperation(), + writer.operations.get(6)); + } + + public void testWithoutResponseCode() throws Exception { + String message = "A message"; + CommandFailedResponseMessage responseMessage + = new CommandFailedResponseMessage(command, message); + responseMessage.encode(response, session); + assertEquals(6, writer.operations.size()); + assertEquals(new MockImapResponseWriter.TagOperation(TAG), writer.operations.get(0)); + assertEquals(new MockImapResponseWriter.TextMessageOperation(ImapConstants.NO), + writer.operations.get(1)); + assertEquals(new MockImapResponseWriter.CommandNameOperation(MockCommand.NAME), + writer.operations.get(2)); + assertEquals(new MockImapResponseWriter.TextMessageOperation(ImapResponse.FAILED), + writer.operations.get(3)); + assertEquals(new MockImapResponseWriter.TextMessageOperation(message), + writer.operations.get(4)); + assertEquals(new MockImapResponseWriter.EndOperation(), + writer.operations.get(5)); + } +} Added: james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/ErrorResponseMessageTest.java URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/ErrorResponseMessageTest.java?view=auto&rev=503406 ============================================================================== --- james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/ErrorResponseMessageTest.java (added) +++ james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/ErrorResponseMessageTest.java Sun Feb 4 05:46:22 2007 @@ -0,0 +1,61 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.imapserver.commands; + +import org.apache.james.imapserver.ImapConstants; +import org.apache.james.imapserver.ImapResponse; +import org.apache.james.imapserver.MockImapResponseWriter; + +import junit.framework.TestCase; + +public class ErrorResponseMessageTest extends TestCase { + + private static final String ERROR = "An error message"; + private static final String TAG = "A Tag"; + + ErrorResponseMessage message; + MockImapResponseWriter writer; + ImapResponse response; + + protected void setUp() throws Exception { + super.setUp(); + writer = new MockImapResponseWriter(); + response = new ImapResponse(writer); + response.setTag(TAG); + message = new ErrorResponseMessage(ERROR); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testWrite() { + message.encode(response, null); + assertEquals(4, writer.operations.size()); + assertEquals(new MockImapResponseWriter.TagOperation(TAG), writer.operations.get(0)); + assertEquals(new MockImapResponseWriter.TextMessageOperation(ImapConstants.BAD), + writer.operations.get(1)); + assertEquals(new MockImapResponseWriter.TextMessageOperation(ERROR), + writer.operations.get(2)); + assertEquals(new MockImapResponseWriter.EndOperation(), + writer.operations.get(3)); + } + +} Added: james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java?view=auto&rev=503406 ============================================================================== --- james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java (added) +++ james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/commands/MockCommand.java Sun Feb 4 05:46:22 2007 @@ -0,0 +1,24 @@ +package org.apache.james.imapserver.commands; + +import org.apache.james.imapserver.ImapRequestLineReader; +import org.apache.james.imapserver.ProtocolException; + +public class MockCommand extends CommandTemplate { + + public static final String NAME = "MOCK"; + + protected String getArgSyntax() { + return null; + } + + public String getName() { + return NAME; + } + + protected AbstractImapCommandMessage decode(ImapRequestLineReader request) throws ProtocolException { + // TODO implementation + return null; + } + + +} Added: james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/encode/RecordingImapResponseWriterTest.java URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/encode/RecordingImapResponseWriterTest.java?view=auto&rev=503406 ============================================================================== --- james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/encode/RecordingImapResponseWriterTest.java (added) +++ james/server/sandbox/seda-imap/src/test/org/apache/james/imapserver/encode/RecordingImapResponseWriterTest.java Sun Feb 4 05:46:22 2007 @@ -0,0 +1,109 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.imapserver.encode; + +import org.apache.james.imapserver.ImapResponse; +import org.apache.james.imapserver.MockImapResponseWriter; +import org.apache.james.imapserver.MockImapSession; + +import junit.framework.TestCase; + +public class RecordingImapResponseWriterTest extends TestCase { + + RecordingImapResponseWriter writer; + MockImapResponseWriter out; + ImapResponse response; + + protected void setUp() throws Exception { + super.setUp(); + out = new MockImapResponseWriter(); + response = new ImapResponse(out); + writer = new RecordingImapResponseWriter(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testProcess() { + assertEquals("Recorder is a response", writer, writer.process(new MockImapSession())); + } + + public void testCommandName() { + String name = "A command name"; + writer.commandName(name); + writer.encode(response, null); + assertEquals("Reply response", 1, out.operations.size()); + assertEquals("Reply response", new MockImapResponseWriter.CommandNameOperation(name), + out.operations.get(0)); + } + + public void testEnd() { + writer.end(); + writer.encode(response, null); + assertEquals("Reply response", 1, out.operations.size()); + assertEquals("Reply response", new MockImapResponseWriter.EndOperation(), + out.operations.get(0)); + } + + public void testMessageString() { + String message = "A message"; + writer.message(message); + writer.encode(response, null); + assertEquals("Reply response", 1, out.operations.size()); + assertEquals("Reply response", new MockImapResponseWriter.TextMessageOperation(message), + out.operations.get(0)); + } + + public void testMessageInt() { + int message = 42; + writer.message(message); + writer.encode(response, null); + assertEquals("Reply response", 1, out.operations.size()); + assertEquals("Reply response", new MockImapResponseWriter.NumericMessageOperation(message), + out.operations.get(0)); + } + + public void testResponseCode() { + String code = "A response code"; + writer.responseCode(code); + writer.encode(response, null); + assertEquals("Reply response", 1, out.operations.size()); + assertEquals("Reply response", new MockImapResponseWriter.ResponseCodeOperation(code), + out.operations.get(0)); + } + + public void testTag() { + String tag = "A tag"; + writer.tag(tag); + writer.encode(response, null); + assertEquals("Reply response", 1, out.operations.size()); + assertEquals("Reply response", new MockImapResponseWriter.TagOperation(tag), + out.operations.get(0)); + } + + public void testUntagged() { + writer.untagged(); + writer.encode(response, null); + assertEquals("Reply response", 1, out.operations.size()); + assertEquals("Reply response", new MockImapResponseWriter.UntaggedOperation(), + out.operations.get(0)); + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
