Skip to content

Commit 351c1af

Browse files
committed
init
0 parents  commit 351c1af

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
.sts4-cache
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/build/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/
26+
27+
### NOVA
28+
asm-log/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package fr.enedis.teme.assertapi.core;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Setter
10+
@Getter
11+
@NoArgsConstructor
12+
public class HttpQuery extends HttpRequest {
13+
14+
private boolean debug = false;
15+
private boolean disabled = false;
16+
private boolean strict = true;
17+
private boolean parallel = true;
18+
private String description = "";
19+
private HttpRequest expected;
20+
private HttpRequest actual;
21+
22+
public HttpQuery build() {
23+
if(getUri() == null) {
24+
requireNonNull(expected);
25+
requireNonNull(actual);
26+
}
27+
else {
28+
expected = actual = this;
29+
}
30+
return this;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return description + " : " + super.toString();
36+
}
37+
38+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package fr.enedis.teme.assertapi.core;
2+
3+
import static java.nio.charset.StandardCharsets.ISO_8859_1;
4+
import static java.nio.charset.StandardCharsets.UTF_16;
5+
import static java.nio.charset.StandardCharsets.UTF_8;
6+
import static java.util.Objects.requireNonNull;
7+
8+
import java.nio.charset.Charset;
9+
10+
import lombok.Getter;
11+
import lombok.NoArgsConstructor;
12+
import lombok.Setter;
13+
14+
@Setter
15+
@Getter
16+
@NoArgsConstructor
17+
public class HttpRequest {
18+
19+
private String uri;
20+
private String method = "GET";
21+
private String charset = "UTF-8";
22+
private String[] excludePaths;
23+
24+
public String url() {
25+
return requireNonNull(uri).trim().startsWith("/") ? uri : "/" + uri;
26+
}
27+
28+
public String httpMethod() {
29+
30+
return requireNonNull(method).trim().toUpperCase();
31+
}
32+
33+
public Charset charset(){
34+
35+
switch(requireNonNull(charset).trim().toUpperCase().replace('-', '_')) {
36+
case "ISO_8859_1": return ISO_8859_1;
37+
case "UTF_8": return UTF_8;
38+
case "UTF_16": return UTF_16;
39+
default : throw new IllegalArgumentException("Unsupported charset " + charset);
40+
}
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "["+method+"]" + " " + uri;
46+
}
47+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package fr.enedis.teme.assertapi.core;
2+
3+
import static java.lang.Integer.parseInt;
4+
import static java.lang.String.format;
5+
import static java.lang.String.valueOf;
6+
7+
import java.util.HashMap;
8+
9+
import lombok.NoArgsConstructor;
10+
11+
@SuppressWarnings("serial")
12+
@NoArgsConstructor
13+
public final class ServerConfig extends HashMap<String, String> {
14+
15+
private static final String PORT_KEY = "port";
16+
private static final String HOST_KEY = "host";
17+
18+
private ServerConfig(String host, int port) {
19+
put(HOST_KEY, host);
20+
put(PORT_KEY, valueOf(port));
21+
}
22+
23+
public String buildRootUrl() {
24+
25+
int port = getPort();
26+
return format("http%s://%s",
27+
port == 443 ? "s" : "", getHost()) +
28+
(port == 80 || port == 443 ? "" : ":" + port) + "/";
29+
}
30+
31+
public static ServerConfig localServer(int port) {
32+
33+
return new ServerConfig("localhost", port);
34+
}
35+
36+
public String getHost() {
37+
return get(HOST_KEY);
38+
}
39+
40+
public int getPort(){
41+
return parseInt(get(PORT_KEY));
42+
}
43+
44+
public String getAuthMethod() {
45+
return get("auth-method");
46+
}
47+
48+
public String getToken() {
49+
return get("token");
50+
}
51+
52+
public String getUsername() {
53+
return get("username");
54+
}
55+
56+
public String getPassword() {
57+
return get("password");
58+
}
59+
60+
public String getAccessTokenUrl() {
61+
return get("access-token-url");
62+
}
63+
64+
}

0 commit comments

Comments
 (0)