Skip to content

Commit 6d19986

Browse files
committed
feat(engine, server-core, server): fix tests
1 parent 33803e8 commit 6d19986

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

chutney/engine/src/test/java/com/chutneytesting/engine/domain/execution/strategies/ForEachStrategyTest.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
import com.chutneytesting.engine.api.execution.StepExecutionReportDto;
2727
import com.chutneytesting.engine.api.execution.TestEngine;
2828
import com.chutneytesting.tools.Jsons;
29+
import com.fasterxml.jackson.databind.JsonNode;
30+
import com.fasterxml.jackson.databind.node.ArrayNode;
31+
import com.fasterxml.jackson.databind.node.ObjectNode;
32+
import com.fasterxml.jackson.databind.node.TextNode;
2933
import java.time.ZonedDateTime;
30-
import java.util.ArrayList;
31-
import java.util.HashMap;
3234
import java.util.List;
3335
import java.util.UUID;
3436
import org.junit.jupiter.api.Test;
@@ -199,13 +201,13 @@ public void should_evaluate_dataset_before_iterations() {
199201
assertThat(iteration0.status).isEqualTo(SUCCESS);
200202
assertThat(iteration0.name).startsWith("0 -");
201203
assertThat(iteration0.information.get(0)).isEqualTo("Validation [check_0_ok : ${#check_0 == \"/\" + #generatedID + \"/0\"}] : OK");
202-
assertDoesNotThrow(() -> UUID.fromString((String) iteration0.context.evaluatedInputs.get("stringParam")));
204+
assertDoesNotThrow(() -> UUID.fromString(((JsonNode) iteration0.context.evaluatedInputs.get("stringParam")).asText()));
203205

204206
StepExecutionReportDto iteration1 = parentStep.steps.get(1);
205207
assertThat(iteration1.status).isEqualTo(SUCCESS);
206208
assertThat(iteration1.name).startsWith("1 -");
207209
assertThat(iteration1.information.get(0)).isEqualTo("Validation [check_1_ok : ${#check_1 == \"/\" + #generatedID + \"/1\"}] : OK");
208-
assertDoesNotThrow(() -> UUID.fromString((String) iteration1.context.evaluatedInputs.get("stringParam")));
210+
assertDoesNotThrow(() -> UUID.fromString(((JsonNode) iteration1.context.evaluatedInputs.get("stringParam")).asText()));
209211
}
210212

211213
@Test
@@ -221,14 +223,12 @@ public void should_preserve_input_types() {
221223
StepExecutionReportDto iterationWithMap = result.steps.get(0);
222224
assertThat(iterationWithMap.steps).hasSize(2);
223225
assertThat(iterationWithMap.status).isEqualTo(SUCCESS);
224-
assertThat(((HashMap<?, ?>) iterationWithMap.steps.get(0).context.evaluatedInputs.values().stream().toList().get(0)).values())
225-
.hasExactlyElementsOfTypes(ZonedDateTime.class);
226+
assertDoesNotThrow(() -> ZonedDateTime.parse(((ObjectNode) iterationWithMap.steps.get(0).context.evaluatedInputs.values().stream().toList().get(0)).elements().next().asText()));
226227

227228
StepExecutionReportDto iterationWithList = result.steps.get(1);
228229
assertThat(iterationWithList.steps).hasSize(2);
229230
assertThat(iterationWithList.status).isEqualTo(SUCCESS);
230-
assertThat(((ArrayList<?>) iterationWithList.steps.get(0).context.evaluatedInputs.values().stream().toList().get(0)).get(0))
231-
.isOfAnyClassIn(ZonedDateTime.class);
231+
assertDoesNotThrow(() -> ZonedDateTime.parse(((ArrayNode) iterationWithList.steps.get(0).context.evaluatedInputs.values().stream().toList().get(0)).elements().next().asText()));
232232
}
233233

234234
@Test
@@ -306,17 +306,21 @@ public void should_accept_nested_loops_and_override_dataset() {
306306
StepExecutionReportDto firstIteration = parentIterativeStep.steps.get(0).steps.get(0);
307307
assertThat(firstIteration.steps).hasSize(2);
308308
assertThat(firstIteration.steps.get(0).name).startsWith("0 -");
309-
assertThat(firstIteration.steps.get(0).context.stepResults).containsEntry("environment_0.0","overriddenEnvX");
309+
assertThat(firstIteration.steps.get(0).context.stepResults).containsKey("environment_0.0");
310+
assertThat(((TextNode)firstIteration.steps.get(0).context.stepResults.get("environment_0.0")).asText()).isEqualTo("overriddenEnvX");
310311
assertThat(firstIteration.steps.get(1).name).startsWith("1 -");
311-
assertThat(firstIteration.steps.get(1).context.stepResults).containsEntry("environment_0.1","overriddenEnvY");
312+
assertThat(firstIteration.steps.get(1).context.stepResults).containsKey("environment_0.1");
313+
assertThat(((TextNode)firstIteration.steps.get(1).context.stepResults.get("environment_0.1")).asText()).isEqualTo("overriddenEnvY");
312314

313315
// And the second iteration contains 2 nested iterations
314316
StepExecutionReportDto secondIteration = parentIterativeStep.steps.get(1).steps.get(0);
315317
assertThat(secondIteration.steps).hasSize(2);
316318
assertThat(secondIteration.steps.get(0).name).startsWith("0 -");
317-
assertThat(secondIteration.steps.get(0).context.stepResults).containsEntry("environment_1.0","overriddenEnvX");
319+
assertThat(secondIteration.steps.get(0).context.stepResults).containsKey("environment_1.0");
320+
assertThat(((TextNode)secondIteration.steps.get(0).context.stepResults.get("environment_1.0")).asText()).isEqualTo("overriddenEnvX");
318321
assertThat(secondIteration.steps.get(1).name).startsWith("1 -");
319-
assertThat(secondIteration.steps.get(1).context.stepResults).containsEntry("environment_1.1","overriddenEnvY");
322+
assertThat(secondIteration.steps.get(1).context.stepResults).containsKey("environment_1.1");
323+
assertThat(((TextNode)secondIteration.steps.get(1).context.stepResults.get("environment_1.1")).asText()).contains("overriddenEnvY");
320324
}
321325

322326
@Test

chutney/server/src/test/java/com/chutneytesting/execution/domain/ScenarioExecutionTest.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.chutneytesting.server.core.domain.execution.report.StepExecutionReportCoreBuilder;
2626
import com.fasterxml.jackson.core.JsonProcessingException;
2727
import com.fasterxml.jackson.databind.ObjectMapper;
28+
import java.time.Instant;
2829
import java.util.HashMap;
2930
import java.util.List;
3031
import java.util.Map;
@@ -33,20 +34,43 @@
3334
public class ScenarioExecutionTest {
3435

3536
@Test
36-
public void should_serialize_and_deserialize_input_and_output_in_report() throws JsonProcessingException {
37+
public void should_serialize_and_deserialize_simple_input_and_output_in_report() throws JsonProcessingException {
38+
// Given
39+
ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
40+
Map<String, Object> mapStringObject = Map.of("TUTU", "TITI");
41+
42+
Step.StepContextSnapshot stepContextSnapshot = new Step.StepContextSnapshot(mapStringObject, mapStringObject, objectMapper);
43+
StepExecutionReportCore stepExecutionReport = new StepExecutionReportCoreBuilder()
44+
.setStepOutputs(new HashMap<>(stepContextSnapshot.getOutputsSnapshot()))
45+
.setEvaluatedInputs(new HashMap<>(stepContextSnapshot.getInputsSnapshot()))
46+
.createStepExecutionReport();
47+
ScenarioExecutionReport scenarioExecutionReport = new ScenarioExecutionReport(1L, "", "", "", List.of(), stepExecutionReport);
48+
49+
// When
50+
String serializedReport = objectMapper.writeValueAsString(scenarioExecutionReport);
51+
52+
// Then
53+
assertThat(serializedReport).isEqualTo("{\"executionId\":1,\"scenarioName\":\"\",\"environment\":\"\",\"user\":\"\",\"tags\":[],\"constants\":{},\"datatable\":[],\"report\":{\"name\":null,\"duration\":0,\"startDate\":null,\"status\":null,\"information\":[],\"errors\":[],\"steps\":[],\"type\":null,\"targetName\":\"\",\"targetUrl\":\"\",\"strategy\":\"sequential\",\"evaluatedInputs\":{\"TUTU\":\"TITI\"},\"stepOutputs\":{\"TUTU\":\"TITI\"}},\"contextVariables\":{}}");
54+
55+
}
56+
@Test
57+
public void should_serialize_and_deserialize_complex_input_and_output_in_report() throws JsonProcessingException {
3758
// Given
3859
ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
3960
Map<String, Object> mapStringObject = Map.of("TUTU", Map.of("TOTO", Map.of("BUBU",Map.of("VIVI","LALA"))));
4061

4162
Step.StepContextSnapshot stepContextSnapshot = new Step.StepContextSnapshot(mapStringObject, mapStringObject, objectMapper);
42-
StepExecutionReportCore stepExecutionReport = new StepExecutionReportCoreBuilder().setStepOutputs(new HashMap<>(stepContextSnapshot.getOutputsSnapshot())).createStepExecutionReport();
63+
StepExecutionReportCore stepExecutionReport = new StepExecutionReportCoreBuilder()
64+
.setStepOutputs(new HashMap<>(stepContextSnapshot.getOutputsSnapshot()))
65+
.setEvaluatedInputs(new HashMap<>(stepContextSnapshot.getInputsSnapshot()))
66+
.createStepExecutionReport();
4367
ScenarioExecutionReport scenarioExecutionReport = new ScenarioExecutionReport(1L, "", "", "", List.of(), stepExecutionReport);
4468

4569
// When
4670
String serializedReport = objectMapper.writeValueAsString(scenarioExecutionReport);
4771

4872
// Then
49-
assertThat(serializedReport).isEqualTo("{\"executionId\":1,\"scenarioName\":\"\",\"environment\":\"\",\"user\":\"\",\"tags\":[],\"constants\":{},\"datatable\":[],\"report\":{\"name\":null,\"duration\":0,\"startDate\":null,\"status\":null,\"information\":[],\"errors\":[],\"steps\":[],\"type\":null,\"targetName\":\"\",\"targetUrl\":\"\",\"strategy\":\"sequential\",\"evaluatedInputs\":{\"TUTU\":{\"TOTO\":{\"BUBU\":{\"VIVI\":\"LALA\"}}}}},\"stepOutputs\":{\"TUTU\":{\"TOTO\":{\"BUBU\":{\"VIVI\":\"LALA\"}}}}},\"contextVariables\":{}}");
73+
assertThat(serializedReport).isEqualTo("{\"executionId\":1,\"scenarioName\":\"\",\"environment\":\"\",\"user\":\"\",\"tags\":[],\"constants\":{},\"datatable\":[],\"report\":{\"name\":null,\"duration\":0,\"startDate\":null,\"status\":null,\"information\":[],\"errors\":[],\"steps\":[],\"type\":null,\"targetName\":\"\",\"targetUrl\":\"\",\"strategy\":\"sequential\",\"evaluatedInputs\":{\"TUTU\":{\"TOTO\":{\"BUBU\":{\"VIVI\":\"LALA\"}}}},\"stepOutputs\":{\"TUTU\":{\"TOTO\":{\"BUBU\":{\"VIVI\":\"LALA\"}}}}},\"contextVariables\":{}}");
5074

5175
}
5276
}

0 commit comments

Comments
 (0)