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: package servletunit.struts.tests;
17:
18: import servletunit.struts.*;
19: import java.io.File;
20:
21: /**
22: * <p>Title: NullPointerActionTest</p>
23: * <p>Description: Tests to confirm a NullPointerException
24: * thrown from a misbehaving action reaches the test.</p>
25: * <p>Copyright: Copyright (c) 2003</p>
26: * @author Sean Pritchard
27: * @version 1.0
28: */
29: public class TestNullPointerAction extends MockStrutsTestCase {
30:
31: public TestNullPointerAction() {
32: }
33:
34: public void setUp() throws Exception {
35: super .setUp();
36: this .setContextDirectory(new File(System.getProperty("basedir")
37: + "/src/examples"));
38: setConfigFile("/WEB-INF/struts-config-test.xml");
39: }
40:
41: public void testNullPointer() throws Exception {
42: try {
43: this .setRequestPathInfo("/testNullPointer");
44: this .actionPerform();
45: fail("Exception expected");
46: } catch (ExceptionDuringTestError e) {
47: //uncomment this to see a sample stack trace
48: //that users will see if their action throws an exception
49: // throw e;
50: }
51: }
52:
53: public void testNullPointerFromForm() throws Exception {
54: try {
55: this .setRequestPathInfo("/testNullPointerForm");
56: this .actionPerform();
57: fail("Exception expected");
58: } catch (ExceptionDuringTestError e) {
59: //uncomment this to see a sample stack trace
60: //that users will see if their action throws an exception
61: // throw e;
62: }
63: }
64:
65: public static void main(String[] args) {
66: junit.textui.TestRunner.run(TestNullPointerAction.class);
67: }
68:
69: }
|