Author: rdonkin
Date: Fri Aug 10 09:27:27 2007
New Revision: 564655

URL: http://svn.apache.org/viewvc?view=rev&rev=564655
Log:
Encoder for new messages

Added:
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/AbstactStatusResponseFactory.java
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/ImmutableStatusResponse.java
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactory.java
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoder.java
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusCommandResponseEncoder.java
      - copied, changed from r564494, 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusResponseEncoder.java
    james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/response/
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/response/imap4rev1/
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/response/imap4rev1/status/
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactoryTest.java
    
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java
Removed:
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusResponseEncoder.java
Modified:
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
    
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java

Added: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/AbstactStatusResponseFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/AbstactStatusResponseFactory.java?view=auto&rev=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/AbstactStatusResponseFactory.java
 (added)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/AbstactStatusResponseFactory.java
 Fri Aug 10 09:27:27 2007
@@ -0,0 +1,99 @@
+/****************************************************************
+ * 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.imap.message.response.imap4rev1.status;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.display.HumanReadableTextKey;
+import org.apache.james.api.imap.message.response.imap4rev1.StatusResponse;
+import 
org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
+import 
org.apache.james.api.imap.message.response.imap4rev1.StatusResponse.ResponseCode;
+
+public abstract class AbstactStatusResponseFactory implements 
StatusResponseFactory {
+
+    public AbstactStatusResponseFactory() {
+        super();
+    }
+
+    protected abstract StatusResponse createResponse(StatusResponse.Type type, 
String tag, ImapCommand command, HumanReadableTextKey displayTextKey, 
ResponseCode code);
+    
+    public StatusResponse bye(HumanReadableTextKey displayTextKey, 
ResponseCode code) {
+        return createResponse(StatusResponse.Type.BYE, null, null, 
displayTextKey, code);
+    }
+
+    public StatusResponse bye(HumanReadableTextKey displayTextKey) {
+        return bye(displayTextKey, null);
+    }
+
+    public StatusResponse preauth(HumanReadableTextKey displayTextKey, 
ResponseCode code)  {
+        return createResponse(StatusResponse.Type.PREAUTH, null, null, 
displayTextKey, code);
+    }
+    
+    public StatusResponse preauth(HumanReadableTextKey displayTextKey) {
+        return preauth(displayTextKey, null);
+    }
+
+    public StatusResponse taggedBad(String tag, ImapCommand command, 
HumanReadableTextKey displayTextKey, ResponseCode code)  {
+        return createResponse(StatusResponse.Type.BAD, tag, command, 
displayTextKey, code);
+    }
+
+    public StatusResponse taggedBad(String tag, ImapCommand command, 
HumanReadableTextKey displayTextKey) {
+        return taggedBad(tag, command, displayTextKey, null);
+    }
+
+    public StatusResponse taggedNo(String tag, ImapCommand command, 
HumanReadableTextKey displayTextKey, ResponseCode code)  {
+        return createResponse(StatusResponse.Type.NO, tag, command, 
displayTextKey, code);
+    }
+
+    public StatusResponse taggedNo(String tag, ImapCommand command, 
HumanReadableTextKey displayTextKey) {
+        return taggedNo(tag, command, displayTextKey, null);
+    }
+
+    public StatusResponse taggedOk(String tag, ImapCommand command, 
HumanReadableTextKey displayTextKey, ResponseCode code)  {
+        return createResponse(StatusResponse.Type.OK, tag, command, 
displayTextKey, code);
+    }
+
+    public StatusResponse taggedOk(String tag, ImapCommand command, 
HumanReadableTextKey displayTextKey) {
+        return taggedOk(tag, command, displayTextKey, null);
+    }
+
+    public StatusResponse untaggedBad(HumanReadableTextKey displayTextKey, 
ResponseCode code) {
+        return taggedBad(null, null, displayTextKey, code);
+    }
+
+    public StatusResponse untaggedBad(HumanReadableTextKey displayTextKey) {
+        return untaggedBad(displayTextKey, null);
+    }
+
+    public StatusResponse untaggedNo(HumanReadableTextKey displayTextKey, 
ResponseCode code) {
+        return taggedNo(null, null, displayTextKey, code);
+    }
+
+    public StatusResponse untaggedNo(HumanReadableTextKey displayTextKey) {
+        return untaggedNo(displayTextKey, null);
+    }
+
+    public StatusResponse untaggedOk(HumanReadableTextKey displayTextKey, 
ResponseCode code) {
+        return taggedOk(null, null, displayTextKey, code);
+    }
+
+    public StatusResponse untaggedOk(HumanReadableTextKey displayTextKey) {
+        return untaggedOk(displayTextKey, null);
+    }
+}
\ No newline at end of file

Added: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/ImmutableStatusResponse.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/ImmutableStatusResponse.java?view=auto&rev=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/ImmutableStatusResponse.java
 (added)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/ImmutableStatusResponse.java
 Fri Aug 10 09:27:27 2007
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.imap.message.response.imap4rev1.status;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.display.HumanReadableTextKey;
+import org.apache.james.api.imap.message.response.imap4rev1.StatusResponse;
+
+/**
+ * Immutable status response.
+ * Suitable for unpooled usage.
+ * @see [EMAIL PROTECTED] StatusResponse}
+ */
+public class ImmutableStatusResponse implements StatusResponse {
+
+    private final ResponseCode responseCode;
+    private final Type serverResponseType;
+    private final String tag;
+    private final HumanReadableTextKey textKey;
+    private final ImapCommand command;
+    
+    public ImmutableStatusResponse(final Type serverResponseType, final String 
tag, final ImapCommand command,
+            final HumanReadableTextKey textKey, final ResponseCode 
responseCode) {
+        super();
+        this.responseCode = responseCode;
+        this.serverResponseType = serverResponseType;
+        this.tag = tag;
+        this.textKey = textKey;
+        this.command = command;
+    }
+
+    /**
+     * @see [EMAIL PROTECTED] StatusResponse#getResponseCode()}
+     */
+    public ResponseCode getResponseCode() {
+        return responseCode;
+    }
+
+    /**
+     * @see [EMAIL PROTECTED] StatusResponse#getServerResponseType()}
+     */
+    public Type getServerResponseType() {
+        return serverResponseType;
+    }
+
+    /**
+     * @see [EMAIL PROTECTED] StatusResponse#getTag()}
+     */
+    public String getTag() {
+        return tag;
+    }
+
+    /**
+     * @see [EMAIL PROTECTED] StatusResponse#getTextKey()}
+     */
+    public HumanReadableTextKey getTextKey() {
+        return textKey;
+    }
+
+    public ImapCommand getCommand() {
+        return command;
+    }
+}

Added: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactory.java?view=auto&rev=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactory.java
 (added)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactory.java
 Fri Aug 10 09:27:27 2007
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.imap.message.response.imap4rev1.status;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.display.HumanReadableTextKey;
+import org.apache.james.api.imap.message.response.imap4rev1.StatusResponse;
+import 
org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
+import 
org.apache.james.api.imap.message.response.imap4rev1.StatusResponse.ResponseCode;
+import 
org.apache.james.api.imap.message.response.imap4rev1.StatusResponse.Type;
+
+public class UnpooledStatusResponseFactory extends 
AbstactStatusResponseFactory implements StatusResponseFactory {
+
+    protected StatusResponse createResponse(Type type, String tag, ImapCommand 
command, HumanReadableTextKey displayTextKey, ResponseCode code) {
+        return new ImmutableStatusResponse(type, tag, command, displayTextKey, 
code);
+    }
+
+
+}

Modified: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java?view=diff&rev=564655&r1=564654&r2=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/ImapResponseComposer.java
 Fri Aug 10 09:27:27 2007
@@ -343,4 +343,23 @@
     public void tag(String tag) {
         writer.tag(tag);
     }
+    
+    public void statusResponse(String tag, ImapCommand command, String type, 
String responseCode, String text) {
+        if (tag == null) {
+            untagged();
+        } else {
+            tag(tag);
+        }
+        message(type);
+        if (responseCode != null) {
+            message(responseCode);
+        }
+        if (command != null) {
+            commandName(command);
+        }
+        if (text != null) {
+            message(text);
+        }
+        end();
+    }
 }

Added: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoder.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoder.java?view=auto&rev=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoder.java
 (added)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoder.java
 Fri Aug 10 09:27:27 2007
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.codec.encode.imap4rev1;
+
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.display.HumanReadableTextKey;
+import org.apache.james.api.imap.message.response.imap4rev1.StatusResponse;
+import org.apache.james.imapserver.codec.encode.ImapEncoder;
+import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
+import 
org.apache.james.imapserver.codec.encode.base.AbstractChainedImapEncoder;
+
+public class StatusResponseEncoder extends AbstractChainedImapEncoder {
+
+    public StatusResponseEncoder(ImapEncoder next) {
+        super(next);
+    }
+
+    protected void doEncode(ImapMessage acceptableMessage,
+            ImapResponseComposer composer) {
+        StatusResponse response = (StatusResponse) acceptableMessage;
+        composer.statusResponse(response.getTag(), response.getCommand(), 
+                asString(response.getServerResponseType()), 
asString(response.getResponseCode()),
+                asString(response.getTextKey()));
+    }
+
+    private String asString(HumanReadableTextKey text)
+    {
+        final String result;
+        if (text == null) {
+            result = null;
+        } else {
+            result = text.getDefaultValue();
+        }
+        return result;
+    }
+    
+    private String asString(StatusResponse.ResponseCode code)
+    {
+        final String result;
+        if (code == null) {
+            result = null;
+        } else {
+            result = code.getCode();
+        }
+        return result;
+    }
+    
+    private String asString(StatusResponse.Type type)
+    {
+        final String result;
+        if (type == null) {
+            result = null;
+        } else {
+            result = type.getCode();
+        }
+        return result;
+    }
+    
+    protected boolean isAcceptable(ImapMessage message) {
+        return (message instanceof StatusResponse);
+    }
+
+}

Copied: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusCommandResponseEncoder.java
 (from r564494, 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusResponseEncoder.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusCommandResponseEncoder.java?view=diff&rev=564655&p1=james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusResponseEncoder.java&r1=564494&p2=james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusCommandResponseEncoder.java&r2=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusResponseEncoder.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/imap4rev1/legacy/StatusCommandResponseEncoder.java
 Fri Aug 10 09:27:27 2007
@@ -30,9 +30,9 @@
 /**
  * @deprecated responses should correspond directly to the specification
  */
-public class StatusResponseEncoder extends AbstractChainedImapEncoder {
+public class StatusCommandResponseEncoder extends AbstractChainedImapEncoder {
     
-    public StatusResponseEncoder(ImapEncoder next) {
+    public StatusCommandResponseEncoder(ImapEncoder next) {
         super(next);
     }
 

Modified: 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java?view=diff&rev=564655&r1=564654&r2=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java
 (original)
+++ 
james/server/trunk/imap-codec-library/src/main/java/org/apache/james/imapserver/codec/encode/main/DefaultImapEncoderFactory.java
 Fri Aug 10 09:27:27 2007
@@ -26,6 +26,7 @@
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.ExpungeResponseEncoder;
 import org.apache.james.imapserver.codec.encode.imap4rev1.FetchResponseEncoder;
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.RecentResponseEncoder;
+import 
org.apache.james.imapserver.codec.encode.imap4rev1.StatusResponseEncoder;
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.BadResponseEncoder;
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.CapabilityResponseEncoder;
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.CloseResponseEncoder;
@@ -37,7 +38,7 @@
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.ListResponseEncoder;
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.LogoutResponseEncoder;
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.SearchResponseEncoder;
-import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.StatusResponseEncoder;
+import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.StatusCommandResponseEncoder;
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.StoreResponseEncoder;
 import 
org.apache.james.imapserver.codec.encode.imap4rev1.status.UntaggedNoResponseEncoder;
 
@@ -48,14 +49,15 @@
     
     public static final ImapEncoder createDefaultEncoder() {
         final EndImapEncoder endImapEncoder = new EndImapEncoder();
-        final UntaggedNoResponseEncoder untaggedNoResponseEncoder = new 
UntaggedNoResponseEncoder(endImapEncoder);
+        final StatusResponseEncoder statusResponseEncoder = new 
StatusResponseEncoder(endImapEncoder);
+        final UntaggedNoResponseEncoder untaggedNoResponseEncoder = new 
UntaggedNoResponseEncoder(statusResponseEncoder);
         final RecentResponseEncoder recentResponseEncoder = new 
RecentResponseEncoder(untaggedNoResponseEncoder);
         final FetchResponseEncoder fetchResponseEncoder = new 
FetchResponseEncoder(recentResponseEncoder);
         final ExpungeResponseEncoder expungeResponseEncoder = new 
ExpungeResponseEncoder(fetchResponseEncoder);
         final ExistsResponseEncoder existsResponseEncoder = new 
ExistsResponseEncoder(expungeResponseEncoder);
         final StoreResponseEncoder storeResponseEncoder = new 
StoreResponseEncoder(existsResponseEncoder);
-        final StatusResponseEncoder statusResponseEncoder = new 
StatusResponseEncoder(storeResponseEncoder);
-        final SearchResponseEncoder searchResponseEncoder = new 
SearchResponseEncoder(statusResponseEncoder);
+        final StatusCommandResponseEncoder statusCommandResponseEncoder = new 
StatusCommandResponseEncoder(storeResponseEncoder);
+        final SearchResponseEncoder searchResponseEncoder = new 
SearchResponseEncoder(statusCommandResponseEncoder);
         final LogoutResponseEncoder logoutResponseEncoder = new 
LogoutResponseEncoder(searchResponseEncoder);
         final ListResponseEncoder listResponseEncoder = new 
ListResponseEncoder(logoutResponseEncoder);
         final LegacyFetchResponseEncoder legacyFetchResponseEncoder = new 
LegacyFetchResponseEncoder(listResponseEncoder);

Added: 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactoryTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactoryTest.java?view=auto&rev=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactoryTest.java
 (added)
+++ 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imap/message/response/imap4rev1/status/UnpooledStatusResponseFactoryTest.java
 Fri Aug 10 09:27:27 2007
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.imap.message.response.imap4rev1.status;
+
+import 
org.apache.james.api.imap.message.response.imap4rev1.AbstractTestForStatusResponseFactory;
+import 
org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory;
+
+public class UnpooledStatusResponseFactoryTest extends
+        AbstractTestForStatusResponseFactory {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    protected StatusResponseFactory createInstance() {
+        return new UnpooledStatusResponseFactory();
+    }
+
+}

Added: 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java?view=auto&rev=564655
==============================================================================
--- 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java
 (added)
+++ 
james/server/trunk/imap-codec-library/src/test/java/org/apache/james/imapserver/codec/encode/imap4rev1/StatusResponseEncoderTest.java
 Fri Aug 10 09:27:27 2007
@@ -0,0 +1,256 @@
+/****************************************************************
+ * 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.codec.encode.imap4rev1;
+
+import org.apache.james.api.imap.ImapCommand;
+import org.apache.james.api.imap.ImapConstants;
+import org.apache.james.api.imap.ImapMessage;
+import org.apache.james.api.imap.display.HumanReadableTextKey;
+import org.apache.james.api.imap.message.response.imap4rev1.StatusResponse;
+import org.apache.james.imapserver.codec.encode.ImapEncoder;
+import org.apache.james.imapserver.codec.encode.ImapResponseComposer;
+import 
org.apache.james.imapserver.codec.encode.imap4rev1.legacy.MockImapResponseWriter;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+public class StatusResponseEncoderTest extends MockObjectTestCase {
+
+    private static final String COMMAND = "COMMAND";
+    private static final String TAG = "TAG";
+    private static final HumanReadableTextKey KEY = new 
HumanReadableTextKey("KEY", "TEXT");
+    
+    MockImapResponseWriter writer;
+    ImapResponseComposer response;
+    Mock mockNextEncoder;
+    Mock mockStatusResponse;
+    StatusResponseEncoder encoder;
+    Mock mockCommand;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        writer = new MockImapResponseWriter();
+        response = new ImapResponseComposer(writer);
+        mockNextEncoder = mock(ImapEncoder.class);
+        mockStatusResponse = mock(StatusResponse.class);
+        encoder = new StatusResponseEncoder((ImapEncoder) 
mockNextEncoder.proxy());
+        mockCommand = mock(ImapCommand.class);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testTaggedOkCode() throws Exception {
+        execute(StatusResponse.Type.OK, StatusResponse.ResponseCode.ALERT, 
KEY, TAG);
+        assertEquals(6, this.writer.operations.size());
+        assertEquals(new MockImapResponseWriter.TagOperation(TAG), 
writer.operations.get(0));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(ImapConstants.OK), 
+                writer.operations.get(1));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(StatusResponse.ResponseCode.ALERT.getCode()),
+                writer.operations.get(2));
+        assertEquals(new MockImapResponseWriter.CommandNameOperation(COMMAND),
+                writer.operations.get(3));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(4));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(5));        
+    }
+    
+    public void testTaggedOkNoCode() throws Exception {
+        execute(StatusResponse.Type.OK, null, KEY, TAG);
+        assertEquals(5, this.writer.operations.size());
+        assertEquals(new MockImapResponseWriter.TagOperation(TAG), 
writer.operations.get(0));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(ImapConstants.OK), 
+                writer.operations.get(1));
+        assertEquals(new MockImapResponseWriter.CommandNameOperation(COMMAND),
+                writer.operations.get(2));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(3));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(4));        
+    }
+
+    public void testTaggedBadCode() throws Exception {
+        execute(StatusResponse.Type.BAD, StatusResponse.ResponseCode.ALERT, 
KEY, TAG);
+        assertEquals(6, this.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(StatusResponse.ResponseCode.ALERT.getCode()),
+                writer.operations.get(2));
+        assertEquals(new MockImapResponseWriter.CommandNameOperation(COMMAND),
+                writer.operations.get(3));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(4));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(5));        
+    }
+    
+    public void testTaggedBadNoCode() throws Exception {
+        execute(StatusResponse.Type.BAD, null, KEY, TAG);
+        assertEquals(5, this.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.CommandNameOperation(COMMAND),
+                writer.operations.get(2));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(3));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(4));        
+    }
+
+    public void testTaggedNoCode() throws Exception {
+        execute(StatusResponse.Type.NO, StatusResponse.ResponseCode.ALERT, 
KEY, TAG);
+        assertEquals(6, this.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.TextMessageOperation(StatusResponse.ResponseCode.ALERT.getCode()),
+                writer.operations.get(2));
+        assertEquals(new MockImapResponseWriter.CommandNameOperation(COMMAND),
+                writer.operations.get(3));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(4));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(5));        
+    }
+    
+    public void testTaggedNoNoCode() throws Exception {
+        execute(StatusResponse.Type.NO, null, KEY, TAG);
+        assertEquals(5, this.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(COMMAND),
+                writer.operations.get(2));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(3));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(4));        
+    }
+    
+
+    public void testUntaggedOkCode() throws Exception {
+        execute(StatusResponse.Type.OK, StatusResponse.ResponseCode.ALERT, 
KEY, null);
+        assertEquals(5, this.writer.operations.size());
+        assertEquals(new MockImapResponseWriter.UntaggedOperation(), 
writer.operations.get(0));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(ImapConstants.OK), 
+                writer.operations.get(1));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(StatusResponse.ResponseCode.ALERT.getCode()),
+                writer.operations.get(2));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(3));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(4));        
+    }
+    
+    public void testUntaggedOkNoCode() throws Exception {
+        execute(StatusResponse.Type.OK, null, KEY, null);
+        assertEquals(4, this.writer.operations.size());
+        assertEquals(new MockImapResponseWriter.UntaggedOperation(), 
writer.operations.get(0));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(ImapConstants.OK), 
+                writer.operations.get(1));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(2));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(3));        
+    }
+
+    public void testUntaggedBadCode() throws Exception {
+        execute(StatusResponse.Type.BAD, StatusResponse.ResponseCode.ALERT, 
KEY, null);
+        assertEquals(5, this.writer.operations.size());
+        assertEquals(new MockImapResponseWriter.UntaggedOperation(), 
writer.operations.get(0));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(ImapConstants.BAD), 
+                writer.operations.get(1));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(StatusResponse.ResponseCode.ALERT.getCode()),
+                writer.operations.get(2));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(3));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(4));        
+    }
+    
+    public void testUntaggedBadNoCode() throws Exception {
+        execute(StatusResponse.Type.BAD, null, KEY, null);
+        assertEquals(4, this.writer.operations.size());
+        assertEquals(new MockImapResponseWriter.UntaggedOperation(), 
writer.operations.get(0));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(ImapConstants.BAD), 
+                writer.operations.get(1));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(2));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(3));        
+    }
+
+    public void testUntaggedNoCode() throws Exception {
+        execute(StatusResponse.Type.NO, StatusResponse.ResponseCode.ALERT, 
KEY, null);
+        assertEquals(5, this.writer.operations.size());
+        assertEquals(new MockImapResponseWriter.UntaggedOperation(), 
writer.operations.get(0));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(ImapConstants.NO), 
+                writer.operations.get(1));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(StatusResponse.ResponseCode.ALERT.getCode()),
+                writer.operations.get(2));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(3));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(4));        
+    }
+    
+    public void testUntaggedNoNoCode() throws Exception {
+        execute(StatusResponse.Type.NO, null, KEY, null);
+        assertEquals(4, this.writer.operations.size());
+        assertEquals(new MockImapResponseWriter.UntaggedOperation(), 
writer.operations.get(0));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(ImapConstants.NO), 
+                writer.operations.get(1));
+        assertEquals(new 
MockImapResponseWriter.TextMessageOperation(KEY.getDefaultValue()),
+                writer.operations.get(2));
+        assertEquals(new MockImapResponseWriter.EndOperation(), 
+                writer.operations.get(3));        
+    }
+    
+
+    
+    private void execute(StatusResponse.Type type, StatusResponse.ResponseCode 
code, 
+            HumanReadableTextKey key, String tag) throws Exception {
+        configure(type, code, key, tag);
+        compose();
+    }
+    
+    
+    private void compose() throws Exception {
+       encoder.doEncode((ImapMessage) mockStatusResponse.proxy(), response); 
+    }
+    
+    private void configure(StatusResponse.Type type, 
StatusResponse.ResponseCode code, 
+            HumanReadableTextKey key, String tag) {
+        
mockStatusResponse.expects(once()).method("getServerResponseType").will(returnValue(type));
+        
mockStatusResponse.expects(once()).method("getTag").will(returnValue(tag));
+        
mockStatusResponse.expects(once()).method("getTextKey").will(returnValue(key));
+        
mockStatusResponse.expects(once()).method("getResponseCode").will(returnValue(code));
+
+        if (tag == null) {
+            
mockStatusResponse.expects(once()).method("getCommand").will(returnValue(null));
+        } else {
+            
mockCommand.expects(once()).method("getName").will(returnValue(COMMAND));
+            
mockStatusResponse.expects(once()).method("getCommand").will(returnValue(mockCommand.proxy()));
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to