1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.action;
17  
18  import javax.servlet.http.HttpServletResponse;
19  
20  import junit.framework.TestCase;
21  
22  import org.seasar.framework.mock.servlet.MockHttpServletRequest;
23  import org.seasar.framework.mock.servlet.MockHttpServletResponse;
24  import org.seasar.framework.mock.servlet.MockHttpServletResponseImpl;
25  import org.seasar.framework.mock.servlet.MockServletContext;
26  import org.seasar.framework.mock.servlet.MockServletContextImpl;
27  
28  public class SendErrorTest extends TestCase {
29  
30  	public void testSendError() throws Exception {
31  		MockServletContext context = new MockServletContextImpl("test");
32  		MockHttpServletRequest request = context.createRequest("foo");
33  		MockHttpServletResponse response = new MockHttpServletResponseImpl(
34  				request);
35  
36  		SendError sendError = new SendError(HttpServletResponse.SC_NOT_FOUND);
37  		sendError.execute(null, null, null, request, response);
38  
39  		assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
40  	}
41  
42  	public void testSendErrorWithMessage() throws Exception {
43  		MockServletContext context = new MockServletContextImpl("test");
44  		MockHttpServletRequest request = context.createRequest("foo");
45  		MockHttpServletResponse response = new MockHttpServletResponseImpl(
46  				request);
47  
48  		SendError sendError = new SendError(HttpServletResponse.SC_NOT_FOUND,
49  				"NOT FOUND");
50  		sendError.execute(null, null, null, request, response);
51  
52  		assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
53  		assertEquals("NOT FOUND", response.getMessage());
54  	}
55  }