View Javadoc

1   /*
2    * $Id: ActionComponentTest.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.components;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import org.apache.struts2.StrutsTestCase;
28  import org.springframework.mock.web.MockHttpServletRequest;
29  import org.springframework.mock.web.MockHttpServletResponse;
30  
31  import com.mockobjects.dynamic.Mock;
32  import com.opensymphony.xwork2.util.ValueStack;
33  
34  public class ActionComponentTest extends StrutsTestCase {
35  
36      public void testCreateParametersForContext() throws Exception {
37          MockHttpServletRequest req = new MockHttpServletRequest();
38          MockHttpServletResponse res = new MockHttpServletResponse();
39          Mock mockValueStack = new Mock(ValueStack.class);
40          HashMap ctx = new HashMap();
41          mockValueStack.expectAndReturn("getContext", ctx);
42          mockValueStack.expectAndReturn("getContext", ctx);
43          mockValueStack.expectAndReturn("getContext", ctx);
44          
45          ActionComponent comp = new ActionComponent((ValueStack) mockValueStack.proxy(), req, res);
46          comp.addParameter("foo", "bar");
47          comp.addParameter("baz", new String[]{"jim", "sarah"});
48          Map params = comp.createParametersForContext();
49          assertNotNull(params);
50          assertEquals(2, params.size());
51          assertEquals("bar", ((String[])params.get("foo"))[0]);
52          assertEquals(2, ((String[])params.get("baz")).length);
53          mockValueStack.verify();
54      }
55  }