package com.ibm.liberty.starter.availability;

import static org.junit.Assert.assertTrue;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;

import org.junit.Test;

public class EndpointAvailabilityTest {
	
    private String port = System.getProperty("liberty.test.port");
    private String url = "http://localhost:" + port + "/start/";

    @Test
    public void testEndpoint() throws Exception {
        System.out.println("Testing endpoint " + url);
        int maxCount = 30;
        int responseCode = makeRequest();
        for(int i = 0; (responseCode != 200) && (i < maxCount); i++) {
          System.out.println("Response code : " + responseCode + ", retrying ... (" + i + " of " + maxCount + ")");
          Thread.sleep(5000);
          responseCode = makeRequest();
        }
        assertTrue("Incorrect response code: " + responseCode, responseCode == 200);
    }

    private int makeRequest() {
      Client client = ClientBuilder.newClient();
      Invocation.Builder invoBuild = client.target(url).request();
      Response response = invoBuild.get();
      int responseCode = response.getStatus();
      response.close();
      return responseCode;
    }
}

@@ -369,73 +369,625 @@
 %22);%0A
-    private String url = %22http://localhost:%22 + port + %22/start/%22;%0A
+%0A    @Test%0A    public void testLocalHostEndpoint() throws Exception %7B%0A        String url = %22http://localhost:%22 + port + %22/%22;%0A        System.out.println(%22Testing endpoint %22 + url);%0A        int maxCount = 30;%0A        int responseCode = makeRequest(url);%0A        for(int i = 0; (responseCode != 200) && (i %3C maxCount); i++) %7B%0A          System.out.println(%22Response code : %22 + responseCode + %22, retrying ... (%22 + i + %22 of %22 + maxCount + %22)%22);%0A          Thread.sleep(5000);%0A          responseCode = makeRequest(url);%0A        %7D%0A        assertTrue(%22Incorrect response code: %22 + responseCode, responseCode == 200);%0A    %7D%0A    
 %0A   
@@ -1035,32 +1035,84 @@
 ows Exception %7B%0A
+    %09String url = %22http://172.0.0.1:%22 + port + %22/%22;%0A
         System.o
@@ -1208,32 +1208,35 @@
 e = makeRequest(
+url
 );%0A        for(i
@@ -1472,24 +1472,646 @@
 makeRequest(
+url);%0A        %7D%0A        assertTrue(%22Incorrect response code: %22 + responseCode, responseCode == 200);%0A    %7D%0A    %0A    @Test%0A    public void testStartEndpoint() throws Exception %7B%0A        String url = %22http://localhost:%22 + port + %22/start/%22;%0A        System.out.println(%22Testing endpoint %22 + url);%0A        int maxCount = 30;%0A        int responseCode = makeRequest(url);%0A        for(int i = 0; (responseCode != 200) && (i %3C maxCount); i++) %7B%0A          System.out.println(%22Response code : %22 + responseCode + %22, retrying ... (%22 + i + %22 of %22 + maxCount + %22)%22);%0A          Thread.sleep(5000);%0A          responseCode = makeRequest(url
 );%0A        %7D
@@ -2231,16 +2231,26 @@
 Request(
+String url
 ) %7B%0A    

Add extra tests.