Skip to content

Commit

Permalink
fix(citrusframework#281): cascade delete on TestResult to ScenarioExe…
Browse files Browse the repository at this point in the history
…cution
  • Loading branch information
Melvin Johner authored and bbortt committed Aug 22, 2024
1 parent 3aef091 commit e852eb6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Set;

import static jakarta.persistence.CascadeType.ALL;
import static jakarta.persistence.CascadeType.REMOVE;
import static java.util.Objects.nonNull;
import static lombok.AccessLevel.NONE;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause;
Expand Down Expand Up @@ -132,7 +133,7 @@ public class TestResult extends AbstractAuditingEntity<TestResult, Long> impleme
private String failureType;

@ToString.Exclude
@OneToOne(mappedBy = "testResult")
@OneToOne(mappedBy = "testResult", cascade = {REMOVE})
private ScenarioExecution scenarioExecution;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ public class TestResultResourceIT {
* if they test an entity which requires the current entity.
*/
public static TestResult createEntity(EntityManager entityManager) {
return TestResult.builder()
return createEntity(entityManager, false);

}

public static TestResult createEntity(EntityManager entityManager, boolean includeScenarioExecution) {
var testResult = TestResult.builder()
.status(DEFAULT_STATUS)
.testName(DEFAULT_TEST_NAME)
.className(DEFAULT_CLASS_NAME)
Expand All @@ -108,6 +113,12 @@ public static TestResult createEntity(EntityManager entityManager) {
.createdDate(DEFAULT_CREATED_DATE)
.lastModifiedDate(DEFAULT_LAST_MODIFIED_DATE)
.build();

if (includeScenarioExecution) {
testResult.setScenarioExecution(ScenarioExecutionResourceIT.createEntity(entityManager));
}

return testResult;
}

/**
Expand Down Expand Up @@ -758,16 +769,18 @@ void getAllTestResultsByTestParameterIsEqualToSomething() throws Exception {
@Test
@Transactional
void deleteAllTestResults() throws Exception {
TestParameter testParameter = getOrCreateTestParameterWithTestResult();
testResult = createEntity(entityManager, true);
getOrCreateTestParameterWithTestResult();

int databaseSizeBeforeDelete = testResultRepository.findAll().size();
assertThat(testResultRepository.findAll())
.isNotEmpty();

mockMvc
.perform(delete(ENTITY_API_URL).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent());

List<TestResult> eventList = testResultRepository.findAll();
assertThat(eventList).hasSize(databaseSizeBeforeDelete - 1);
assertThat(testResultRepository.findAll())
.isEmpty();
}

private TestParameter getOrCreateTestParameterWithTestResult() {
Expand Down

0 comments on commit e852eb6

Please sign in to comment.