2828import org .mockito .Mockito ;
2929
3030import static org .junit .Assert .assertEquals ;
31+ import static org .junit .Assert .assertNotNull ;
32+ import static org .junit .Assert .assertNull ;
3133import static org .junit .Assert .fail ;
3234
3335public class RestClientTest {
@@ -241,4 +243,50 @@ public void testCount7xBadRelation() throws Exception {
241243
242244 assertEquals (5L , count );
243245 }
246+
247+ @ Test
248+ public void testMainInfoWithClusterNotProvidingUUID () {
249+ String response = "{\n " +
250+ "\" name\" : \" node\" ,\n " +
251+ "\" cluster_name\" : \" cluster\" ,\n " +
252+ "\" version\" : {\n " +
253+ " \" number\" : \" 2.0.1\" \n " +
254+ "},\n " +
255+ "\" tagline\" : \" You Know, for Search\" \n " +
256+ "}" ;
257+
258+ NetworkClient mock = Mockito .mock (NetworkClient .class );
259+ Mockito .when (mock .execute (Mockito .any (SimpleRequest .class ))).thenReturn (new SimpleResponse (201 , new FastByteArrayInputStream (new BytesArray (response )), "localhost:9200" ));
260+
261+ RestClient client = new RestClient (new TestSettings (), mock );
262+
263+ ClusterInfo clusterInfo = client .mainInfo ();
264+
265+ assertNotNull (clusterInfo .getClusterName ());
266+ assertNull (clusterInfo .getClusterName ().getUUID ());
267+ }
268+
269+ @ Test
270+ public void testMainInfoWithClusterProvidingUUID () {
271+ String response = "{\n " +
272+ "\" name\" : \" node\" ,\n " +
273+ "\" cluster_name\" : \" cluster\" ,\n " +
274+ "\" cluster_uuid\" : \" uuid\" ,\n " +
275+ "\" version\" : {\n " +
276+ " \" number\" : \" 6.7.0\" \n " +
277+ "},\n " +
278+ "\" tagline\" : \" You Know, for Search\" \n " +
279+ "}" ;
280+
281+ NetworkClient mock = Mockito .mock (NetworkClient .class );
282+ Mockito .when (mock .execute (Mockito .any (SimpleRequest .class ))).thenReturn (new SimpleResponse (201 , new FastByteArrayInputStream (new BytesArray (response )), "localhost:9200" ));
283+
284+ RestClient client = new RestClient (new TestSettings (), mock );
285+
286+ ClusterInfo clusterInfo = client .mainInfo ();
287+
288+ assertNotNull (clusterInfo .getClusterName ());
289+ assertEquals ("uuid" , clusterInfo .getClusterName ().getUUID ());
290+ }
291+
244292}
0 commit comments