@@ -91,21 +91,16 @@ private List<TestSuiteDto> fillTestSuites(List<TestSuiteDto> testSuites, boolean
91
91
return testSuites ;
92
92
}
93
93
94
- public void syncLegacyTests (TestSuiteDto template , Integer notExecutedFor , boolean removeNotExecutedResults ) throws AqualityException {
95
- if (baseUser .isManager () || baseUser .getProjectUserBySuiteId (template .getId ()).isManager ()){
96
- TestRunDto testRunTemplate = new TestRunDto ();
97
- testRunTemplate .setTest_suite_id (template .getId ());
98
- testRunTemplate .setLimit (notExecutedFor );
99
- List <TestRunDto > testRuns = testRunDao .searchAll (testRunTemplate );
100
- List <TestDto > legacyTests = getLegacyTests (testRuns , template .getId ());
94
+ public void syncLegacyTests (List <TestDto > legacyTests , Integer suiteId , boolean removeNotExecutedResults ) throws AqualityException {
95
+ if (baseUser .isManager () || baseUser .getProjectUserBySuiteId (suiteId ).isManager ()){
101
96
legacyTests .forEach (test -> {
102
97
Test2SuiteDto test2Suite = new Test2SuiteDto ();
103
98
test2Suite .setTest_id (test .getId ());
104
- test2Suite .setSuite_id (template . getId () );
99
+ test2Suite .setSuite_id (suiteId );
105
100
try {
106
101
test2SuiteDao .delete (test2Suite );
107
102
if (removeNotExecutedResults ) {
108
- removePendingResultsForTest (test );
103
+ removePendingResultsForTest (suiteId , test . getId () );
109
104
}
110
105
} catch (AqualityException e ) {
111
106
e .printStackTrace ();
@@ -116,12 +111,8 @@ public void syncLegacyTests(TestSuiteDto template, Integer notExecutedFor, boole
116
111
}
117
112
}
118
113
119
- private void removePendingResultsForTest (TestDto test ) throws AqualityException {
120
- TestResultDto testResultTemplate = new TestResultDto ();
121
- testResultTemplate .setTest_id (test .getId ());
122
- testResultTemplate .setFinal_result_id (3 );
123
- testResultTemplate .setTest_resolution_id (1 );
124
- List <TestResultDto > testResults = testResultDao .searchAll (testResultTemplate );
114
+ private void removePendingResultsForTest (Integer suiteId , Integer testId ) throws AqualityException {
115
+ List <TestResultDto > testResults = testResultDao .selectSuiteLegacyResults (suiteId , testId );
125
116
testResults .forEach (testResult -> {
126
117
try {
127
118
testResultDao .delete (testResult );
@@ -131,20 +122,28 @@ private void removePendingResultsForTest(TestDto test) throws AqualityException
131
122
});
132
123
}
133
124
134
- private List <TestDto > getLegacyTests (List <TestRunDto > testRuns , Integer suiteId ) throws AqualityException {
135
- TestDto testTemplate = new TestDto ();
136
- testTemplate .setTest_suite_id (suiteId );
137
- List <TestDto > tests = testController .get (testTemplate );
138
- for (TestRunDto testRun : testRuns ) {
139
- TestResultDto testResultTemplate = new TestResultDto ();
140
- testResultTemplate .setTest_run_id (testRun .getId ());
141
- List <TestResultDto > testResults = testResultDao .searchAll (testResultTemplate );
142
- tests = tests .stream ().filter (test -> {
143
- TestResultDto currentResult = testResults .stream ().filter (result -> result .getTest_id ().equals (test .getId ())).findFirst ().orElse (null );
144
- return currentResult == null || currentResult .getFinal_result_id () == 3 ;
145
- }).collect (Collectors .toList ());
146
- }
125
+ public List <TestDto > findLegacyTests (Integer suiteId , Integer notExecutedFor ) throws AqualityException {
126
+ if (baseUser .isManager () || baseUser .getProjectUserBySuiteId (suiteId ).isManager ()) {
127
+ TestRunDto testRunTemplate = new TestRunDto ();
128
+ testRunTemplate .setTest_suite_id (suiteId );
129
+ testRunTemplate .setLimit (notExecutedFor );
130
+ List <TestRunDto > testRuns = testRunDao .searchAll (testRunTemplate );
131
+ TestDto testTemplate = new TestDto ();
132
+ testTemplate .setTest_suite_id (suiteId );
133
+ List <TestDto > tests = testController .get (testTemplate );
134
+ for (TestRunDto testRun : testRuns ) {
135
+ TestResultDto testResultTemplate = new TestResultDto ();
136
+ testResultTemplate .setTest_run_id (testRun .getId ());
137
+ List <TestResultDto > testResults = testResultDao .searchAll (testResultTemplate );
138
+ tests = tests .stream ().filter (test -> {
139
+ TestResultDto currentResult = testResults .stream ().filter (result -> result .getTest_id ().equals (test .getId ())).findFirst ().orElse (null );
140
+ return currentResult == null || currentResult .getFinal_result_id () == 3 ;
141
+ }).collect (Collectors .toList ());
142
+ }
147
143
148
- return tests ;
144
+ return tests ;
145
+ } else {
146
+ throw new AqualityPermissionsException ("Account is not allowed to Sync Test Suite" , baseUser );
147
+ }
149
148
}
150
149
}
0 commit comments