void fetchUpdateCheckHeaders(DownloadableFile downloadableFile) throws Exception { String url = downloadableFile.validatedUrl(urlGenerator); final HttpRequestBase request = new HttpHead(url); request.setConfig(RequestConfig.custom().setConnectTimeout(HTTP_TIMEOUT_IN_MILLISECONDS).build()); try ( CloseableHttpClient httpClient = httpClientBuilder.build(); CloseableHttpResponse response = httpClient.execute(request) ) { handleInvalidResponse(response, url); this.md5 = response.getFirstHeader(MD5_HEADER).getValue(); this.sslPort = response.getFirstHeader(SSL_PORT_HEADER).getValue(); this.extraProperties = HeaderUtil.parseExtraProperties(response.getFirstHeader(AGENT_EXTRA_PROPERTIES_HEADER)); } }
@Test public void shouldThrowExceptionIfUrlIsInvalid() throws Exception { ServerUrlGenerator serverUrlGenerator = mock(ServerUrlGenerator.class); when(serverUrlGenerator.serverUrlFor("admin/agent")).thenReturn("invalidUrl"); exception.expect(RuntimeException.class); exception.expectMessage("URL you provided to access Go Server: " + "invalidUrl" + " is not valid"); DownloadableFile.AGENT.validatedUrl(serverUrlGenerator); } }
@Test public void shouldValidateTheUrl() throws Exception { ServerUrlGenerator serverUrlGenerator = ServerUrlGeneratorMother.generatorFor("localhost", 9090); assertThat(DownloadableFile.AGENT.validatedUrl(serverUrlGenerator), is("http://localhost:9090/go/admin/agent")); }