Skip to content

Commit ea3efb1

Browse files
Merge pull request #22 from aquality-automation/feature/Nunit3Add_Possibility_to_use_fullname_attribute_as_test_name
Feature/nunit3 add possibility to use fullname attribute as test name
2 parents 5d50b2f + 76d7b06 commit ea3efb1

File tree

14 files changed

+199
-53
lines changed

14 files changed

+199
-53
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# CHANGELOG
2+
3+
## 0.3.2 (unreleased)
4+
5+
Features:
6+
7+
- Import: NUnit V3 add possibility to import with fullname test name -> [View Issue](https://github.com/aquality-automation/aquality-tracking-ui/issues/27)
8+
9+
Bugfixes:
10+
11+
- Import: Import to latest test Run not working when importing more than one file -> [View Issue](https://github.com/aquality-automation/aquality-tracking-ui/issues/29)
12+
13+
## 0.3.1 (2019-08-30)
14+
15+
Features:
16+
17+
- Add ability to set Default Email Pattern
18+
- Add regex search to Results Searcher
19+
20+
Bugfixes:
21+
22+
- Fix Fail Reason Search

src/main/java/main/controllers/Project/SuiteController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ public List<TestSuiteDto> get(TestSuiteDto template) throws AqualityException {
4646
return get(template, false);
4747
}
4848

49+
public TestSuiteDto get(String name, Integer projectId) throws AqualityException {
50+
TestSuiteDto template = new TestSuiteDto();
51+
template.setName(name);
52+
template.setProject_id(projectId);
53+
try{
54+
return get(template, false).get(0);
55+
} catch (IndexOutOfBoundsException e) {
56+
throw new AqualityException("The '%s' suite does not exist.", name);
57+
}
58+
}
59+
4960
@Override
5061
public boolean delete(TestSuiteDto template) throws AqualityException {
5162
if(baseUser.isManager() || baseUser.getProjectUserBySuiteId(template.getId()).isManager()){

src/main/java/main/controllers/Project/TestRunController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public List<TestRunStatisticDto> get(TestRunStatisticDto template) throws Aquali
6565
return testRunStatisticDao.searchAll(template);
6666
}
6767

68+
public TestRunDto getLastSuiteTestRun(Integer suiteId, Integer projectId) throws AqualityException {
69+
TestRunDto template = new TestRunDto();
70+
template.setTest_suite_id(suiteId);
71+
template.setProject_id(projectId);
72+
List<TestRunDto> testRuns = get(template, false, 1);
73+
if(testRuns.size() > 0){
74+
return testRuns.get(0);
75+
}
76+
77+
throw new AqualityException("There are no test runs for suite with '%s' id!", suiteId);
78+
}
79+
6880
@Override
6981
public boolean delete(TestRunDto template) throws AqualityException {
7082
if(baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isEditor()){

src/main/java/main/exceptions/AqualityException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ public class AqualityException extends Exception {
88
public AqualityException(String error) {
99
super(error);
1010
}
11+
12+
public AqualityException(String error, Object... args) {
13+
super(String.format(error, args));
14+
}
1115
}

src/main/java/main/exceptions/AqualitySQLException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ private static String getErrorMessage(String sqlcode){
1717
return "You are trying to create duplicate entity.";
1818
case "42000":
1919
return "You Regular expression is not valid!";
20+
case "40001":
21+
return "You are trying to edit entity which is locked. Please retry the operation.";
2022
default:
2123
return String.format("Unknown SQL Error: %s", sqlcode);
2224
}

src/main/java/main/model/db/imports/BaseImporter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ void addLogToImport(String log) throws AqualityException {
8080

8181
private void createTestRun() throws AqualityException {
8282
if(testRun.getId() != null){
83-
this.testRun = controllerFactory.getHandler(testRun).get(testRun, false, 1).get(0);
83+
TestRunDto template = new TestRunDto();
84+
template.setProject_id(testRun.getProject_id());
85+
template.setId(testRun.getId());
86+
List<TestRunDto> testRuns = controllerFactory.getHandler(template).get(template, false, 1);
87+
if(testRuns.size() > 0){
88+
testRun = testRuns.get(0);
89+
} else {
90+
throw new AqualityException("Test run with %s id does not exist!", testRun.getId());
91+
}
8492
}
8593
else{
8694
createTestRun((testRun.getBuild_name() != null && !testRun.getBuild_name().equals(""))

src/main/java/main/model/db/imports/HandlerFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ Handler getHandler(File file, String type, TestNameNodeType testNameNodeType) th
2828
case NUnit_v2:
2929
return new NUnitV2(file);
3030
case NUnit_v3:
31-
return new NUnitV3(file);
31+
if(testNameNodeType == null){
32+
throw new AqualityException("testNameNode is required");
33+
}
34+
return new NUnitV3(file, testNameNodeType);
3235
default:
3336
throw new AqualityException(String.format("Import Type '%s' is not implemented", type));
3437
}

src/main/java/main/model/db/imports/ImportHandlers/NUnitV3.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import main.exceptions.AqualityException;
44
import main.model.db.imports.Handler;
55
import main.model.db.imports.SAXHandlers.NUnitV3Handler;
6+
import main.model.db.imports.TestNameNodeType;
67
import main.model.dto.TestDto;
78
import main.model.dto.TestResultDto;
89
import main.model.dto.TestRunDto;
@@ -17,8 +18,8 @@ public class NUnitV3 extends Handler {
1718

1819
private NUnitV3Handler handler;
1920

20-
public NUnitV3(File file) throws AqualityException {
21-
handler = new NUnitV3Handler();
21+
public NUnitV3(File file, TestNameNodeType testNameNodeType) throws AqualityException {
22+
handler = new NUnitV3Handler(testNameNodeType);
2223
try {
2324
this.parser.parse(file, handler);
2425
} catch (SAXException | IOException e) {

src/main/java/main/model/db/imports/SAXHandlers/NUnitV3Handler.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import main.model.db.imports.ResultStatus;
44
import main.exceptions.AqualityException;
55
import main.model.db.imports.Handler;
6+
import main.model.db.imports.TestNameNodeType;
67
import main.model.dto.*;
78
import org.xml.sax.Attributes;
89
import org.xml.sax.SAXException;
@@ -13,6 +14,7 @@
1314
import java.util.*;
1415

1516
import static main.model.db.imports.ResultStatus.*;
17+
import static main.model.db.imports.TestNameNodeType.*;
1618

1719
public class NUnitV3Handler extends Handler {
1820
private TestSuiteDto testSuite = new TestSuiteDto();
@@ -28,9 +30,11 @@ public class NUnitV3Handler extends Handler {
2830
private Boolean isReasonStarted = false;
2931
private Boolean isTestCaseStarted = false;
3032
private Integer assertionNumber = 0;
33+
private TestNameNodeType testNameNodeType;
3134

32-
public NUnitV3Handler() throws AqualityException {
35+
public NUnitV3Handler(TestNameNodeType testNameNodeType) throws AqualityException {
3336
super();
37+
this.testNameNodeType = testNameNodeType;
3438
result.setFail_reason("$blank");
3539
}
3640

@@ -59,13 +63,13 @@ public void startElement(String uri, String localName, String qName, Attributes
5963
testRun.setAuthor(String.format("%s\\%s", attributes.getValue("user-domain"), attributes.getValue("user")));
6064
break;
6165
case "test-suite":
62-
if(attributes.getValue("type").equals("TestFixture")) {
66+
if(attributes.getValue("type").equals("TestFixture") && testNameNodeType == featureNameTestName) {
6367
currentFixture = attributes.getValue("name");
6468
}
6569
break;
6670
case "test-case":
6771
isTestCaseStarted = true;
68-
test.setName(String.format("%s: %s", currentFixture, attributes.getValue("name")) );
72+
setTestName(attributes);
6973
try {
7074
result.setStart_date(convertToDate(attributes.getValue("start-time")));
7175
result.setFinish_date(convertToDate(attributes.getValue("end-time")));
@@ -166,6 +170,18 @@ public void characters(char[] ch, int start, int length) {
166170
}
167171
}
168172

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+
}
169185

170186
private Date convertToDate(String dateString) throws ParseException {
171187
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

src/main/java/main/model/db/imports/TestNameNodeType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
public enum TestNameNodeType {
44
className,
55
testName,
6-
descriptionNode
6+
descriptionNode,
7+
featureNameTestName
78
}

0 commit comments

Comments
 (0)