1 20 package org.apache.cactus.sample.servlet.unit; 21 22 import java.util.Enumeration ; 23 24 import org.apache.cactus.ServletTestCase; 25 import org.apache.cactus.server.ServletContextWrapper; 26 27 32 public class TestServletContext extends ServletTestCase 33 { 34 37 private ServletContextWrapper context; 38 39 42 public void setUp() 43 { 44 context = (ServletContextWrapper) config.getServletContext(); 45 } 46 47 51 public void testSetContextInitParameterUsingApi() 52 { 53 context.setInitParameter("testparam", "test value"); 54 55 assertEquals("test value", context.getInitParameter("testparam")); 56 57 boolean found = false; 58 Enumeration en = context.getInitParameterNames(); 59 60 while (en.hasMoreElements()) 61 { 62 String name = (String ) en.nextElement(); 63 64 if (name.equals("testparam")) 65 { 66 found = true; 67 68 break; 69 } 70 } 71 72 assertTrue("[testparam] not found in parameter names", found); 73 } 74 75 77 81 public void testSetContextInitParameterOverrideWebXmlParameter() 82 { 83 assertTrue("'param' context-param should been defined in web.xml", 87 context.getOriginalContext().getInitParameter("param") != null); 88 assertTrue( 89 !context.getOriginalContext().getInitParameter("param").equals( 90 "testoverrideparam")); 91 92 context.setInitParameter("param", "testoverrideparam"); 93 94 Enumeration en = context.getInitParameterNames(); 95 int count = 0; 96 97 while (en.hasMoreElements()) 98 { 99 String name = (String ) en.nextElement(); 100 101 if (name.equals("param")) 102 { 103 assertEquals("testoverrideparam", 104 context.getInitParameter(name)); 105 count++; 106 } 107 } 108 109 assertTrue("[param] was found " + count + " times. Should have " 110 + "been found once.", count == 1); 111 } 112 113 } 114 | Popular Tags |