2020package org .elasticsearch .client ;
2121
2222import com .fasterxml .jackson .core .JsonParseException ;
23+
2324import org .apache .http .Header ;
2425import org .apache .http .HttpEntity ;
2526import org .apache .http .HttpHost ;
3334import org .apache .http .message .BasicHttpResponse ;
3435import org .apache .http .message .BasicRequestLine ;
3536import org .apache .http .message .BasicStatusLine ;
37+ import org .elasticsearch .Build ;
3638import org .elasticsearch .ElasticsearchException ;
39+ import org .elasticsearch .Version ;
3740import org .elasticsearch .action .ActionListener ;
3841import org .elasticsearch .action .ActionRequest ;
3942import org .elasticsearch .action .ActionRequestValidationException ;
4043import org .elasticsearch .action .main .MainRequest ;
44+ import org .elasticsearch .action .main .MainResponse ;
45+ import org .elasticsearch .cluster .ClusterName ;
4146import org .elasticsearch .common .CheckedFunction ;
4247import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
4348import org .elasticsearch .common .xcontent .XContentBuilder ;
4449import org .elasticsearch .common .xcontent .XContentParser ;
50+ import org .elasticsearch .common .xcontent .XContentType ;
4551import org .elasticsearch .common .xcontent .cbor .CborXContent ;
4652import org .elasticsearch .common .xcontent .smile .SmileXContent ;
4753import org .elasticsearch .rest .RestStatus ;
5965import java .util .concurrent .atomic .AtomicInteger ;
6066import java .util .concurrent .atomic .AtomicReference ;
6167
68+ import static org .elasticsearch .common .xcontent .XContentHelper .toXContent ;
6269import static org .hamcrest .CoreMatchers .instanceOf ;
6370import static org .mockito .Matchers .anyMapOf ;
6471import static org .mockito .Matchers .anyObject ;
@@ -79,7 +86,7 @@ public class RestHighLevelClientTests extends ESTestCase {
7986 private RestHighLevelClient restHighLevelClient ;
8087
8188 @ Before
82- public void initClient () throws IOException {
89+ public void initClient () {
8390 restClient = mock (RestClient .class );
8491 restHighLevelClient = new RestHighLevelClient (restClient );
8592 }
@@ -115,6 +122,21 @@ public void testPingSocketTimeout() throws IOException {
115122 Matchers .isNull (HttpEntity .class ), argThat (new HeadersVarargMatcher (headers )));
116123 }
117124
125+ public void testInfo () throws IOException {
126+ Header [] headers = RestClientTestUtil .randomHeaders (random (), "Header" );
127+ Response response = mock (Response .class );
128+ MainResponse testInfo = new MainResponse ("nodeName" , Version .CURRENT , new ClusterName ("clusterName" ), "clusterUuid" ,
129+ Build .CURRENT , true );
130+ when (response .getEntity ()).thenReturn (
131+ new StringEntity (toXContent (testInfo , XContentType .JSON , false ).utf8ToString (), ContentType .APPLICATION_JSON ));
132+ when (restClient .performRequest (anyString (), anyString (), anyMapOf (String .class , String .class ),
133+ anyObject (), anyVararg ())).thenReturn (response );
134+ MainResponse receivedInfo = restHighLevelClient .info (headers );
135+ assertEquals (testInfo , receivedInfo );
136+ verify (restClient ).performRequest (eq ("GET" ), eq ("/" ), eq (Collections .emptyMap ()),
137+ Matchers .isNull (HttpEntity .class ), argThat (new HeadersVarargMatcher (headers )));
138+ }
139+
118140 public void testRequestValidation () {
119141 ActionRequestValidationException validationException = new ActionRequestValidationException ();
120142 validationException .addValidationError ("validation error" );
@@ -388,7 +410,7 @@ public void testPerformRequestOnResponseExceptionWithIgnoresErrorValidBody() thr
388410 assertEquals ("Elasticsearch exception [type=exception, reason=test error message]" , elasticsearchException .getMessage ());
389411 }
390412
391- public void testWrapResponseListenerOnSuccess () throws IOException {
413+ public void testWrapResponseListenerOnSuccess () {
392414 {
393415 TrackingActionListener trackingActionListener = new TrackingActionListener ();
394416 ResponseListener responseListener = restHighLevelClient .wrapResponseListener (
@@ -414,7 +436,7 @@ public void testWrapResponseListenerOnSuccess() throws IOException {
414436 }
415437 }
416438
417- public void testWrapResponseListenerOnException () throws IOException {
439+ public void testWrapResponseListenerOnException () {
418440 TrackingActionListener trackingActionListener = new TrackingActionListener ();
419441 ResponseListener responseListener = restHighLevelClient .wrapResponseListener (
420442 response -> response .getStatusLine ().getStatusCode (), trackingActionListener , Collections .emptySet ());
@@ -543,7 +565,7 @@ public void testWrapResponseListenerOnResponseExceptionWithIgnoresErrorValidBody
543565 assertEquals ("Elasticsearch exception [type=exception, reason=test error message]" , elasticsearchException .getMessage ());
544566 }
545567
546- public void testNamedXContents () throws IOException {
568+ public void testNamedXContents () {
547569 List <NamedXContentRegistry .Entry > namedXContents = RestHighLevelClient .getNamedXContents ();
548570 assertEquals (0 , namedXContents .size ());
549571 }
0 commit comments