5
5
*/
6
6
package org .elasticsearch .xpack .ml .integration ;
7
7
8
- import org .apache .http .entity .ContentType ;
9
- import org .apache .http .entity .StringEntity ;
8
+ import org .elasticsearch .client .Request ;
10
9
import org .elasticsearch .client .ResponseException ;
11
10
import org .elasticsearch .common .Strings ;
12
11
import org .elasticsearch .common .xcontent .XContentBuilder ;
13
12
import org .elasticsearch .test .rest .ESRestTestCase ;
14
13
import org .elasticsearch .xpack .ml .MachineLearning ;
15
14
16
- import java .util .Collections ;
17
-
18
15
import static org .elasticsearch .common .xcontent .XContentFactory .jsonBuilder ;
19
16
import static org .hamcrest .Matchers .containsString ;
20
17
@@ -27,30 +24,40 @@ public class MlPluginDisabledIT extends ESRestTestCase {
27
24
public void testActionsFail () throws Exception {
28
25
XContentBuilder xContentBuilder = jsonBuilder ();
29
26
xContentBuilder .startObject ();
30
- xContentBuilder .field ("actions-fail-job" , "foo" );
31
- xContentBuilder .field ("description" , "Analysis of response time by airline" );
32
-
33
- xContentBuilder .startObject ("analysis_config" );
34
- xContentBuilder .field ("bucket_span" , "3600s" );
35
- xContentBuilder .startArray ("detectors" );
36
- xContentBuilder .startObject ();
37
- xContentBuilder .field ("function" , "metric" );
38
- xContentBuilder .field ("field_name" , "responsetime" );
39
- xContentBuilder .field ("by_field_name" , "airline" );
40
- xContentBuilder .endObject ();
41
- xContentBuilder .endArray ();
42
- xContentBuilder .endObject ();
43
-
44
- xContentBuilder .startObject ("data_description" );
45
- xContentBuilder .field ("format" , "xcontent" );
46
- xContentBuilder .field ("time_field" , "time" );
47
- xContentBuilder .field ("time_format" , "epoch" );
48
- xContentBuilder .endObject ();
27
+ {
28
+ xContentBuilder .field ("actions-fail-job" , "foo" );
29
+ xContentBuilder .field ("description" , "Analysis of response time by airline" );
30
+
31
+ xContentBuilder .startObject ("analysis_config" );
32
+ {
33
+ xContentBuilder .field ("bucket_span" , "3600s" );
34
+ xContentBuilder .startArray ("detectors" );
35
+ {
36
+ xContentBuilder .startObject ();
37
+ {
38
+ xContentBuilder .field ("function" , "metric" );
39
+ xContentBuilder .field ("field_name" , "responsetime" );
40
+ xContentBuilder .field ("by_field_name" , "airline" );
41
+ }
42
+ xContentBuilder .endObject ();
43
+ }
44
+ xContentBuilder .endArray ();
45
+ }
46
+ xContentBuilder .endObject ();
47
+
48
+ xContentBuilder .startObject ("data_description" );
49
+ {
50
+ xContentBuilder .field ("format" , "xcontent" );
51
+ xContentBuilder .field ("time_field" , "time" );
52
+ xContentBuilder .field ("time_format" , "epoch" );
53
+ }
54
+ xContentBuilder .endObject ();
55
+ }
49
56
xContentBuilder .endObject ();
50
57
51
- ResponseException exception = expectThrows ( ResponseException . class , () -> client (). performRequest ( "put" ,
52
- MachineLearning . BASE_PATH + "anomaly_detectors/foo" , Collections . emptyMap (),
53
- new StringEntity ( Strings . toString ( xContentBuilder ), ContentType . APPLICATION_JSON ) ));
58
+ Request request = new Request ( "PUT" , MachineLearning . BASE_PATH + "anomaly_detectors/foo" );
59
+ request . setJsonEntity ( Strings . toString ( xContentBuilder ));
60
+ ResponseException exception = expectThrows ( ResponseException . class , () -> client (). performRequest ( request ));
54
61
assertThat (exception .getMessage (), containsString ("no handler found for uri [/_xpack/ml/anomaly_detectors/foo] and method [PUT]" ));
55
62
}
56
63
}
0 commit comments