5
5
*/
6
6
package org .elasticsearch .license ;
7
7
8
+ import org .elasticsearch .client .Request ;
8
9
import org .elasticsearch .client .Response ;
9
10
import org .elasticsearch .client .ResponseException ;
10
11
import org .elasticsearch .client .RestClient ;
@@ -51,13 +52,13 @@ public void testStartTrial() throws Exception {
51
52
ensureStartingWithBasic ();
52
53
53
54
RestClient restClient = getRestClient ();
54
- Response response = restClient .performRequest ("GET" , "/_xpack/license/trial_status" );
55
+ Response response = restClient .performRequest (new Request ( "GET" , "/_xpack/license/trial_status" ) );
55
56
String body = Streams .copyToString (new InputStreamReader (response .getEntity ().getContent (), StandardCharsets .UTF_8 ));
56
57
assertEquals (200 , response .getStatusLine ().getStatusCode ());
57
58
assertEquals ("{\" eligible_to_start_trial\" :true}" , body );
58
59
59
60
// Test that starting will fail without acknowledgement
60
- Response response2 = restClient .performRequest ("POST" , "/_xpack/license/start_trial" );
61
+ Response response2 = restClient .performRequest (new Request ( "POST" , "/_xpack/license/start_trial" ) );
61
62
String body2 = Streams .copyToString (new InputStreamReader (response2 .getEntity ().getContent (), StandardCharsets .UTF_8 ));
62
63
assertEquals (200 , response2 .getStatusLine ().getStatusCode ());
63
64
assertTrue (body2 .contains ("\" trial_was_started\" :false" ));
@@ -71,7 +72,10 @@ public void testStartTrial() throws Exception {
71
72
72
73
String type = randomFrom (LicenseService .VALID_TRIAL_TYPES );
73
74
74
- Response response3 = restClient .performRequest ("POST" , "/_xpack/license/start_trial?acknowledge=true&type=" + type );
75
+ Request ackRequest = new Request ("POST" , "/_xpack/license/start_trial" );
76
+ ackRequest .addParameter ("acknowledge" , "true" );
77
+ ackRequest .addParameter ("type" , type );
78
+ Response response3 = restClient .performRequest (ackRequest );
75
79
String body3 = Streams .copyToString (new InputStreamReader (response3 .getEntity ().getContent (), StandardCharsets .UTF_8 ));
76
80
assertEquals (200 , response3 .getStatusLine ().getStatusCode ());
77
81
assertTrue (body3 .contains ("\" trial_was_started\" :true" ));
@@ -83,15 +87,17 @@ public void testStartTrial() throws Exception {
83
87
assertEquals (type , postTrialLicenseResponse .license ().type ());
84
88
});
85
89
86
- Response response4 = restClient .performRequest ("GET" , "/_xpack/license/trial_status" );
90
+ Response response4 = restClient .performRequest (new Request ( "GET" , "/_xpack/license/trial_status" ) );
87
91
String body4 = Streams .copyToString (new InputStreamReader (response4 .getEntity ().getContent (), StandardCharsets .UTF_8 ));
88
92
assertEquals (200 , response4 .getStatusLine ().getStatusCode ());
89
93
assertEquals ("{\" eligible_to_start_trial\" :false}" , body4 );
90
94
91
95
String secondAttemptType = randomFrom (LicenseService .VALID_TRIAL_TYPES );
92
96
93
- ResponseException ex = expectThrows (ResponseException .class ,
94
- () -> restClient .performRequest ("POST" , "/_xpack/license/start_trial?acknowledge=true&type=" + secondAttemptType ));
97
+ Request startTrialWhenStartedRequest = new Request ("POST" , "/_xpack/license/start_trial" );
98
+ startTrialWhenStartedRequest .addParameter ("acknowledge" , "true" );
99
+ startTrialWhenStartedRequest .addParameter ("type" , secondAttemptType );
100
+ ResponseException ex = expectThrows (ResponseException .class , () -> restClient .performRequest (startTrialWhenStartedRequest ));
95
101
Response response5 = ex .getResponse ();
96
102
String body5 = Streams .copyToString (new InputStreamReader (response5 .getEntity ().getContent (), StandardCharsets .UTF_8 ));
97
103
assertEquals (403 , response5 .getStatusLine ().getStatusCode ());
@@ -102,8 +108,9 @@ public void testStartTrial() throws Exception {
102
108
public void testInvalidType () throws Exception {
103
109
ensureStartingWithBasic ();
104
110
105
- ResponseException ex = expectThrows (ResponseException .class , () ->
106
- getRestClient ().performRequest ("POST" , "/_xpack/license/start_trial?type=basic" ));
111
+ Request request = new Request ("POST" , "/_xpack/license/start_trial" );
112
+ request .addParameter ("type" , "basic" );
113
+ ResponseException ex = expectThrows (ResponseException .class , () -> getRestClient ().performRequest (request ));
107
114
Response response = ex .getResponse ();
108
115
String body = Streams .copyToString (new InputStreamReader (response .getEntity ().getContent (), StandardCharsets .UTF_8 ));
109
116
assertEquals (400 , response .getStatusLine ().getStatusCode ());
0 commit comments