1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.backsource.alert;
21
22 import java.lang.reflect.Constructor;
23 import java.util.Iterator;
24 import java.util.Properties;
25 import org.w3c.dom.Element;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 /***
33 * The alert test suite.
34 *
35 *<p>This is the central class in the alert framework. The ant driven junit
36 * tets will be run agains this class, and it is up the the class to return
37 * a TestSuite. This test suite is dynalically created throu reading of an
38 * alert XML file, where all the agents are specifyed.</p>
39 *
40 * @author <a href="mailto:pra@tim.se">Peter Antman</a>
41 * @version $Revision: 1.1.1.1 $
42 */
43
44 public class AlertCase{
45 static final Log log = LogFactory.getLog( AlertCase.class);
46 public AlertCase (){
47
48 }
49 public static junit.framework.Test suite() throws Exception{
50 TestSuite suite= new TestSuite();
51 try {
52
53
54 Iterator agents = PropertyUtil.getAgents().iterator();
55
56
57 while (agents.hasNext()) {
58 Element agent = (Element)agents.next();
59 String code = agent.getAttribute("code");
60 String method = agent.getAttribute("method");
61 String name =agent.getAttribute("name");
62 Properties prop = PropertyUtil.getProperties(agent);
63 suite.addTest(getTest(code,method,name,prop));
64 }
65
66 } catch (Exception e) {
67 log.error("Could not setup Agents",e);
68 throw e;
69 }
70 return suite;
71 }
72 /***
73 * Dynalically create an Agent.
74 *
75 * @param clazz the fully qualifyed name of the Agent class.
76 * @param test the name of the method to invoke on the test.
77 * @param name the unique agent name.
78 * @param prop the properties for the agent.
79 */
80 public static TestCase getTest(String clazz, String test, String name, Properties prop) throws Exception {
81 Class tc = Class.forName(clazz);
82 Constructor c = tc.getConstructor(new Class[] {String.class});
83
84 Object o = c.newInstance(new Object[] {test});
85 ((Agent)o).initialize(name,prop);
86
87
88 return (TestCase)o;
89 }
90 public static void main(String[] args){
91
92
93 }
94 }