1   /*
2    * Copyright 2004-2009 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.examples.s2.action;
17  
18  import org.seasar.cubby.action.ActionErrors;
19  import org.seasar.cubby.action.ActionResult;
20  import org.seasar.cubby.action.Forward;
21  import org.seasar.cubby.examples.s2.action.HelloAction;
22  import org.seasar.cubby.plugins.s2.unit.CubbyTestCase;
23  
24  public class HelloActionTest extends CubbyTestCase {
25  
26  	public HelloAction action;
27  
28  	public ActionErrors actionErrors;
29  
30  	protected void setUp() throws Exception {
31  		include("app.dicon");
32  	}
33  
34  	public void testIndex() throws Exception {
35  		ActionResult result = processAction("/hello/");
36  		assertPathEquals(Forward.class, "index.jsp", result);
37  	}
38  
39  	public void setUpMessage() {
40  		getRequest().addParameter("name", "name1");
41  	}
42  
43  	public void testMessage() throws Exception {
44  		ActionResult result = processAction("/hello/message");
45  		assertPathEquals(Forward.class, "hello.jsp", result);
46  		assertEquals("name1", action.name);
47  		assertEquals("name1 Hello!", action.message);
48  	}
49  	
50  	public void testMessage_validationError() throws Exception {
51  		ActionResult result = processAction("/hello/message");
52  		assertPathEquals(Forward.class, "index.jsp", result);
53  		assertNull(action.name);
54  		assertEquals(0, actionErrors.getOthers().size());
55  		assertEquals(1, actionErrors.getFields().size());
56  		assertEquals(1, actionErrors.getFields().get("name").size());
57  		assertEquals("あなたの名前は必須です。", actionErrors.getFields().get("name").get(0));
58  		assertNull(action.name);
59  		assertNull(action.message);
60  	}
61  
62  }