Repository navigation
Expand file tree
/
Copy pathServerFeature.java
More file actions
70 lines (54 loc) · 1.96 KB
/
Copy pathServerFeature.java
File metadata and controls
70 lines (54 loc) · 1.96 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
package org.jooby.test;
import static com.google.common.base.Preconditions.checkState;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.http.client.utils.URIBuilder;
import org.jooby.Jooby;
import org.junit.Before;
import org.junit.Rule;
import org.junit.runner.RunWith;
import com.google.common.base.Joiner;
@RunWith(JoobySuite.class)
public abstract class ServerFeature extends Jooby {
public static boolean DEBUG = false;
@Named("port")
@Inject
protected int port;
@Named("securePort")
@Inject
protected int securePort;
public static String protocol = "http";
private Client server = null;
@Before
public void debug() {
if (DEBUG) {
java.util.logging.Logger.getLogger("httpclient.wire.header").setLevel(
java.util.logging.Level.FINEST);
java.util.logging.Logger.getLogger("httpclient.wire.content").setLevel(
java.util.logging.Level.FINEST);
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers",
"debug");
}
}
@Rule
public Client createServer() {
checkState(server == null, "Server was created already");
server = new Client(
protocol + "://localhost:" + (protocol.equals("https") ? securePort : port));
return server;
}
public Client request() {
checkState(server != null, "Server wasn't started");
return server;
}
protected URIBuilder ws(final String... parts) throws Exception {
URIBuilder builder = new URIBuilder("ws://localhost:" + port + "/"
+ Joiner.on("/").join(parts));
return builder;
}
}