3
3
import main .model .db .imports .ResultStatus ;
4
4
import main .exceptions .AqualityException ;
5
5
import main .model .db .imports .Handler ;
6
+ import main .model .db .imports .TestNameNodeType ;
6
7
import main .model .dto .*;
7
8
import org .xml .sax .Attributes ;
8
9
import org .xml .sax .SAXException ;
13
14
import java .util .*;
14
15
15
16
import static main .model .db .imports .ResultStatus .*;
17
+ import static main .model .db .imports .TestNameNodeType .*;
16
18
17
19
public class NUnitV3Handler extends Handler {
18
20
private TestSuiteDto testSuite = new TestSuiteDto ();
@@ -28,9 +30,11 @@ public class NUnitV3Handler extends Handler {
28
30
private Boolean isReasonStarted = false ;
29
31
private Boolean isTestCaseStarted = false ;
30
32
private Integer assertionNumber = 0 ;
33
+ private TestNameNodeType testNameNodeType ;
31
34
32
- public NUnitV3Handler () throws AqualityException {
35
+ public NUnitV3Handler (TestNameNodeType testNameNodeType ) throws AqualityException {
33
36
super ();
37
+ this .testNameNodeType = testNameNodeType ;
34
38
result .setFail_reason ("$blank" );
35
39
}
36
40
@@ -59,13 +63,13 @@ public void startElement(String uri, String localName, String qName, Attributes
59
63
testRun .setAuthor (String .format ("%s\\ %s" , attributes .getValue ("user-domain" ), attributes .getValue ("user" )));
60
64
break ;
61
65
case "test-suite" :
62
- if (attributes .getValue ("type" ).equals ("TestFixture" )) {
66
+ if (attributes .getValue ("type" ).equals ("TestFixture" ) && testNameNodeType == featureNameTestName ) {
63
67
currentFixture = attributes .getValue ("name" );
64
68
}
65
69
break ;
66
70
case "test-case" :
67
71
isTestCaseStarted = true ;
68
- test . setName ( String . format ( "%s: %s" , currentFixture , attributes . getValue ( "name" )) );
72
+ setTestName ( attributes );
69
73
try {
70
74
result .setStart_date (convertToDate (attributes .getValue ("start-time" )));
71
75
result .setFinish_date (convertToDate (attributes .getValue ("end-time" )));
@@ -166,6 +170,18 @@ public void characters(char[] ch, int start, int length) {
166
170
}
167
171
}
168
172
173
+ private void setTestName (Attributes attributes ) throws SAXException {
174
+ switch (testNameNodeType ) {
175
+ case featureNameTestName :
176
+ test .setName (String .format ("%s: %s" , currentFixture , attributes .getValue ("name" )) );
177
+ break ;
178
+ case className :
179
+ test .setName (attributes .getValue ("fullname" ));
180
+ break ;
181
+ default :
182
+ throw new SAXException ("testNameNodeType is not correct for NUnitV3 parser." );
183
+ }
184
+ }
169
185
170
186
private Date convertToDate (String dateString ) throws ParseException {
171
187
DateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
0 commit comments