13
13
import java .util .stream .Collectors ;
14
14
15
15
public class TestController extends BaseController <TestDto > {
16
- private TestDao testDao ;
17
- private TestSuiteDao suiteDao ;
18
- private TestResultDao resultDao ;
19
- private Test2SuiteController test2SuiteController ;
20
- private ProjectUserController projectUserController ;
16
+ private final TestDao testDao ;
17
+ private final TestSuiteDao suiteDao ;
18
+ private final TestResultDao resultDao ;
19
+ private final Test2SuiteController test2SuiteController ;
20
+ private final ProjectUserController projectUserController ;
21
21
22
22
public TestController (UserDto user ) {
23
23
super (user );
@@ -54,10 +54,8 @@ public TestDto createOrUpdate(TestDto test) throws AqualityException {
54
54
if (existingTests .size () > 0 ) {
55
55
TestDto existingTest = existingTests .get (0 );
56
56
if (existingTest .getSuites () != null ) {
57
- TestSuiteDto testSuite = existingTest .getSuites ().stream ().filter (suite -> suite .getId ().equals (test .getSuites ().get (0 ).getId ())).findFirst ().orElse (null );
58
- if (testSuite != null ) {
59
- existingTest .getSuites ().add (test .getSuites ().get (0 ));
60
- }
57
+ existingTest .getSuites ().stream ()
58
+ .filter (suite -> suite .getId ().equals (test .getSuites ().get (0 ).getId ())).findFirst ().ifPresent (testSuite -> existingTest .getSuites ().add (test .getSuites ().get (0 )));
61
59
}else {
62
60
existingTest .setSuites (test .getSuites ());
63
61
}
@@ -98,12 +96,12 @@ public boolean delete(TestDto template) throws AqualityException {
98
96
}
99
97
}
100
98
101
- public boolean updateMultipleTests (List <TestDto > entities ) throws AqualityException {
99
+ public void updateMultipleTests (List <TestDto > entities ) throws AqualityException {
102
100
if (entities .size () > 0 && (baseUser .isManager () || baseUser .getProjectUser (entities .get (0 ).getProject_id ()).isEditor ())) {
103
101
for (TestDto test : entities ) {
104
102
updateSuites (test );
105
103
}
106
- return testDao .updateMultiply (entities );
104
+ testDao .updateMultiply (entities );
107
105
} else {
108
106
throw new AqualityPermissionsException ("Account is not allowed to update Test " , baseUser );
109
107
}
@@ -162,16 +160,12 @@ private List<TestDto> fillTests(List<TestDto> tests) throws AqualityException {
162
160
TestSuiteDto testSuiteDto = new TestSuiteDto ();
163
161
testSuiteDto .setProject_id (projectId );
164
162
List <TestSuiteDto > testSuites = suiteDao .searchAll (testSuiteDto );
165
- List <Test2SuiteDto > test2Suites = new ArrayList <>();
166
163
ProjectDto projectDto = new ProjectDto ();
167
164
projectDto .setId (tests .get (0 ).getProject_id ());
168
165
169
- for (TestSuiteDto testSuite : testSuites ) {
170
- Test2SuiteDto test2Suite = new Test2SuiteDto ();
171
- test2Suite .setSuite_id (testSuite .getId ());
172
- test2Suites .addAll (test2SuiteController .get (test2Suite ));
173
- }
174
-
166
+ Test2SuiteDto test2Suite = new Test2SuiteDto ();
167
+ test2Suite .setProject_id (projectId );
168
+ List <Test2SuiteDto > test2Suites = test2SuiteController .get (test2Suite );
175
169
176
170
for (TestDto test : tests ) {
177
171
if (test .getDeveloper_id () != null ) {
@@ -192,7 +186,8 @@ private void updateSuites(TestDto test) throws AqualityException {
192
186
test2SuiteDto .setTest_id (test .getId ());
193
187
List <Test2SuiteDto > oldSuites = test2SuiteController .get (test2SuiteDto );
194
188
if (test .getSuites () != null && test .getSuites ().size () > 0 ) {
195
- for (TestSuiteDto newSuite : test .getSuites ()) {
189
+ List <TestSuiteDto > suites = test .getSuites ();
190
+ for (TestSuiteDto newSuite : suites ) {
196
191
Test2SuiteDto alreadyExists = oldSuites .stream ().filter (x -> Objects .equals (x .getSuite_id (), newSuite .getId ())).findAny ().orElse (null );
197
192
if (alreadyExists != null ) {
198
193
oldSuites .removeIf (x -> Objects .equals (x .getSuite_id (), alreadyExists .getSuite_id ()));
0 commit comments