3030import org .mockito .Mockito ;
3131
3232import static org .junit .Assert .assertEquals ;
33+ import static org .junit .Assert .assertNotNull ;
34+ import static org .junit .Assert .assertNull ;
3335import static org .junit .Assert .fail ;
3436
3537public class RestClientTest {
@@ -406,4 +408,50 @@ public void testCount7xBadRelation() throws Exception {
406408
407409 assertEquals (5L , count );
408410 }
411+
412+ @ Test
413+ public void testMainInfoWithClusterNotProvidingUUID () {
414+ String response = "{\n " +
415+ "\" name\" : \" node\" ,\n " +
416+ "\" cluster_name\" : \" cluster\" ,\n " +
417+ "\" version\" : {\n " +
418+ " \" number\" : \" 2.0.1\" \n " +
419+ "},\n " +
420+ "\" tagline\" : \" You Know, for Search\" \n " +
421+ "}" ;
422+
423+ NetworkClient mock = Mockito .mock (NetworkClient .class );
424+ Mockito .when (mock .execute (Mockito .any (SimpleRequest .class ))).thenReturn (new SimpleResponse (201 , new FastByteArrayInputStream (new BytesArray (response )), "localhost:9200" ));
425+
426+ RestClient client = new RestClient (new TestSettings (), mock );
427+
428+ ClusterInfo clusterInfo = client .mainInfo ();
429+
430+ assertNotNull (clusterInfo .getClusterName ());
431+ assertNull (clusterInfo .getClusterName ().getUUID ());
432+ }
433+
434+ @ Test
435+ public void testMainInfoWithClusterProvidingUUID () {
436+ String response = "{\n " +
437+ "\" name\" : \" node\" ,\n " +
438+ "\" cluster_name\" : \" cluster\" ,\n " +
439+ "\" cluster_uuid\" : \" uuid\" ,\n " +
440+ "\" version\" : {\n " +
441+ " \" number\" : \" 6.7.0\" \n " +
442+ "},\n " +
443+ "\" tagline\" : \" You Know, for Search\" \n " +
444+ "}" ;
445+
446+ NetworkClient mock = Mockito .mock (NetworkClient .class );
447+ Mockito .when (mock .execute (Mockito .any (SimpleRequest .class ))).thenReturn (new SimpleResponse (201 , new FastByteArrayInputStream (new BytesArray (response )), "localhost:9200" ));
448+
449+ RestClient client = new RestClient (new TestSettings (), mock );
450+
451+ ClusterInfo clusterInfo = client .mainInfo ();
452+
453+ assertNotNull (clusterInfo .getClusterName ());
454+ assertEquals ("uuid" , clusterInfo .getClusterName ().getUUID ());
455+ }
456+
409457}
0 commit comments