Skip to content

Commit

Permalink
fix: cascade test parameters when persisting result
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed May 14, 2024
1 parent de152a3 commit 4f9e57f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.HashSet;
import java.util.Set;

import static jakarta.persistence.CascadeType.REMOVE;
import static jakarta.persistence.CascadeType.ALL;
import static java.util.Objects.nonNull;
import static lombok.AccessLevel.NONE;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause;
Expand Down Expand Up @@ -107,7 +107,7 @@ public class TestResult extends AbstractAuditingEntity<TestResult, Long> impleme
/**
* Optional test parameters
*/
@OneToMany(mappedBy = "testResult", cascade = {REMOVE})
@OneToMany(mappedBy = "testResult", cascade = ALL)
@JsonIgnoreProperties(value = {"testResult"}, allowSetters = true)
private final Set<TestParameter> testParameters = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.citrusframework.simulator.service.impl;

import org.citrusframework.simulator.IntegrationTest;
import org.citrusframework.simulator.model.ScenarioExecution;
import org.citrusframework.simulator.model.TestParameter;
import org.citrusframework.simulator.model.TestResult;
import org.citrusframework.simulator.service.ScenarioExecutionService;
import org.citrusframework.simulator.service.TestParameterService;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
import org.springframework.beans.factory.annotation.Autowired;

import static java.time.Instant.now;
import static org.assertj.core.api.Assertions.assertThat;

@Isolated
@IntegrationTest
class ScenarioExecutionServiceIT {

@Autowired
private TestParameterService testParameterService;

@Autowired
private ScenarioExecutionService fixture;

@Nested
class CompleteScenarioExecution {

@Test
void cascadesUpdateEvent() {
var scenarioExecution = fixture.save(
ScenarioExecution.builder()
.scenarioName("cascadesUpdateEvent")
.startDate(now())
.build()
);

var result = fixture.completeScenarioExecution(
scenarioExecution.getExecutionId(),
TestResult.builder()
.testName("cascadesUpdateEvent")
.className(getClass().getSimpleName())
.build()
.addTestParameter(
TestParameter.builder()
.key("key")
.value("value")
.build()));

assertThat(result.getTestResult().getTestParameters())
.allSatisfy(
p -> assertThat(p.getTestParameterId().testResultId)
.isNotNull()
);
}
}
}

0 comments on commit 4f9e57f

Please sign in to comment.