Skip to content

Commit e7c643d

Browse files
committed
review feedback
1 parent ed0035f commit e7c643d

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/RequestsWithoutContentIT.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,63 +30,59 @@ public class RequestsWithoutContentIT extends ESRestTestCase {
3030
public void testIndexMissingBody() throws IOException {
3131
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
3232
randomBoolean() ? "POST" : "PUT", "/idx/type/123"));
33-
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
34-
assertThat(responseException.getMessage(), containsString("request body is required"));
33+
assertResponseException(responseException, "request body is required");
3534
}
3635

3736
public void testBulkMissingBody() throws IOException {
3837
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
3938
randomBoolean() ? "POST" : "PUT", "/_bulk"));
40-
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
41-
assertThat(responseException.getMessage(), containsString("request body is required"));
39+
assertResponseException(responseException, "request body is required");
4240
}
4341

4442
public void testPutSettingsMissingBody() throws IOException {
4543
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
4644
"PUT", "/_settings"));
47-
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
48-
assertThat(responseException.getMessage(), containsString("request body is required"));
45+
assertResponseException(responseException, "request body is required");
4946
}
5047

5148
public void testPutMappingsMissingBody() throws IOException {
5249
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
5350
randomBoolean() ? "POST" : "PUT", "/test_index/test_type/_mapping"));
54-
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
55-
assertThat(responseException.getMessage(), containsString("request body is required"));
51+
assertResponseException(responseException, "request body is required");
5652
}
5753

5854
public void testPutIndexTemplateMissingBody() throws IOException {
5955
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
6056
randomBoolean() ? "PUT" : "POST", "/_template/my_template"));
61-
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
62-
assertThat(responseException.getMessage(), containsString("request body is required"));
57+
assertResponseException(responseException, "request body is required");
6358
}
6459

6560
public void testMultiSearchMissingBody() throws IOException {
6661
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
6762
randomBoolean() ? "POST" : "GET", "/_msearch"));
68-
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
69-
assertThat(responseException.getMessage(), containsString("request body or source parameter is required"));
63+
assertResponseException(responseException, "request body or source parameter is required");
7064
}
7165

7266
public void testPutPipelineMissingBody() throws IOException {
7367
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
7468
"PUT", "/_ingest/pipeline/my_pipeline"));
75-
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
76-
assertThat(responseException.getMessage(), containsString("request body or source parameter is required"));
69+
assertResponseException(responseException, "request body or source parameter is required");
7770
}
7871

7972
public void testSimulatePipelineMissingBody() throws IOException {
8073
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
8174
randomBoolean() ? "POST" : "GET", "/_ingest/pipeline/my_pipeline/_simulate"));
82-
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
83-
assertThat(responseException.getMessage(), containsString("request body or source parameter is required"));
75+
assertResponseException(responseException, "request body or source parameter is required");
8476
}
8577

8678
public void testPutScriptMissingBody() throws IOException {
8779
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest(
8880
randomBoolean() ? "POST" : "PUT", "/_scripts/lang"));
81+
assertResponseException(responseException, "request body is required");
82+
}
83+
84+
private static void assertResponseException(ResponseException responseException, String message) {
8985
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode());
90-
assertThat(responseException.getMessage(), containsString("request body is required"));
86+
assertThat(responseException.getMessage(), containsString(message));
9187
}
9288
}

0 commit comments

Comments
 (0)