1 package com.flexiblewebsolutions.xdriveunit;
2
3 import java.lang.reflect.Constructor;
4 import java.lang.reflect.InvocationTargetException;
5
6 import junit.framework.Test;
7
8 import com.flexiblewebsolutions.xml.util.XMLStringParser;
9
10 /***
11 * Wraps test cases with a Test Decorator
12 *
13 * @author Donavon Buss
14 */
15 class TestDecoratorLoader {
16 /***
17 * Apply a test decorator to a single test or test suite
18 *
19 * @param pDecString -
20 * XML configuration information for the Decorator
21 * @param pTest -
22 * Test to be wrapped by the decorator
23 * @return - Test that has been 'decorated'
24 */
25 public Test wrapTestWithDecorator(StringBuffer pDecString, Test pTest) {
26 String classname = XMLStringParser.getValueForTag(pDecString,
27 "decoratorclass");
28 StringBuffer parameters = new StringBuffer(XMLStringParser
29 .getValueForTag(pDecString, "parameterdata"));
30
31 Test thisTest = null;
32 try {
33 Class thisClass = Class.forName(classname);
34
35 Constructor constructor = thisClass.getConstructor(new Class[] {
36 Test.class, StringBuffer.class });
37 thisTest = (Test) constructor.newInstance(new Object[] { pTest,
38 parameters });
39 } catch (SecurityException e) {
40 e.printStackTrace();
41 } catch (IllegalArgumentException e) {
42 e.printStackTrace();
43 } catch (ClassNotFoundException e) {
44 e.printStackTrace();
45 } catch (NoSuchMethodException e) {
46 e.printStackTrace();
47 } catch (InstantiationException e) {
48 e.printStackTrace();
49 } catch (IllegalAccessException e) {
50 e.printStackTrace();
51 } catch (InvocationTargetException e) {
52 e.printStackTrace();
53 }
54 return (thisTest);
55 }
56 }