Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JHttpScenarioGlobalContext.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.invoker.scenario;
2 
3 import com.griddynamics.jagger.invoker.v2.JHttpEndpoint;
4 import org.springframework.http.HttpHeaders;
5 
6 import java.util.List;
7 import java.util.Map;
8 
9 import static com.google.common.collect.Lists.newArrayList;
10 
17  private String userName;
18  private String password;
19  private JHttpEndpoint globalEndpoint;
20  private HttpHeaders globalHeaders;
21 
24  return copy.withBasicAuth(this.userName, this.password)
25  .withGlobalEndpoint(JHttpEndpoint.copyOf(this.globalEndpoint))
26  .withGlobalHeaders(CopyUtil.copyOf(this.globalHeaders));
27  }
28 
36  this.globalEndpoint = globalEndpoint;
37  return this;
38  }
39 
43  public JHttpScenarioGlobalContext withBasicAuth(String userName, String password) {
44  this.userName = userName;
45  this.password = password;
46  return this;
47  }
48 
54  public JHttpScenarioGlobalContext withGlobalHeaders(HttpHeaders globalHeaders) {
55  this.globalHeaders = globalHeaders;
56  return this;
57  }
58 
64  public JHttpScenarioGlobalContext withGlobalHeaders(Map<String, List<String>> globalHeaders) {
65  initHeadersIfNull();
66  this.globalHeaders.putAll(globalHeaders);
67  return this;
68  }
69 
74  public JHttpScenarioGlobalContext withGlobalHeader(String key, String value) {
75  initHeadersIfNull();
76  globalHeaders.put(key, newArrayList(value));
77  return this;
78  }
79 
85  public JHttpScenarioGlobalContext withGlobalCookies(Map<String, String> cookies) {
86  initHeadersIfNull();
87  cookies.entrySet().forEach(entry -> this.globalHeaders.add("Cookie", entry.getKey() + "=" + entry.getValue()));
88  return this;
89  }
90 
94  public JHttpScenarioGlobalContext withGlobalCookie(String name, String value) {
95  initHeadersIfNull();
96  this.globalHeaders.add("Cookie", name + "=" + value);
97  return this;
98  }
99 
100  private void initHeadersIfNull() {
101  if (this.globalHeaders == null)
102  this.globalHeaders = new HttpHeaders();
103  }
104 
106  return globalEndpoint;
107  }
108 
109  public String getUserName() {
110  return userName;
111  }
112 
113  public String getPassword() {
114  return password;
115  }
116 
117  public HttpHeaders getGlobalHeaders() {
118  return globalHeaders;
119  }
120 
121  public List<String> getGlobalCookies() {
122  return globalHeaders.get("Cookie");
123  }
124 }