/** Create a URL suitable for rest-assured's post(), get() e.al. methods. */ public String host(String path) { return UrlSupport.url(baseUrl, path).toString(); }
/** * Return a localhost base URL with a random port between 8081 and 9000. The method features a port usage detection to * ensure it returns a free port. */ public static URL localhostRandomPort() { for (int tries = 100; tries > 0; tries--) { final URL url = UrlSupport.url("http", "localhost", 8081 + new Random(System.currentTimeMillis()).nextInt(919)); try { final URLConnection con = url.openConnection(); con.setConnectTimeout(1000); con.setReadTimeout(1000); con.getInputStream(); } catch (IOException e) { return url; } } throw new RuntimeException("Cannot find free port. Giving up."); }
public static RestServiceTestEnv testEnvForCustomConfig(String baseUrl, ResourceConfig cfg) { return new RestServiceTestEnv(UrlSupport.url(baseUrl), some(cfg)); }