@@ -18,11 +18,15 @@ class BaseImporter {
18
18
private ControllerFactory controllerFactory ;
19
19
private String pattern ;
20
20
protected File file ;
21
+ private List <PredefinedResolutionDto > predefinedResolutions ;
21
22
22
- BaseImporter (int projectId , String pattern , UserDto user ){
23
+ BaseImporter (int projectId , String pattern , UserDto user ) throws AqualityException {
23
24
this .projectId = projectId ;
24
25
this .pattern = pattern ;
25
26
controllerFactory = new ControllerFactory (user );
27
+ PredefinedResolutionDto predefinedResolutionTemplate = new PredefinedResolutionDto ();
28
+ predefinedResolutionTemplate .setProject_id (this .projectId );
29
+ predefinedResolutions = controllerFactory .getHandler (predefinedResolutionTemplate ).get (predefinedResolutionTemplate );
26
30
}
27
31
28
32
private List <TestResultDto > existingResults = new ArrayList <>();
@@ -37,46 +41,52 @@ class BaseImporter {
37
41
ImportDao importDao = new ImportDao ();
38
42
ImportDto importDto = new ImportDto ();
39
43
40
- void createResults (boolean update ) throws AqualityException {
44
+ void processImport (boolean update ) throws AqualityException {
41
45
createTestSuite ();
42
- addLogToImport ("Suites are updated." );
43
46
createTests ();
44
- addLogToImport ("Tests are updated." );
45
47
createTestRun ();
46
- addLogToImport ( "Test Run is updated." );
47
- updateImportTestRun ();
48
+ createResults ( update );
49
+ }
48
50
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." );
54
55
55
- int testRunId = testRun .getId ();
56
- addLogToImport ("Starting test results creation." );
57
56
for (int i = 0 ; i < testResults .size (); i ++) {
58
57
TestResultDto result = testResults .get (i );
58
+
59
59
if (result .getInternalTestId () != null ){
60
60
result .setTest (tests .stream ().filter (x -> Objects .equals (x .getInternalId (), result .getInternalTestId ())).findFirst ().orElse (null ));
61
61
}else {
62
62
result .setTest (tests .get (i ));
63
63
}
64
+
64
65
result .setTest_id (result .getTest ().getId ());
65
- result .setTest_run_id (testRunId );
66
+ result .setTest_run_id (testRun . getId () );
66
67
result .setFinal_result_updated (result .getFinish_date ());
67
68
result .setProject_id (testRun .getProject_id ());
68
69
69
70
createResult (result , update );
70
71
}
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 );
72
82
}
73
83
74
84
private void updateImportTestRun () throws AqualityException {
75
85
importDto .setTestrun_id (testRun .getId ());
76
86
importDto = importDao .create (importDto );
77
87
}
78
88
79
- void addLogToImport (String log ) throws AqualityException {
89
+ void logToImport (String log ) throws AqualityException {
80
90
importDto .addToLog (log );
81
91
importDto = importDao .create (importDto );
82
92
}
@@ -98,6 +108,8 @@ private void createTestRun() throws AqualityException {
98
108
? testRun .getBuild_name ()
99
109
: file .getName ().substring (0 , file .getName ().lastIndexOf ("." )));
100
110
}
111
+ updateImportTestRun ();
112
+ logToImport ("Test Run is updated." );
101
113
}
102
114
103
115
private void createTestRun (String buildName ) throws AqualityException {
@@ -133,6 +145,8 @@ private void createTestSuite() throws AqualityException {
133
145
} else {
134
146
testSuite .setId (controllerFactory .getHandler (testSuite ).create (testSuite ).getId ());
135
147
}
148
+
149
+ logToImport ("Suites are updated." );
136
150
}
137
151
138
152
private void createTests () throws AqualityException {
@@ -157,6 +171,8 @@ private void createTests() throws AqualityException {
157
171
completedTests .add (test );
158
172
}
159
173
this .tests = completedTests ;
174
+
175
+ logToImport ("Tests are updated." );
160
176
}
161
177
162
178
private TestDto tryGetExistingTest (List <TestDto > allTests , TestDto test ) throws AqualityException {
@@ -192,7 +208,7 @@ private void createResult(TestResultDto result, boolean update) throws AqualityE
192
208
}
193
209
194
210
if (result .getFail_reason () != null && !result .getFail_reason ().equals ("" )){
195
- updateResultWithSimilarError (result );
211
+ predictResultResolution (result );
196
212
}
197
213
controllerFactory .getHandler (result ).create (result );
198
214
} catch (AqualityException e ){
@@ -202,7 +218,13 @@ private void createResult(TestResultDto result, boolean update) throws AqualityE
202
218
}
203
219
}
204
220
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 {
206
228
try {
207
229
ProjectDto project = new ProjectDto ();
208
230
project .setId (result .getProject_id ());
@@ -227,8 +249,6 @@ private TestResultDto updateResultWithSimilarError(TestResultDto result) throws
227
249
result .setAssignee (similarResult .getAssignee ());
228
250
}
229
251
}
230
-
231
- return result ;
232
252
} catch (Exception e ){
233
253
throw new AqualityException ("Failed on update Result with similar error" );
234
254
}
@@ -245,6 +265,21 @@ private TestResultDto compareByRegexp(TestResultDto result, List<TestResultDto>
245
265
return null ;
246
266
}
247
267
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
+
248
283
private TestDto getTestByPatternOrName (List <TestDto > tests , TestDto importTest ) throws AqualityException {
249
284
Pattern pattern = Pattern .compile (this .pattern );
250
285
Matcher matcher = pattern .matcher (importTest .getBody ());
0 commit comments