Skip to content

Commit 604a74a

Browse files
Predefined Resolutions import
1 parent 2c401bd commit 604a74a

File tree

3 files changed

+64
-23
lines changed

3 files changed

+64
-23
lines changed

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

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ class BaseImporter {
1818
private ControllerFactory controllerFactory;
1919
private String pattern;
2020
protected File file;
21+
private List<PredefinedResolutionDto> predefinedResolutions;
2122

22-
BaseImporter(int projectId, String pattern, UserDto user){
23+
BaseImporter(int projectId, String pattern, UserDto user) throws AqualityException {
2324
this.projectId = projectId;
2425
this.pattern = pattern;
2526
controllerFactory = new ControllerFactory(user);
27+
PredefinedResolutionDto predefinedResolutionTemplate = new PredefinedResolutionDto();
28+
predefinedResolutionTemplate.setProject_id(this.projectId);
29+
predefinedResolutions = controllerFactory.getHandler(predefinedResolutionTemplate).get(predefinedResolutionTemplate);
2630
}
2731

2832
private List<TestResultDto> existingResults = new ArrayList<>();
@@ -37,46 +41,52 @@ class BaseImporter {
3741
ImportDao importDao = new ImportDao();
3842
ImportDto importDto = new ImportDto();
3943

40-
void createResults(boolean update) throws AqualityException {
44+
void processImport(boolean update) throws AqualityException {
4145
createTestSuite();
42-
addLogToImport("Suites are updated.");
4346
createTests();
44-
addLogToImport("Tests are updated.");
4547
createTestRun();
46-
addLogToImport("Test Run is updated.");
47-
updateImportTestRun();
48+
createResults(update);
49+
}
4850

49-
TestResultDto template = new TestResultDto();
50-
template.setTest_run_id(testRun.getId());
51-
template.setProject_id(testRun.getProject_id());
52-
template.setLimit(10000);
53-
existingResults = testResultDao.searchAll(template);
51+
private void createResults(boolean update) throws AqualityException {
52+
existingResults = getExistingResults();
53+
54+
logToImport("Starting test results creation.");
5455

55-
int testRunId = testRun.getId();
56-
addLogToImport("Starting test results creation.");
5756
for (int i = 0; i < testResults.size(); i++) {
5857
TestResultDto result = testResults.get(i);
58+
5959
if(result.getInternalTestId() != null){
6060
result.setTest(tests.stream().filter(x-> Objects.equals(x.getInternalId(), result.getInternalTestId())).findFirst().orElse(null));
6161
}else{
6262
result.setTest(tests.get(i));
6363
}
64+
6465
result.setTest_id(result.getTest().getId());
65-
result.setTest_run_id(testRunId);
66+
result.setTest_run_id(testRun.getId());
6667
result.setFinal_result_updated(result.getFinish_date());
6768
result.setProject_id(testRun.getProject_id());
6869

6970
createResult(result, update);
7071
}
71-
addLogToImport("Test results were created.");
72+
73+
logToImport("Test results were created.");
74+
}
75+
76+
private List<TestResultDto> getExistingResults() throws AqualityException {
77+
TestResultDto template = new TestResultDto();
78+
template.setTest_run_id(testRun.getId());
79+
template.setProject_id(testRun.getProject_id());
80+
template.setLimit(10000);
81+
return testResultDao.searchAll(template);
7282
}
7383

7484
private void updateImportTestRun() throws AqualityException {
7585
importDto.setTestrun_id(testRun.getId());
7686
importDto = importDao.create(importDto);
7787
}
7888

79-
void addLogToImport(String log) throws AqualityException {
89+
void logToImport(String log) throws AqualityException {
8090
importDto.addToLog(log);
8191
importDto = importDao.create(importDto);
8292
}
@@ -98,6 +108,8 @@ private void createTestRun() throws AqualityException {
98108
? testRun.getBuild_name()
99109
: file.getName().substring(0, file.getName().lastIndexOf(".")));
100110
}
111+
updateImportTestRun();
112+
logToImport("Test Run is updated.");
101113
}
102114

103115
private void createTestRun(String buildName) throws AqualityException {
@@ -133,6 +145,8 @@ private void createTestSuite() throws AqualityException {
133145
} else {
134146
testSuite.setId(controllerFactory.getHandler(testSuite).create(testSuite).getId());
135147
}
148+
149+
logToImport("Suites are updated.");
136150
}
137151

138152
private void createTests() throws AqualityException {
@@ -157,6 +171,8 @@ private void createTests() throws AqualityException {
157171
completedTests.add(test);
158172
}
159173
this.tests = completedTests;
174+
175+
logToImport("Tests are updated.");
160176
}
161177

162178
private TestDto tryGetExistingTest(List<TestDto> allTests, TestDto test) throws AqualityException {
@@ -192,7 +208,7 @@ private void createResult(TestResultDto result, boolean update) throws AqualityE
192208
}
193209

194210
if(result.getFail_reason() != null && !result.getFail_reason().equals("")){
195-
updateResultWithSimilarError(result);
211+
predictResultResolution(result);
196212
}
197213
controllerFactory.getHandler(result).create(result);
198214
} catch (AqualityException e){
@@ -202,7 +218,13 @@ private void createResult(TestResultDto result, boolean update) throws AqualityE
202218
}
203219
}
204220

205-
private TestResultDto updateResultWithSimilarError(TestResultDto result) throws AqualityException {
221+
private void predictResultResolution(TestResultDto result) throws AqualityException {
222+
if(!tryFillByPredefinedResolution(result, predefinedResolutions)) {
223+
updateResultWithSimilarError(result);
224+
}
225+
}
226+
227+
private void updateResultWithSimilarError(TestResultDto result) throws AqualityException {
206228
try{
207229
ProjectDto project = new ProjectDto();
208230
project.setId(result.getProject_id());
@@ -227,8 +249,6 @@ private TestResultDto updateResultWithSimilarError(TestResultDto result) throws
227249
result.setAssignee(similarResult.getAssignee());
228250
}
229251
}
230-
231-
return result;
232252
} catch (Exception e){
233253
throw new AqualityException("Failed on update Result with similar error");
234254
}
@@ -245,6 +265,21 @@ private TestResultDto compareByRegexp(TestResultDto result, List<TestResultDto>
245265
return null;
246266
}
247267

268+
private boolean tryFillByPredefinedResolution(TestResultDto result, List<PredefinedResolutionDto> predefinedResolutions) {
269+
if (result.getFail_reason() != null) {
270+
for (PredefinedResolutionDto predefinedResolution : predefinedResolutions) {
271+
if (RegexpUtil.match(result.getFail_reason(), predefinedResolution.getExpression())) {
272+
result.setTest_resolution_id(predefinedResolution.getResolution_id());
273+
result.setComment(predefinedResolution.getComment());
274+
result.setAssignee(predefinedResolution.getAssignee());
275+
return true;
276+
}
277+
}
278+
}
279+
280+
return false;
281+
}
282+
248283
private TestDto getTestByPatternOrName(List<TestDto> tests, TestDto importTest) throws AqualityException {
249284
Pattern pattern = Pattern.compile(this.pattern);
250285
Matcher matcher = pattern.matcher(importTest.getBody());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Importer extends BaseImporter {
2525

2626
private HandlerFactory handlerFactory = new HandlerFactory();
2727

28-
public Importer(List<String> files, TestRunDto testRunTemplate, String pattern, String type, TestNameNodeType testNameNodeType, boolean singleTestRun, UserDto user) {
28+
public Importer(List<String> files, TestRunDto testRunTemplate, String pattern, String type, TestNameNodeType testNameNodeType, boolean singleTestRun, UserDto user) throws AqualityException {
2929
super(testRunTemplate.getProject_id(), pattern, user);
3030
this.environment = testRunTemplate.getExecution_environment();
3131
this.ci_build = testRunTemplate.getCi_build();
@@ -85,7 +85,7 @@ private List<ImportDto> parseIntoMultiple() throws AqualityException {
8585
private void executeResultsCreation() throws AqualityException {
8686
fillTestRunWithInputData();
8787
fillTestSuiteWithInputData();
88-
this.createResults(testRunId != null);
88+
this.processImport(testRunId != null);
8989
this.testRun = new TestRunDto();
9090
this.testResults = new ArrayList<>();
9191
this.tests = new ArrayList<>();
@@ -96,7 +96,7 @@ private void storeResults(Handler handler) throws AqualityException {
9696
this.testResults.addAll(handler.getTestResults());
9797
this.tests.addAll(handler.getTests());
9898
this.testSuite = handler.getTestSuite();
99-
addLogToImport("File was parsed correctly!");
99+
logToImport("File was parsed correctly!");
100100
}
101101

102102
private void fillTestSuiteWithInputData(){

src/main/java/main/utils/RegexpUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public static boolean compareByRegexpGroups(String actual, String expected, Stri
2626
return result;
2727
}
2828

29+
public static boolean match(String value, String expression) {
30+
Pattern pattern = Pattern.compile(expression, Pattern.DOTALL);
31+
Matcher matcher = pattern.matcher(value);
32+
return matcher.matches();
33+
}
34+
2935
private static List<String> getGroups(Matcher matcher) {
3036
List<String> groups = new ArrayList<>();
3137
while (matcher.find()) {

0 commit comments

Comments
 (0)