KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > junit > examples > SimpleLocalTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.junit.examples;
8
9
10 import java.io.File JavaDoc;
11 import java.io.InputStream JavaDoc;
12
13 import com.inversoft.junit.Request;
14 import com.inversoft.junit.Response;
15 import com.inversoft.junit.WebTestCase;
16 import com.inversoft.junit.internal.http.MockHttpServletRequest;
17
18
19 /**
20  * This class is a simple local test
21  */

22 public class SimpleLocalTest extends WebTestCase {
23
24     /**
25      * The standard JUnit constructor
26      */

27     public SimpleLocalTest(String JavaDoc name) {
28         super(name);
29         setLocal(true);
30     }
31
32     /**
33      * This tests the begin method
34      */

35     public void beginFoo(Request request) {
36         System.out.println("Inside beginFoo");
37     }
38
39     /**
40      * This tests the test method
41      */

42     public void testFoo() {
43         System.out.println("Inside testFoo");
44     }
45
46     /**
47      * This tests the end method
48      */

49     public void endFoo(Response response) {
50         System.out.println("Inside endFoo");
51     }
52
53     /**
54      * This tests the begin method
55      */

56     public void beginFailure(Request request) {
57         System.out.println("Inside beginFailure");
58     }
59
60     /**
61      * This tests the test method
62      */

63     public void testFailure() {
64         System.out.println("Inside testFailure");
65         fail("Failure");
66     }
67
68     /**
69      * This tests the end method
70      */

71     public void endFailure(Response response) {
72         System.out.println("SHOULD NOT BE HERE!!! - Inside endFailure");
73     }
74
75     /**
76      * This tests that the request can be cast and setup
77      */

78     public void beginRequestSetup(Request request) {
79         request.addParameter("test", "test");
80         assertTrue("The request variable of WebTestCase should be null",
81             this.request == null);
82     }
83
84     /**
85      * This tests that the request can be cast and setup
86      */

87     public void testRequestSetup() {
88         assertTrue("The request should be a Mock",
89             super.request instanceof MockHttpServletRequest);
90         assertTrue("The request should have a parameter",
91             super.request.getParameter("test").equals("test"));
92     }
93
94     /**
95      * This test that the context resolves resources correctly
96      */

97     public void testContextResource() {
98
99         File JavaDoc file = new File JavaDoc(".");
100         System.out.println("The current directory: " + file.getAbsolutePath());
101
102         InputStream JavaDoc is = context.getResourceAsStream("src/com/inversoft/junit/examples/junit.properties");
103         assertTrue("InputStream should not be null", is != null);
104     }
105 }
106
Popular Tags