@@ -30,63 +30,59 @@ public class RequestsWithoutContentIT extends ESRestTestCase {
30
30
public void testIndexMissingBody () throws IOException {
31
31
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
32
32
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" );
35
34
}
36
35
37
36
public void testBulkMissingBody () throws IOException {
38
37
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
39
38
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" );
42
40
}
43
41
44
42
public void testPutSettingsMissingBody () throws IOException {
45
43
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
46
44
"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" );
49
46
}
50
47
51
48
public void testPutMappingsMissingBody () throws IOException {
52
49
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
53
50
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" );
56
52
}
57
53
58
54
public void testPutIndexTemplateMissingBody () throws IOException {
59
55
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
60
56
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" );
63
58
}
64
59
65
60
public void testMultiSearchMissingBody () throws IOException {
66
61
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
67
62
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" );
70
64
}
71
65
72
66
public void testPutPipelineMissingBody () throws IOException {
73
67
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
74
68
"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" );
77
70
}
78
71
79
72
public void testSimulatePipelineMissingBody () throws IOException {
80
73
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
81
74
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" );
84
76
}
85
77
86
78
public void testPutScriptMissingBody () throws IOException {
87
79
ResponseException responseException = expectThrows (ResponseException .class , () -> client ().performRequest (
88
80
randomBoolean () ? "POST" : "PUT" , "/_scripts/lang" ));
81
+ assertResponseException (responseException , "request body is required" );
82
+ }
83
+
84
+ private static void assertResponseException (ResponseException responseException , String message ) {
89
85
assertEquals (400 , responseException .getResponse ().getStatusLine ().getStatusCode ());
90
- assertThat (responseException .getMessage (), containsString ("request body is required" ));
86
+ assertThat (responseException .getMessage (), containsString (message ));
91
87
}
92
88
}
0 commit comments