KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > tests > TestInitParameters


1 // StrutsTestCase - a JUnit extension for testing Struts actions
2
// within the context of the ActionServlet.
3
// Copyright (C) 2002 Deryl Seale
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the Apache Software License as
7
// published by the Apache Software Foundation; either version 1.1
8
// of the License, or (at your option) any later version.
9
//
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 JavaDoc;
23
24 public class TestInitParameters extends TestCase {
25
26     ServletConfigSimulator config;
27
28     public TestInitParameters(String JavaDoc 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 JavaDoc names = config.getInitParameterNames();
51         boolean fail = true;
52         while (names.hasMoreElements()) {
53             fail = true;
54             String JavaDoc name = (String JavaDoc) names.nextElement();
55             if ((name.equals("test")) || (name.equals("another")))
56                 fail = false;
57         }
58         if (fail)
59             fail();
60     }
61
62 }
63
64
65
Popular Tags