Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JHttpUserScenarioInvocationResult com.griddynamics.jagger.invoker.scenario.JHttpUserScenarioInvoker.invoke ( Void  nothing,
JHttpUserScenario  scenario 
) throws InvocationException

Definition at line 29 of file JHttpUserScenarioInvoker.java.

References com.griddynamics.jagger.invoker.scenario.JHttpScenarioGlobalContext.copy(), com.griddynamics.jagger.invoker.v2.SpringBasedHttpClient.execute(), and com.griddynamics.jagger.invoker.scenario.JHttpScenarioGlobalContext.getGlobalHeaders().

29  {
30  Boolean scenarioSucceeded = true;
31  JHttpUserScenarioStep previousStep = null;
32  List<JHttpUserScenarioStepInvocationResult> stepInvocationResults = new ArrayList<>();
33 
34  JHttpScenarioGlobalContext localScenarioContext = scenario.getScenarioGlobalContext().copy();
35 
36  for (JHttpUserScenarioStep userScenarioStep : scenario.getUserScenarioSteps()) {
37 
38  // Pre process step: internal setup. Can be later overridden by the user
39  // Basic auth
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);
43  }
44 
45  // Pre process step: user actions executed before request
46  userScenarioStep.preProcessGlobalContext(previousStep, localScenarioContext);
47  userScenarioStep.preProcess(previousStep);
48 
49  // check endpoint for null
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.");
52  // use global endpoint for step if step has none
53  if (userScenarioStep.getEndpoint() == null)
54  userScenarioStep.setEndpoint(localScenarioContext.getGlobalEndpoint());
55  // copy global headers and cookies to current step if query is present
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()));
63  } else {
64  userScenarioStep.getQuery().header(header, values);
65  }
66  });
67  }
68 
69  log.info("Step {}: {}", userScenarioStep.getStepNumber(), userScenarioStep.getStepId());
70  log.info("Endpoint: {}", userScenarioStep.getEndpoint());
71  log.info("Query: {}", userScenarioStep.getQuery());
72 
73  // Request execution step
74  long requestStartTime = System.nanoTime();
75  JHttpResponse response = httpClient.execute(userScenarioStep.getEndpoint(), userScenarioStep.getQuery());
76  Double requestTimeInMilliseconds = (System.nanoTime() - requestStartTime) / 1_000_000.0;
77 
78  //TODO: JFG-1121
79  log.info("Response: {}", response);
80 
81  // Wait after execution if needed
82  userScenarioStep.waitAfterExecution();
83 
84  // Post process step: executed after request. If returned false, scenario invocation stops.
85  Boolean succeeded = userScenarioStep.postProcess(response);
86  stepInvocationResults.add(new JHttpUserScenarioStepInvocationResult(userScenarioStep.getStepId(), userScenarioStep.getStepDisplayName(),
87  requestTimeInMilliseconds, succeeded));
88  previousStep = userScenarioStep;
89 
90  if (!succeeded) {
91  scenarioSucceeded = false;
92  log.error("Step {} '{}' post process returned false! Stopping scenario (next steps won't be executed).",
93  userScenarioStep.getStepId(), userScenarioStep.getStepDisplayName());
94  break;
95  }
96  }
97 
98  return new JHttpUserScenarioInvocationResult(stepInvocationResults, scenario.getScenarioId(), scenario.getScenarioDisplayName(), scenarioSucceeded);
99  }

Here is the call graph for this function: