01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.action;
19:
20: import de.finix.contelligent.HTTPCallData;
21: import de.finix.contelligent.core.HTTPCallDataImpl;
22: import de.finix.contelligent.test.ContelligentTestCase;
23: import de.finix.contelligent.test.mock.ContelligentMockHttpServletRequest;
24: import de.finix.contelligent.test.mock.MockContelligentSession;
25:
26: public class ActionParameterTests extends ContelligentTestCase {
27:
28: public ActionParameterTests(String s) {
29: super (s);
30: }
31:
32: public void testRequestValue() throws Exception {
33: ActionParameter parameter = new ActionParameter();
34: String PARAM_KEY = "/test/value";
35: parameter.setStorageKey(PARAM_KEY);
36: parameter.setStorageScope(StoredObject.SCOPE_REQUEST_STRING);
37:
38: final String PARAM_VALUE = "PARAM_VALUE";
39: ContelligentMockHttpServletRequest request = new ContelligentMockHttpServletRequest();
40: request.setupAddParameter(PARAM_KEY, PARAM_VALUE);
41: HTTPCallData callData = new HTTPCallDataImpl(null,
42: "http://test", "http://test", false, false, request,
43: null, null, true);
44:
45: Object o = parameter.getObject(callData);
46: assertTrue(
47: "ActionParameter.getObject() returned no String[] for param '"
48: + PARAM_KEY + "' with scope '"
49: + parameter.getStorageScope() + "'",
50: (o instanceof String[]));
51: String value = ((String[]) o)[0];
52: assertTrue(
53: "value of ActionParameter doesn't match, should be '"
54: + PARAM_VALUE + "' but is '" + value + "'!",
55: PARAM_VALUE.equals(value));
56: }
57:
58: public void testSessionValue() throws Exception {
59: ActionParameter parameter = new ActionParameter();
60: parameter.setStorageKey("/test/value");
61: parameter.setStorageScope(StoredObject.SCOPE_SESSION_STRING);
62:
63: ContelligentMockHttpServletRequest request = new ContelligentMockHttpServletRequest();
64: MockContelligentSession session = new MockContelligentSession();
65:
66: HTTPCallData callData = new HTTPCallDataImpl(session,
67: "http://test", "http://test", false, false, request,
68: null, null, true);
69: callData.setSessionAttribute(parameter.getStorageKey(),
70: "PARAM_NEW");
71: assertTrue(parameter.getObject(callData).equals("PARAM_NEW"));
72: }
73:
74: }
|