Skip to content

Commit efc9329

Browse files
author
Alexander Bainczyk
committed
Merge remote-tracking branch 'origin/streamline-testing' into streamline-testing
2 parents 9639a40 + 87caa68 commit efc9329

File tree

9 files changed

+71
-57
lines changed

9 files changed

+71
-57
lines changed

backend/src/main/java/de/learnlib/alex/data/dao/ProjectDAO.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ public Project importProject(User user, ProjectExportableEntity projectExportabl
338338

339339
symbolGroupDAO.importGroups(user, createdProject, groups, new HashMap<>());
340340

341-
//todo:
341+
/* oldTestId -> newTestId
342+
* maps the exported testids to the corresponding newly created ones,
343+
* enabling correct referencing when importing testExecutionConfigs
344+
*/
342345
Map<Long, Long> configRefMap = new HashMap<>();
343346

344347
if (!tests.isEmpty()) {

backend/src/main/java/de/learnlib/alex/data/dao/ProjectEnvironmentDAO.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package de.learnlib.alex.data.dao;
1818

1919
import de.learnlib.alex.auth.entities.User;
20+
import de.learnlib.alex.common.exceptions.ForbiddenOperationException;
2021
import de.learnlib.alex.common.exceptions.NotFoundException;
2122
import de.learnlib.alex.data.entities.Project;
2223
import de.learnlib.alex.data.entities.ProjectEnvironment;
@@ -30,19 +31,20 @@
3031
import de.learnlib.alex.data.repositories.ProjectRepository;
3132
import de.learnlib.alex.data.repositories.ProjectUrlRepository;
3233
import de.learnlib.alex.data.repositories.SymbolActionRepository;
33-
import de.learnlib.alex.learning.entities.LearnerSetup;
3434
import de.learnlib.alex.learning.repositories.LearnerSetupRepository;
35+
import de.learnlib.alex.testing.repositories.TestExecutionConfigRepository;
3536
import de.learnlib.alex.testing.repositories.TestReportRepository;
36-
import java.util.ArrayList;
37-
import java.util.List;
38-
import java.util.stream.Collectors;
39-
import javax.validation.ValidationException;
4037
import org.apache.shiro.authz.UnauthorizedException;
4138
import org.hibernate.Hibernate;
4239
import org.springframework.beans.factory.annotation.Autowired;
4340
import org.springframework.stereotype.Service;
4441
import org.springframework.transaction.annotation.Transactional;
4542

43+
import javax.validation.ValidationException;
44+
import java.util.ArrayList;
45+
import java.util.List;
46+
import java.util.stream.Collectors;
47+
4648
@Service
4749
@Transactional(rollbackFor = Exception.class)
4850
public class ProjectEnvironmentDAO {
@@ -55,6 +57,7 @@ public class ProjectEnvironmentDAO {
5557
private final SymbolActionRepository symbolActionRepository;
5658
private final TestReportRepository testReportRepository;
5759
private final LearnerSetupRepository learnerSetupRepository;
60+
private final TestExecutionConfigRepository testExecutionConfigRepository;
5861

5962
@Autowired
6063
public ProjectEnvironmentDAO(ProjectDAO projectDAO,
@@ -64,7 +67,8 @@ public ProjectEnvironmentDAO(ProjectDAO projectDAO,
6467
ProjectUrlRepository urlRepository,
6568
SymbolActionRepository symbolActionRepository,
6669
TestReportRepository testReportRepository,
67-
LearnerSetupRepository learnerSetupRepository) {
70+
LearnerSetupRepository learnerSetupRepository,
71+
TestExecutionConfigRepository testExecutionConfigRepository) {
6872
this.projectDAO = projectDAO;
6973
this.projectRepository = projectRepository;
7074
this.environmentRepository = environmentRepository;
@@ -73,6 +77,7 @@ public ProjectEnvironmentDAO(ProjectDAO projectDAO,
7377
this.symbolActionRepository = symbolActionRepository;
7478
this.testReportRepository = testReportRepository;
7579
this.learnerSetupRepository = learnerSetupRepository;
80+
this.testExecutionConfigRepository = testExecutionConfigRepository;
7681
}
7782

7883
public ProjectEnvironment create(User user, Long projectId, ProjectEnvironment environment) {
@@ -138,6 +143,14 @@ public void delete(User user, Long projectId, Long environmentId) {
138143
throw new ValidationException("There has to be at least one environment.");
139144
}
140145

146+
if (!testExecutionConfigRepository.findAllByProject_IdAndEnvironment_Id(projectId, environmentId).isEmpty()) {
147+
throw new ForbiddenOperationException("The environment " + environment.getName() + " is associated with one or more test configs.");
148+
}
149+
150+
if (!learnerSetupRepository.findAllByProject_IdAndEnvironment_Id(projectId, environmentId).isEmpty()) {
151+
throw new ForbiddenOperationException("The environment " + environment.getName() + " is associated with one or more learner setups.");
152+
}
153+
141154
// select next best default environment
142155
if (environment.isDefault()) {
143156
final List<ProjectEnvironment> envs = environmentRepository.findAllByProject_Id(projectId);
@@ -149,18 +162,6 @@ public void delete(User user, Long projectId, Long environmentId) {
149162
// delete test reports that have been executed in the environment
150163
testReportRepository.deleteAllByEnvironment_Id(environment.getId());
151164

152-
// remove environment from learner setups
153-
final List<LearnerSetup> learnerSetups = learnerSetupRepository.findAllByEnvironmentsContains(environment);
154-
for (LearnerSetup learnerSetup : learnerSetups) {
155-
learnerSetup.getEnvironments().remove(environment);
156-
// switch to default environment if the deleted one is the only one
157-
if (learnerSetup.getEnvironments().isEmpty()) {
158-
final var defaultEnvironment = environmentRepository.findByProject_IdAndIs_Default(projectId, true);
159-
learnerSetup.getEnvironments().add(defaultEnvironment);
160-
}
161-
learnerSetupRepository.save(learnerSetup);
162-
}
163-
164165
project.getEnvironments().remove(environment);
165166
projectRepository.save(project);
166167
environmentRepository.delete(environment);

backend/src/main/java/de/learnlib/alex/learning/repositories/LearnerSetupRepository.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919
import de.learnlib.alex.data.entities.ProjectEnvironment;
2020
import de.learnlib.alex.learning.entities.LearnerSetup;
21-
import java.util.List;
2221
import org.springframework.data.jpa.repository.JpaRepository;
22+
import org.springframework.data.jpa.repository.Query;
23+
import org.springframework.data.repository.query.Param;
2324
import org.springframework.stereotype.Repository;
2425

26+
import java.util.List;
27+
2528
@Repository
2629
public interface LearnerSetupRepository extends JpaRepository<LearnerSetup, Long> {
2730

@@ -30,4 +33,9 @@ public interface LearnerSetupRepository extends JpaRepository<LearnerSetup, Long
3033
void deleteAllByProject_Id(Long projectId);
3134

3235
List<LearnerSetup> findAllByEnvironmentsContains(ProjectEnvironment environment);
36+
37+
@Query(value = "select ls "
38+
+ "from LearnerSetup ls join ls.environments e "
39+
+ "where ls.project.id = :projectId and e.id = :environmentId")
40+
List<LearnerSetup> findAllByProject_IdAndEnvironment_Id(@Param("projectId") Long projectId, @Param("environmentId") Long environmentId);
3341
}

backend/src/main/java/de/learnlib/alex/testing/dao/TestDAO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public Test create(User user, Long projectId, Test test) throws NotFoundExceptio
168168
return createByGenerate(user, project, test);
169169
}
170170

171+
public List<Test> create(User user, Long projectId, List<Test> tests) {
172+
return create(user, projectId, tests, null);
173+
}
174+
171175
public List<Test> create(User user, Long projectId, List<Test> tests, Map<Long, Long> configRefMap) {
172176
return create(user, projectId, new ArrayList<>(tests), null, configRefMap);
173177
}

backend/src/main/java/de/learnlib/alex/testing/repositories/TestExecutionConfigRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ public interface TestExecutionConfigRepository extends JpaRepository<TestExecuti
4545
+ "from TestExecutionConfig tc join tc.tests t "
4646
+ "where tc.project.id = :projectId and t.id = :testId")
4747
List<TestExecutionConfig> findAllByProject_IdAndTest_Id(@Param("projectId") Long projectId, @Param("testId") Long testId);
48+
49+
List<TestExecutionConfig> findAllByProject_IdAndEnvironment_Id(Long projectId, Long environmentId);
4850
}

backend/src/main/java/de/learnlib/alex/testing/rest/TestResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public ResponseEntity<Test> createTest(@PathVariable("projectId") Long projectId
115115
public ResponseEntity<List<Test>> createTests(@PathVariable("projectId") Long projectId,
116116
@RequestBody List<Test> tests) {
117117
final var user = authContext.getUser();
118-
final var createdTests = testDAO.create(user, projectId, tests, null);
118+
final var createdTests = testDAO.create(user, projectId, tests);
119119
webhookService.fireEvent(user, new TestEvent.CreatedMany(createdTests));
120120
return ResponseEntity.status(HttpStatus.CREATED).body(createdTests);
121121
}

backend/src/test/java/de/learnlib/alex/integrationtests/resources/ATestExecutionConfigResourceIT.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616

1717
package de.learnlib.alex.integrationtests.resources;
1818

19-
import static org.junit.jupiter.api.Assertions.assertEquals;
20-
2119
import com.jayway.jsonpath.JsonPath;
2220
import de.learnlib.alex.integrationtests.resources.api.ProjectApi;
21+
import de.learnlib.alex.integrationtests.resources.api.TestApi;
2322
import de.learnlib.alex.integrationtests.resources.api.TestExecutionConfigApi;
2423
import de.learnlib.alex.integrationtests.resources.api.UserApi;
25-
import javax.ws.rs.core.Response;
2624
import org.junit.jupiter.api.BeforeEach;
2725
import org.junit.jupiter.api.Test;
2826

27+
import javax.ws.rs.core.Response;
28+
import java.util.List;
29+
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
31+
2932
public class ATestExecutionConfigResourceIT extends AbstractResourceIT {
3033

3134
private TestExecutionConfigApi api;
@@ -72,6 +75,20 @@ public void shouldCreateAConfig() throws Exception {
7275
assertEquals(1, getNumberOfConfigs(projectId1, jwtUser1));
7376
}
7477

78+
@Test
79+
public void shouldCreateAConfigWithTests() throws Exception {
80+
final TestApi testApi = new TestApi(client, port);
81+
82+
final String tc = "{\"name\": \"tc\", \"type\": \"case\"}";
83+
final Response res1 = testApi.create(projectId1, tc, jwtUser1);
84+
assertEquals(Response.Status.CREATED.getStatusCode(), res1.getStatus());
85+
86+
final int tcId = JsonPath.read(res1.readEntity(String.class), "$.id");
87+
final Response res2 = api.create(projectId1, createConfigWithTests(projectId1, envId1, List.of((long) tcId)), jwtUser1);
88+
assertEquals(Response.Status.CREATED.getStatusCode(), res2.getStatus());
89+
assertEquals(1, getNumberOfConfigs(projectId1, jwtUser1));
90+
}
91+
7592
@Test
7693
public void shouldGetEmptyListIfNoConfigExists() throws Exception {
7794
final Response res = api.getAll(projectId1, jwtUser1);
@@ -145,7 +162,16 @@ private String createConfig(int projectId, int envId) {
145162
return "{"
146163
+ "\"tests\":[]"
147164
+ ",\"driverConfig\":{\"browser\":\"chrome\"}"
148-
+ ",\"environment\":" + envId
165+
+ ",\"environmentId\":" + envId
166+
+ ",\"project\":" + projectId
167+
+ "}";
168+
}
169+
170+
private String createConfigWithTests(int projectId, int envId, List<Long> testIds) {
171+
return "{"
172+
+ "\"tests\":" + testIds.toString()
173+
+ ",\"driverConfig\":{\"browser\":\"chrome\"}"
174+
+ ",\"environmentId\":" + envId
149175
+ ",\"project\":" + projectId
150176
+ "}";
151177
}

backend/src/test/resources/integrationtest/ALEX-rest.project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,5 +983,6 @@
983983
}
984984
],
985985
"formulaSuites": [],
986-
"learnerSetups": []
986+
"learnerSetups": [],
987+
"testExecutionConfigs": []
987988
}

frontend/src/app/common/test-status/test-status.component.html

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)