package it.com.atlassian.stash.installer.host;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static com.atlassian.bitbucket.server.ApplicationState.FIRST_RUN;

public class StartupAfterInstallerTest {

    private static final String STATUS_ENDPOINT_URL = "http://localhost:7990/status";

    @Test(timeout = 300000)
    public void testStartup() throws Exception {
        String actualState = null;
        do {
            Thread.sleep(TimeUnit.SECONDS.toMillis(5));

            Response response = RestAssured.get(STATUS_ENDPOINT_URL);
            if (response.getStatusCode() == 200) {
                actualState = response.body()
                        .jsonPath()
                        .getString("state");
            }
        } while(!FIRST_RUN.toString().equals(actualState));
    }
}
