-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathHoverflyOkHttpClientFactory.java
More file actions
75 lines (61 loc) · 2.07 KB
/
HoverflyOkHttpClientFactory.java
File metadata and controls
75 lines (61 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package io.specto.hoverfly.junit.api;
import io.specto.hoverfly.junit.core.HoverflyConstants;
import io.specto.hoverfly.junit.core.config.HoverflyConfiguration;
public class HoverflyOkHttpClientFactory implements HoverflyClientFactory {
public HoverflyClient createHoverflyClient(HoverflyConfiguration hoverflyConfig) {
return custom()
.scheme(hoverflyConfig.getScheme())
.host(hoverflyConfig.getHost())
.port(hoverflyConfig.getAdminPort())
.withAuthToken()
.build();
}
/**
* Static factory method for creating a {@link Builder}
* @return a builder for HoverflyClient
*/
static Builder custom() {
return new Builder();
}
/**
* Static factory method for default Hoverfly client
* @return a default HoverflyClient
*/
static HoverflyClient createDefault() {
return new Builder().build();
}
/**
* HTTP client builder for Hoverfly admin API
*/
static class Builder {
private String scheme = HoverflyConstants.HTTP;
private String host = HoverflyConstants.LOCALHOST;
private int port = HoverflyConstants.DEFAULT_ADMIN_PORT;
private String authToken = null;
Builder() {
}
public Builder scheme(String scheme) {
this.scheme = scheme;
return this;
}
public Builder host(String host) {
this.host = host;
return this;
}
public Builder port(int port) {
this.port = port;
return this;
}
/**
* Get token from environment variable "HOVERFLY_AUTH_TOKEN" to authenticate with admin API
* @return this Builder for further customizations
*/
public Builder withAuthToken() {
this.authToken = System.getenv(HoverflyConstants.HOVERFLY_AUTH_TOKEN);
return this;
}
public HoverflyClient build() {
return new OkHttpHoverflyClient(scheme, host, port, authToken);
}
}
}