View Javadoc

1   /*
2    * $Id$
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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