VersionUtil { public Optional<String> getCurrentVersion(String running, Proxy proxy, OtrosApplication otrosApplication) throws IOException { final String instanceUuid = otrosApplication.getConfiguration().getString(ConfKeys.UUID, ""); final String requestUrl = buildRequestUrl(running, instanceUuid); LOGGER.debug("Will use URL: {}", requestUrl); URL url = new URL(requestUrl); String page = IOUtils.toString(url.openConnection(proxy).getInputStream()); LOGGER.debug("Response from version server is:\n{}", page); ByteArrayInputStream bin = new ByteArrayInputStream(page.getBytes()); Properties p = new Properties(); p.load(bin); final Optional<String> s = validateResponse(p.getProperty("currentVersion")); LOGGER.info("Current version is: {}", s); return s; } VersionUtil();  VersionUtil(String currentVersionPageUrl); Optional<String> getCurrentVersion(String running, Proxy proxy, OtrosApplication otrosApplication); String getRunningVersion();  }
@Test public void testGetCurrentVersion() throws Exception { final WireMockServer wireMockServer = new WireMockServer(); wireMockServer .stubFor( get(urlMatching("/currentVersion.*")) .willReturn(aResponse() .withStatus(200) .withBody("currentVersion=1.2.3\n".getBytes())) ); wireMockServer.start(); final int port = wireMockServer.port(); final VersionUtil versionUtil = new VersionUtil("http: final OtrosApplication otrosApplication = new OtrosApplication(); otrosApplication.setConfiguration(new DataConfiguration(new BaseConfiguration())); otrosApplication.getConfiguration().setProperty(ConfKeys.UUID,"C9457787-AF59-4B9F-B4E8-FB75334EBEF8"); final Optional<String> currentVersion = versionUtil.getCurrentVersion("1.2.3", Proxy.NO_PROXY, otrosApplication); wireMockServer.stop(); assertEquals(currentVersion,Optional.of("1.2.3")); }