1package org.testng.reporters;
2
3import org.testng.ITestResult;
4
5import java.text.ParseException;
6import java.text.SimpleDateFormat;
7import java.util.HashMap;
8import java.util.Map;
9
10/**
11 * @author Hani Suleiman Date: Mar 27, 2007 Time: 9:16:28 AM
12 */
13public class XMLReporterConfig {
14
15  public static final String TAG_TEST = "test";
16  public static final String TAG_TEST_METHOD = "test-method";
17  public static final String TAG_EXCEPTION = "exception";
18  public static final String TAG_MESSAGE = "message";
19  public static final String TAG_SHORT_STACKTRACE = "short-stacktrace";
20  public static final String TAG_FULL_STACKTRACE = "full-stacktrace";
21  public static final String TAG_TESTNG_RESULTS = "testng-results";
22  public static final String TAG_SUITE = "suite";
23  public static final String TAG_GROUPS = "groups";
24  public static final String TAG_GROUP = "group";
25  public static final String TAG_CLASS = "class";
26  public static final String TAG_METHOD = "method";
27  public static final String TAG_PARAMS = "params";
28  public static final String TAG_PARAM = "param";
29  public static final String TAG_PARAM_VALUE = "value";
30  public static final String TAG_REPORTER_OUTPUT = "reporter-output";
31  public static final String TAG_LINE = "line";
32  public static final String TAG_ATTRIBUTES = "attributes";
33  public static final String TAG_ATTRIBUTE = "attribute";
34
35  public static final String ATTR_URL = "url";
36  public static final String ATTR_NAME = "name";
37  public static final String ATTR_STATUS = "status";
38  public static final String ATTR_DESC = "description";
39  public static final String ATTR_METHOD_SIG = "signature";
40  public static final String ATTR_GROUPS = "groups";
41  public static final String ATTR_CLASS = "class";
42  public static final String ATTR_TEST_INSTANCE_NAME = "test-instance-name";
43  public static final String ATTR_INDEX = "index";
44  public static final String ATTR_IS_NULL = "is-null";
45  public static final String ATTR_PACKAGE = "package";
46  public static final String ATTR_STARTED_AT = "started-at";
47  public static final String ATTR_FINISHED_AT = "finished-at";
48  public static final String ATTR_DURATION_MS = "duration-ms";
49  public static final String ATTR_IS_CONFIG = "is-config";
50  public static final String ATTR_DEPENDS_ON_METHODS = "depends-on-methods";
51  public static final String ATTR_DEPENDS_ON_GROUPS = "depends-on-groups";
52  public static final String ATTR_DATA_PROVIDER = "data-provider";
53
54  public static final String TEST_PASSED = "PASS";
55  public static final String TEST_FAILED = "FAIL";
56  public static final String TEST_SKIPPED = "SKIP";
57
58  private static Map<String, Integer> STATUSES = new HashMap<String, Integer>() {{
59    put(TEST_PASSED, ITestResult.SUCCESS);
60    put(TEST_FAILED, ITestResult.FAILURE);
61    put(TEST_SKIPPED, ITestResult.SKIP);
62  }};
63
64  public static Integer getStatus(String status) {
65    return STATUSES.get(status);
66  }
67
68  /**
69   * Indicates that no file fragmentation should be performed. This value
70   * indicates the XML generator to write all the results in one big file. Not
71   * recommended for large test suites.
72   */
73  public static final int FF_LEVEL_NONE = 1;
74  /**
75   * Will cause the XML generator to create separate files for each of the
76   * suites. A separate directory will be generated for each suite having the
77   * name of the suite and containing a <code>suite.xml</code> file that will be
78   * referenced in the main file with an <code>url</code> attribute
79   */
80  public static final int FF_LEVEL_SUITE = 2;
81  /**
82   * It behaves like <code>FF_LEVEL_SUITE</code>, except that it will also
83   * create a file for each <code>ISuiteResult</code>
84   */
85  public static final int FF_LEVEL_SUITE_RESULT = 3;
86
87  /**
88   * No stacktrace will be written in the output file
89   */
90  public static final int STACKTRACE_NONE = 0;
91  /**
92   * Write only a short version of the stacktrace
93   */
94  public static final int STACKTRACE_SHORT = 1;
95  /**
96   * Write only the full version of the stacktrace
97   */
98  public static final int STACKTRACE_FULL = 2;
99  /**
100   * Write both types of stacktrace
101   */
102  public static final int STACKTRACE_BOTH = 3;
103
104  // note: We're hardcoding the 'Z' because Java doesn't support all the
105  // intricacies of ISO-8601.
106  static final String FMT_DEFAULT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
107
108  /**
109   * Indicates the way that the file fragmentation should be performed. Set this
110   * property to one of the FF_LEVEL_* values for the desired output structure
111   */
112  private int fileFragmentationLevel = FF_LEVEL_NONE;
113
114  /**
115   * Stack trace output method for the failed tests using one of the
116   * STACKTRACE_* constants.
117   */
118  private int stackTraceOutputMethod = STACKTRACE_FULL;
119
120  /**
121   * The root output directory where the XMLs will be written. This will default
122   * for now to the default TestNG output directory
123   */
124  private String outputDirectory;
125
126  /**
127   * Indicates whether the <code>groups</code> attribute should be generated for
128   * a <code>test-method</code> element. Defaults to false due to the fact that
129   * this might be considered redundant because of the group generation in the
130   * suite file.
131   */
132  private boolean generateGroupsAttribute = false;
133
134  /**
135   * When <code>true</code> it will generate the &lt;class&lt; element with a
136   * <code>name</code> and a <code>package</code> attribute. Otherwise, the
137   * fully qualified name will be used for the <code>name</code> attribute.
138   */
139  private boolean splitClassAndPackageNames = false;
140
141  /**
142   * Indicates whether the <code>depends-on-methods</code> attribute should be
143   * generated for a <code>test-method</code> element
144   */
145  private boolean generateDependsOnMethods = true;
146
147  /**
148   * Indicates whether the <code>depends-on-groups</code> attribute should be
149   * generated for a <code>test-method</code> element
150   */
151  private boolean generateDependsOnGroups = true;
152
153  /**
154   * Indicates whether {@link ITestResult} attributes should be generated for
155   * each <code>test-method</code> element
156   */
157  private boolean generateTestResultAttributes = false;
158
159  /**
160   * The output format for timestamps
161   */
162  private String timestampFormat = FMT_DEFAULT;
163
164  public int getFileFragmentationLevel() {
165    return fileFragmentationLevel;
166  }
167
168  public void setFileFragmentationLevel(int fileFragmentationLevel) {
169    this.fileFragmentationLevel = fileFragmentationLevel;
170  }
171
172  public int getStackTraceOutputMethod() {
173    return stackTraceOutputMethod;
174  }
175
176  public void setStackTraceOutputMethod(int stackTraceOutputMethod) {
177    this.stackTraceOutputMethod = stackTraceOutputMethod;
178  }
179
180  public String getOutputDirectory() {
181    return outputDirectory;
182  }
183
184  public void setOutputDirectory(String outputDirectory) {
185    this.outputDirectory = outputDirectory;
186  }
187
188  public boolean isGenerateGroupsAttribute() {
189    return generateGroupsAttribute;
190  }
191
192  public void setGenerateGroupsAttribute(boolean generateGroupsAttribute) {
193    this.generateGroupsAttribute = generateGroupsAttribute;
194  }
195
196  public boolean isSplitClassAndPackageNames() {
197    return splitClassAndPackageNames;
198  }
199
200  public void setSplitClassAndPackageNames(boolean splitClassAndPackageNames) {
201    this.splitClassAndPackageNames = splitClassAndPackageNames;
202  }
203
204  public String getTimestampFormat() {
205    return timestampFormat;
206  }
207
208  public void setTimestampFormat(String timestampFormat) {
209    this.timestampFormat = timestampFormat;
210  }
211
212  public boolean isGenerateDependsOnMethods() {
213    return generateDependsOnMethods;
214  }
215
216  public void setGenerateDependsOnMethods(boolean generateDependsOnMethods) {
217    this.generateDependsOnMethods = generateDependsOnMethods;
218  }
219
220  public boolean isGenerateDependsOnGroups() {
221    return generateDependsOnGroups;
222  }
223
224  public void setGenerateDependsOnGroups(boolean generateDependsOnGroups) {
225    this.generateDependsOnGroups = generateDependsOnGroups;
226  }
227
228  public void setGenerateTestResultAttributes(boolean generateTestResultAttributes) {
229    this.generateTestResultAttributes = generateTestResultAttributes;
230  }
231
232  public boolean isGenerateTestResultAttributes() {
233    return generateTestResultAttributes;
234  }
235}
236