Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package org.wuspba.ctams.ws; import org.wuspba.ctams.util.IntegrationTestUtils; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URI; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import static org.junit.Assert.*; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author atrimble */ public class ITDeployment { private static final Logger LOG = LoggerFactory.getLogger(ITDeployment.class); protected static String PROTOCOL = "http"; protected static String HOST = "localhost"; protected static int PORT = 8081; protected static String PATH = "/test"; static { if (System.getProperties().containsKey("ctams.protocol")) { PROTOCOL = System.getProperty("ctams.protocol"); } if (System.getProperties().containsKey("ctams.host")) { HOST = System.getProperty("ctams.host"); } if (System.getProperties().containsKey("ctams.port")) { PORT = Integer.parseInt(System.getProperty("ctams.port")); } if (System.getProperties().containsKey("ctams.uri")) { PATH = System.getProperty("ctams.uri") + PATH; } } @Test public void testActive() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme("http").setHost(HOST).setPort(PORT).setPath(PATH).build(); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); String buff; try (BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent()))) { buff = in.readLine(); while (buff != null) { assertEquals(buff, TestController.TEST_STRING); buff = in.readLine(); } } EntityUtils.consume(entity); } } }