1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2;
23
24 import junit.framework.TestCase;
25
26 import org.apache.struts2.dispatcher.Dispatcher;
27 import org.testng.TestListenerAdapter;
28 import org.testng.TestNG;
29 import org.testng.annotations.Test;
30
31 import com.opensymphony.xwork2.config.ConfigurationManager;
32
33 public class TestNGStrutsTestCaseTest extends TestCase {
34
35 public void testSimpleTest() throws Exception {
36 TestListenerAdapter tla = new TestListenerAdapter();
37 TestNG testng = new TestNG();
38 testng.setTestClasses(new Class[] { RunTest.class });
39 testng.addListener(tla);
40 try {
41 testng.run();
42 assertEquals(1, tla.getPassedTests().size());
43 assertEquals(0, tla.getFailedTests().size());
44 assertTrue(RunTest.ran);
45 assertNotNull(RunTest.mgr);
46 assertNotNull(RunTest.du);
47 assertNull(Dispatcher.getInstance());
48 } finally {
49 RunTest.mgr = null;
50 }
51 }
52
53 public static class RunTest extends StrutsTestCase {
54 public static boolean ran = false;
55 public static ConfigurationManager mgr;
56 public static Dispatcher du;
57
58 @Test
59 public void testRun() {
60 ran = true;
61 mgr = this.configurationManager;
62 du = Dispatcher.getInstance();
63 }
64 }
65 }
66