Skip to content

Commit 986973a

Browse files
committed
deprecated httpserver, please used httpServer instead
1 parent 8f582be commit 986973a

18 files changed

+98
-82
lines changed

moco-core/src/main/java/com/github/dreamhead/moco/Moco.java

+20-5
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,37 @@
4747
import static java.lang.String.format;
4848

4949
public class Moco {
50-
public static HttpServer httpserver(final int port, final MocoConfig... configs) {
50+
public static HttpServer httpServer(final int port, final MocoConfig... configs) {
5151
checkArgument(port > 0, "Port must be greater than zero");
5252
return ActualHttpServer.createQuietServer(of(port), configs);
5353
}
5454

55-
public static HttpServer httpserver(final int port, final MocoMonitor monitor, final MocoConfig... configs) {
55+
@Deprecated
56+
public static HttpServer httpserver(final int port, final MocoConfig... configs) {
57+
return httpServer(port, configs);
58+
}
59+
60+
public static HttpServer httpServer(final int port, final MocoMonitor monitor, final MocoConfig... configs) {
5661
checkArgument(port > 0, "Port must be greater than zero");
5762
return ActualHttpServer.createHttpServerWithMonitor(of(port),
5863
checkNotNull(monitor, "Monitor should not be null"), configs);
5964
}
6065

61-
public static HttpServer httpserver(final int port, final MocoMonitor monitor, final MocoMonitor monitor2, final MocoMonitor... monitors) {
66+
@Deprecated
67+
public static HttpServer httpserver(final int port, final MocoMonitor monitor, final MocoConfig... configs) {
68+
return httpServer(port, monitor, configs);
69+
}
70+
71+
public static HttpServer httpServer(final int port, final MocoMonitor monitor, final MocoMonitor monitor2, final MocoMonitor... monitors) {
6272
checkArgument(port > 0, "Port must be greater than zero");
6373
return ActualHttpServer.createHttpServerWithMonitor(of(port), mergeMonitor(monitor, monitor2, monitors));
6474
}
6575

76+
@Deprecated
77+
public static HttpServer httpserver(final int port, final MocoMonitor monitor, final MocoMonitor monitor2, final MocoMonitor... monitors) {
78+
return httpServer(port, monitor, monitor2, monitors);
79+
}
80+
6681
private static MocoMonitor mergeMonitor(MocoMonitor monitor, MocoMonitor monitor2, MocoMonitor[] monitors) {
6782
MocoMonitor[] targetMonitors = new MocoMonitor[2 + monitors.length];
6883
targetMonitors[0] = checkNotNull(monitor, "Monitor should not be null");
@@ -74,11 +89,11 @@ private static MocoMonitor mergeMonitor(MocoMonitor monitor, MocoMonitor monitor
7489
return new CompositeMonitor(targetMonitors);
7590
}
7691

77-
public static HttpServer httpserver(final MocoConfig... configs) {
92+
public static HttpServer httpServer(final MocoConfig... configs) {
7893
return ActualHttpServer.createQuietServer(Optional.<Integer>absent(), configs);
7994
}
8095

81-
public static HttpServer httpserver(final MocoMonitor monitor, final MocoConfig... configs) {
96+
public static HttpServer httpServer(final MocoMonitor monitor, final MocoConfig... configs) {
8297
return ActualHttpServer.createHttpServerWithMonitor(Optional.<Integer>absent(), checkNotNull(monitor, "Monitor should not be null"), configs);
8398
}
8499

moco-core/src/test/java/com/github/dreamhead/moco/AbstractMocoHttpTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.github.dreamhead.moco.helper.MocoTestHelper;
44
import org.junit.Before;
55

6-
import static com.github.dreamhead.moco.Moco.httpserver;
6+
import static com.github.dreamhead.moco.Moco.httpServer;
77
import static com.github.dreamhead.moco.helper.RemoteTestUtils.port;
88

99
public class AbstractMocoHttpTest {
@@ -13,6 +13,6 @@ public class AbstractMocoHttpTest {
1313
@Before
1414
public void setUp() throws Exception {
1515
helper = new MocoTestHelper();
16-
server = httpserver(port());
16+
server = httpServer(port());
1717
}
1818
}

moco-core/src/test/java/com/github/dreamhead/moco/MocoContextTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class MocoContextTest {
2525
@Before
2626
public void setUp() throws Exception {
2727
helper = new MocoTestHelper();
28-
server = httpserver(port(), context("/context"));
28+
server = httpServer(port(), context("/context"));
2929
}
3030

3131
@Test

moco-core/src/test/java/com/github/dreamhead/moco/MocoDefenseTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class MocoDefenseTest extends AbstractMocoHttpTest {
1111
@Test(expected = HttpResponseException.class)
1212
public void should_work_well_without_response_setting() throws Exception {
13-
server = httpserver(12306, context("/foo"));
13+
server = httpServer(12306, context("/foo"));
1414
server.request(by("bar"));
1515

1616
running(server, new Runnable() {

moco-core/src/test/java/com/github/dreamhead/moco/MocoEventTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void run() throws Exception {
150150
public void should_fire_event_for_context_configuration() throws Exception {
151151
MocoEventAction action = mock(MocoEventAction.class);
152152
when(action.apply(Matchers.<MocoConfig>anyObject())).thenReturn(action);
153-
server = httpserver(port(), context("/context"));
153+
server = httpServer(port(), context("/context"));
154154
server.get(by(uri("/foo"))).response("foo").on(complete(action));
155155

156156
running(server, new Runnable() {
@@ -168,7 +168,7 @@ public void should_send_post_request_with_file_root_configuration() throws Excep
168168
ResponseHandler handler = mock(ResponseHandler.class);
169169
when(handler.apply(Matchers.<MocoConfig>anyObject())).thenReturn(handler);
170170

171-
server = httpserver(port(), fileRoot("src/test/resources"));
171+
server = httpServer(port(), fileRoot("src/test/resources"));
172172
server.request(by(uri("/target")), by(file("foo.request"))).response(handler);
173173
server.request(by(uri("/event"))).response("event").on(complete(post(remoteUrl("/target"), file("foo.request"))));
174174

moco-core/src/test/java/com/github/dreamhead/moco/MocoFileRootTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class MocoFileRootTest {
2424
@Before
2525
public void setup() {
2626
helper = new MocoTestHelper();
27-
server = httpserver(port(), fileRoot("src/test/resources"));
27+
server = httpServer(port(), fileRoot("src/test/resources"));
2828
}
2929

3030
@Test
@@ -41,7 +41,7 @@ public void run() throws IOException {
4141

4242
@Test
4343
public void should_return_header_from_file_root() throws Exception {
44-
server = httpserver(port(), log(), fileRoot("src/test/resources"));
44+
server = httpServer(port(), log(), fileRoot("src/test/resources"));
4545
server.response(header("foo", file("foo.response")));
4646

4747
running(server, new Runnable() {

moco-core/src/test/java/com/github/dreamhead/moco/MocoGlobalRequestTest.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class MocoGlobalRequestTest extends AbstractMocoHttpTest {
1919
@Test
2020
public void should_match_global_header() throws Exception {
21-
server = httpserver(port(), request(eq(header("foo"), "bar")));
21+
server = httpServer(port(), request(eq(header("foo"), "bar")));
2222
server.request(by(uri("/global-request"))).response(text("blah"));
2323

2424
running(server, new Runnable() {
@@ -32,7 +32,7 @@ public void run() throws Exception {
3232

3333
@Test(expected = HttpResponseException.class)
3434
public void should_throw_exception_without_global_matcher() throws Exception {
35-
server = httpserver(port(), request(eq(header("foo"), "bar")));
35+
server = httpServer(port(), request(eq(header("foo"), "bar")));
3636
server.request(by(uri("/global-request"))).response(text("blah"));
3737

3838
running(server, new Runnable() {
@@ -46,7 +46,7 @@ public void run() throws Exception {
4646

4747
@Test
4848
public void should_match_global_header_with_any_response() throws Exception {
49-
server = httpserver(port(), request(eq(header("foo"), "bar")));
49+
server = httpServer(port(), request(eq(header("foo"), "bar")));
5050
server.response(text("blah"));
5151

5252
running(server, new Runnable() {
@@ -61,7 +61,7 @@ public void run() throws Exception {
6161

6262
@Test(expected = HttpResponseException.class)
6363
public void should_throw_exception_without_global_matcher_for_any_response() throws Exception {
64-
server = httpserver(port(), request(eq(header("foo"), "bar")));
64+
server = httpServer(port(), request(eq(header("foo"), "bar")));
6565
server.response(text("blah"));
6666

6767
running(server, new Runnable() {
@@ -74,7 +74,7 @@ public void run() throws Exception {
7474

7575
@Test
7676
public void should_match_with_exist_header() throws Exception {
77-
server = httpserver(port(), request(eq(header("foo"), "bar")));
77+
server = httpServer(port(), request(eq(header("foo"), "bar")));
7878
server.request(exist(header("blah"))).response(text("header"));
7979

8080
running(server, new Runnable() {
@@ -87,7 +87,7 @@ public void run() throws Exception {
8787

8888
@Test(expected = HttpResponseException.class)
8989
public void should_throw_exception_without_global_matcher_for_exist() throws Exception {
90-
server = httpserver(port(), request(eq(header("foo"), "bar")));
90+
server = httpServer(port(), request(eq(header("foo"), "bar")));
9191
server.request(exist(header("blah"))).response(text("header"));
9292

9393
running(server, new Runnable() {
@@ -100,7 +100,7 @@ public void run() throws Exception {
100100

101101
@Test
102102
public void should_match_with_json() throws Exception {
103-
server = httpserver(port(), request(by(uri("/path"))));
103+
server = httpServer(port(), request(by(uri("/path"))));
104104
final String jsonContent = "{\"foo\":\"bar\"}";
105105
server.request(json(text(jsonContent))).response("foo");
106106
running(server, new Runnable() {
@@ -113,7 +113,7 @@ public void run() throws IOException {
113113

114114
@Test(expected = HttpResponseException.class)
115115
public void should_throw_exception_without_match_json() throws Exception {
116-
server = httpserver(port(), request(by(uri("/path"))));
116+
server = httpServer(port(), request(by(uri("/path"))));
117117
final String jsonContent = "{\"foo\":\"bar\"}";
118118
server.request(json(text(jsonContent))).response("foo");
119119
running(server, new Runnable() {
@@ -126,7 +126,7 @@ public void run() throws IOException {
126126

127127
@Test
128128
public void should_match_with_xml() throws Exception {
129-
server = httpserver(port(), request(by(uri("/path"))));
129+
server = httpServer(port(), request(by(uri("/path"))));
130130
server.request(xml(text("<request><parameters><id>1</id></parameters></request>"))).response("foo");
131131
running(server, new Runnable() {
132132
@Override
@@ -138,7 +138,7 @@ public void run() throws IOException {
138138

139139
@Test(expected = HttpResponseException.class)
140140
public void should_throw_exception_without_match_xml() throws Exception {
141-
server = httpserver(port(), request(by(uri("/path"))));
141+
server = httpServer(port(), request(by(uri("/path"))));
142142
server.request(xml(text("<request><parameters><id>1</id></parameters></request>"))).response("foo");
143143
running(server, new Runnable() {
144144
@Override
@@ -151,7 +151,7 @@ public void run() throws IOException {
151151
@Test
152152
public void should_match_mount() throws Exception {
153153
final String MOUNT_DIR = "src/test/resources/test";
154-
server = httpserver(port(), request(eq(header("foo"), "bar")));
154+
server = httpServer(port(), request(eq(header("foo"), "bar")));
155155
server.mount(MOUNT_DIR, to("/dir"));
156156

157157
running(server, new Runnable() {
@@ -165,7 +165,7 @@ public void run() throws IOException {
165165
@Test(expected = HttpResponseException.class)
166166
public void should_throw_exception_without_match_mount() throws Exception {
167167
final String MOUNT_DIR = "src/test/resources/test";
168-
server = httpserver(port(), request(eq(header("foo"), "bar")));
168+
server = httpServer(port(), request(eq(header("foo"), "bar")));
169169
server.mount(MOUNT_DIR, to("/dir"));
170170

171171
running(server, new Runnable() {
@@ -178,7 +178,7 @@ public void run() throws IOException {
178178

179179
@Test
180180
public void should_match_request_based_on_not_matcher() throws Exception {
181-
server = httpserver(port(), request(eq(header("foo"), "bar")));
181+
server = httpServer(port(), request(eq(header("foo"), "bar")));
182182
server.request(not(by(uri("/foo")))).response(text("bar"));
183183

184184
running(server, new Runnable() {
@@ -191,7 +191,7 @@ public void run() throws IOException {
191191

192192
@Test(expected = HttpResponseException.class)
193193
public void should_throw_exception_without_match_not() throws Exception {
194-
server = httpserver(port(), request(eq(header("foo"), "bar")));
194+
server = httpServer(port(), request(eq(header("foo"), "bar")));
195195
server.request(not(by(uri("/foo")))).response(text("bar"));
196196

197197
running(server, new Runnable() {
@@ -204,7 +204,7 @@ public void run() throws IOException {
204204

205205
@Test
206206
public void should_match_request_based_on_and_matcher() throws Exception {
207-
server = httpserver(port(), request(eq(header("foo"), "bar")));
207+
server = httpServer(port(), request(eq(header("foo"), "bar")));
208208
server.request(and(by(uri("/foo")), eq(header("header"), "blah"))).response(text("bar"));
209209

210210
running(server, new Runnable() {
@@ -217,7 +217,7 @@ public void run() throws IOException {
217217

218218
@Test(expected = HttpResponseException.class)
219219
public void should_throw_exception_without_match_and_matcher() throws Exception {
220-
server = httpserver(port(), request(eq(header("foo"), "bar")));
220+
server = httpServer(port(), request(eq(header("foo"), "bar")));
221221
server.request(and(by(uri("/foo")), eq(header("header"), "blah"))).response(text("bar"));
222222

223223
running(server, new Runnable() {

moco-core/src/test/java/com/github/dreamhead/moco/MocoGlobalResponseTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class MocoGlobalResponseTest {
2525

2626
@Test
2727
public void should_return_all_response_for_version_with_header() throws Exception {
28-
server = httpserver(port(), response(header("Content-Type", "text/plain")));
28+
server = httpServer(port(), response(header("Content-Type", "text/plain")));
2929
server.response(version(VERSION_1_0));
3030

3131
running(server, new Runnable() {
@@ -40,7 +40,7 @@ public void run() throws Exception {
4040

4141
@Test
4242
public void should_return_all_response_for_content_with_header() throws Exception {
43-
server = httpserver(port(), response(header("foo", "bar")));
43+
server = httpServer(port(), response(header("foo", "bar")));
4444
server.response("hello");
4545

4646
running(server, new Runnable() {
@@ -58,7 +58,7 @@ public void run() throws Exception {
5858

5959
@Test
6060
public void should_return_all_response_for_header_with_header() throws Exception {
61-
server = httpserver(port(), response(header("foo", "bar")));
61+
server = httpServer(port(), response(header("foo", "bar")));
6262
server.response(header("blah", "param"));
6363

6464
running(server, new Runnable() {
@@ -73,7 +73,7 @@ public void run() throws Exception {
7373

7474
@Test
7575
public void should_return_all_response_for_status_with_header() throws Exception {
76-
server = httpserver(port(), response(header("foo", "bar")));
76+
server = httpServer(port(), response(header("foo", "bar")));
7777
server.response(status(200));
7878

7979
running(server, new Runnable() {
@@ -88,7 +88,7 @@ public void run() throws Exception {
8888

8989
@Test
9090
public void should_return_all_response_for_and_response_handler_with_header() throws Exception {
91-
server = httpserver(port(), response(header("foo", "bar")));
91+
server = httpServer(port(), response(header("foo", "bar")));
9292
server.response(status(200), with(version(VERSION_1_0)));
9393

9494
running(server, new Runnable() {
@@ -103,7 +103,7 @@ public void run() throws Exception {
103103

104104
@Test
105105
public void should_return_all_response_for_proxy_with_header() throws Exception {
106-
server = httpserver(port(), response(header("foo", "bar")));
106+
server = httpServer(port(), response(header("foo", "bar")));
107107
server.response(proxy("https://github.com/"));
108108

109109
running(server, new Runnable() {
@@ -119,7 +119,7 @@ public void run() throws Exception {
119119
@Test
120120
public void should_return_all_response_for_mount_with_header() throws Exception {
121121
String MOUNT_DIR = "src/test/resources/test";
122-
server = httpserver(port(), response(header("foo", "bar")));
122+
server = httpServer(port(), response(header("foo", "bar")));
123123
server.mount(MOUNT_DIR, to("/dir"));
124124

125125
running(server, new Runnable() {
@@ -134,7 +134,7 @@ public void run() throws IOException {
134134

135135
@Test
136136
public void should_return_all_response_for_latency_with_header() throws Exception {
137-
server = httpserver(port(), response(header("foo", "bar")));
137+
server = httpServer(port(), response(header("foo", "bar")));
138138
server.response(latency(1, TimeUnit.SECONDS));
139139

140140
running(server, new Runnable() {
@@ -149,7 +149,7 @@ public void run() throws Exception {
149149

150150
@Test
151151
public void should_return_all_response_for_seq_with_header() throws Exception {
152-
server = httpserver(port(), response(header("foo", "bar")));
152+
server = httpServer(port(), response(header("foo", "bar")));
153153
server.response(seq("hello", "world"));
154154

155155
running(server, new Runnable() {

moco-core/src/test/java/com/github/dreamhead/moco/MocoLogTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void setUp() throws Exception {
3838

3939
@Test
4040
public void should_log_request_and_response() throws Exception {
41-
HttpServer server = httpserver(port(), log());
41+
HttpServer server = httpServer(port(), log());
4242
server.request(by("0XCAFE")).response("0XBABE");
4343
File file = folder.newFile();
4444
System.setOut(new PrintStream(new FileOutputStream(file)));
@@ -58,7 +58,7 @@ public void run() throws Exception {
5858
@Test
5959
public void should_log_request_and_response_into_file() throws Exception {
6060
File file = folder.newFile();
61-
HttpServer server = httpserver(port(), log(file.getAbsolutePath()));
61+
HttpServer server = httpServer(port(), log(file.getAbsolutePath()));
6262
server.request(by("0XCAFE")).response("0XBABE");
6363

6464
running(server, new Runnable() {
@@ -76,7 +76,7 @@ public void run() throws Exception {
7676
@Test
7777
public void should_log_request_and_response_with_exception() throws Exception {
7878
File file = folder.newFile();
79-
HttpServer server = httpserver(port(), log(file.getAbsolutePath()));
79+
HttpServer server = httpServer(port(), log(file.getAbsolutePath()));
8080
ResponseHandler mock = mock(ResponseHandler.class);
8181
doThrow(RuntimeException.class).when(mock).writeToResponse(any(SessionContext.class));
8282

@@ -99,7 +99,7 @@ public void run() throws Exception {
9999
@Test
100100
public void should_log_request_and_response_into_file_with_charset() throws Exception {
101101
File file = folder.newFile();
102-
HttpServer server = httpserver(port(), log(file.getAbsolutePath(), Charset.forName("UTF-8")));
102+
HttpServer server = httpServer(port(), log(file.getAbsolutePath(), Charset.forName("UTF-8")));
103103
server.request(by("0XCAFE")).response("0XBABE");
104104

105105
running(server, new Runnable() {

0 commit comments

Comments
 (0)