01: // StrutsTestCase - a JUnit extension for testing Struts actions
02: // within the context of the ActionServlet.
03: // Copyright (C) 2002 Deryl Seale
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the Apache Software License as
07: // published by the Apache Software Foundation; either version 1.1
08: // of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: // Apache Software Foundation Licens for more details.
14: //
15: // You may view the full text here: http://www.apache.org/LICENSE.txt
16:
17: package servletunit.tests;
18:
19: import junit.framework.TestCase;
20: import servletunit.ServletConfigSimulator;
21:
22: import java.util.Enumeration;
23:
24: public class TestInitParameters extends TestCase {
25:
26: ServletConfigSimulator config;
27:
28: public TestInitParameters(String testName) {
29: super (testName);
30: }
31:
32: public void setUp() {
33: config = new ServletConfigSimulator();
34: }
35:
36: public void testSetInitParameter() {
37: config.setInitParameter("test", "testValue");
38: assertEquals("testValue", config.getInitParameter("test"));
39: }
40:
41: public void testNoParameter() {
42: assertNull(config.getInitParameter("badValue"));
43: }
44:
45: public void testGetInitParameterNames() {
46: config.setInitParameter("test", "testValue");
47: config.setInitParameter("another", "anotherValue");
48: assertEquals("testValue", config.getInitParameter("test"));
49: assertEquals("anotherValue", config.getInitParameter("another"));
50: Enumeration names = config.getInitParameterNames();
51: boolean fail = true;
52: while (names.hasMoreElements()) {
53: fail = true;
54: String name = (String) names.nextElement();
55: if ((name.equals("test")) || (name.equals("another")))
56: fail = false;
57: }
58: if (fail)
59: fail();
60: }
61:
62: }
|