1 package com.griddynamics.jagger.invoker.scenario;
3 import com.griddynamics.jagger.invoker.InvocationException;
4 import com.griddynamics.jagger.invoker.Invoker;
5 import com.griddynamics.jagger.invoker.v2.JHttpResponse;
6 import com.griddynamics.jagger.invoker.v2.SpringBasedHttpClient;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 import java.util.ArrayList;
11 import java.util.Base64;
12 import java.util.List;
13 import java.util.stream.Collectors;
15 import static com.google.common.collect.Lists.newArrayList;
30 Boolean scenarioSucceeded =
true;
32 List<JHttpUserScenarioStepInvocationResult> stepInvocationResults =
new ArrayList<>();
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) {
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);
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());