324
public void testBug51376a() throws Exception {
325
doTestBug51376(false);
328
public void testBug51376b() throws Exception {
329
doTestBug51376(true);
332
private void doTestBug51376(boolean loadOnStartUp) throws Exception {
334
// Set up a container
335
Tomcat tomcat = getTomcatInstance();
337
// Must have a real docBase - just use temp
338
File docBase = new File(System.getProperty("java.io.tmpdir"));
339
Context ctx = tomcat.addContext("", docBase.getAbsolutePath());
341
// Add ServletContainerInitializer
342
Bug51376SCI sci = new Bug51376SCI(loadOnStartUp);
343
ctx.addServletContainerInitializer(sci, null);
351
// Make sure that init() and destroy() were called correctly
352
assertTrue(sci.getServlet().isOk());
355
public static final class Bug51376SCI
356
implements ServletContainerInitializer {
358
private Bug51376Servlet s = null;
359
private boolean loadOnStartUp;
361
public Bug51376SCI(boolean loadOnStartUp) {
362
this.loadOnStartUp = loadOnStartUp;
365
private Bug51376Servlet getServlet() {
370
public void onStartup(Set<Class<?>> c, ServletContext ctx)
371
throws ServletException {
372
// Register and map servlet
373
s = new Bug51376Servlet();
374
ServletRegistration.Dynamic sr = ctx.addServlet("bug51376", s);
375
sr.addMapping("/bug51376");
377
sr.setLoadOnStartup(1);
382
public static final class Bug51376Servlet extends HttpServlet {
384
private static final long serialVersionUID = 1L;
386
private Boolean initOk = null;
387
private Boolean destoryOk = null;
391
if (initOk == null && destoryOk == null) {
392
initOk = Boolean.TRUE;
394
initOk = Boolean.FALSE;
399
public void destroy() {
400
if (initOk.booleanValue() && destoryOk == null) {
401
destoryOk = Boolean.TRUE;
403
destoryOk = Boolean.FALSE;
408
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
409
throws ServletException, IOException {
410
resp.setContentType("text/plain");
411
resp.getWriter().write("OK");
414
protected boolean isOk() {
415
if (initOk != null && initOk.booleanValue() && destoryOk != null &&
416
destoryOk.booleanValue()) {
418
} else if (initOk == null && destoryOk == null) {
325
427
* Test case for bug 49711: HttpServletRequest.getParts does not work