30 Boolean scenarioSucceeded =
true;
31 JHttpUserScenarioStep previousStep = null;
32 List<JHttpUserScenarioStepInvocationResult> stepInvocationResults =
new ArrayList<>();
34 JHttpScenarioGlobalContext localScenarioContext = scenario.getScenarioGlobalContext().copy();
36 for (JHttpUserScenarioStep userScenarioStep : scenario.getUserScenarioSteps()) {
40 if (localScenarioContext.getPassword() != null && localScenarioContext.getUserName() != null) {
41 String value = Base64.getEncoder().encodeToString((localScenarioContext.getUserName() +
":" + localScenarioContext.getPassword()).getBytes());
42 userScenarioStep.getQuery().header(
"Authorization",
"Basic " + value);
46 userScenarioStep.preProcessGlobalContext(previousStep, localScenarioContext);
47 userScenarioStep.preProcess(previousStep);
50 if (localScenarioContext.getGlobalEndpoint() == null && userScenarioStep.getEndpoint() == null)
51 throw new IllegalArgumentException(
"Endpoint must not be null! Please, set global endpoint or set endpoint for every step.");
53 if (userScenarioStep.getEndpoint() == null)
54 userScenarioStep.setEndpoint(localScenarioContext.getGlobalEndpoint());
56 if (localScenarioContext.getGlobalHeaders() != null && userScenarioStep.getQuery() != null) {
57 localScenarioContext.getGlobalHeaders().forEach((header, values) -> {
58 if (userScenarioStep.getQuery().getHeaders() != null && userScenarioStep.getQuery().getHeaders().containsKey(header)) {
59 List<String> newValues = newArrayList(userScenarioStep.getQuery().getHeaders().get(header));
60 newValues.addAll(values);
61 userScenarioStep.getQuery().getHeaders().put(header, newValues.stream().distinct().collect(
62 Collectors.toList()));
64 userScenarioStep.getQuery().header(header, values);
69 log.info(
"Step {}: {}", userScenarioStep.getStepNumber(), userScenarioStep.getStepId());
70 log.info(
"Endpoint: {}", userScenarioStep.getEndpoint());
71 log.info(
"Query: {}", userScenarioStep.getQuery());
74 long requestStartTime = System.nanoTime();
75 JHttpResponse response = httpClient.
execute(userScenarioStep.getEndpoint(), userScenarioStep.getQuery());
76 Double requestTimeInMilliseconds = (System.nanoTime() - requestStartTime) / 1_000_000.0;
79 log.info(
"Response: {}", response);
82 userScenarioStep.waitAfterExecution();
85 Boolean succeeded = userScenarioStep.postProcess(response);
86 stepInvocationResults.add(
new JHttpUserScenarioStepInvocationResult(userScenarioStep.getStepId(), userScenarioStep.getStepDisplayName(),
87 requestTimeInMilliseconds, succeeded));
88 previousStep = userScenarioStep;
91 scenarioSucceeded =
false;
92 log.error(
"Step {} '{}' post process returned false! Stopping scenario (next steps won't be executed).",
93 userScenarioStep.getStepId(), userScenarioStep.getStepDisplayName());
98 return new JHttpUserScenarioInvocationResult(stepInvocationResults, scenario.getScenarioId(), scenario.getScenarioDisplayName(), scenarioSucceeded);