HttpCertSigner implements CertSigner { @Override public String getCACertificate() { ContentResponse response; try { response = httpClient.GET(x509CertUri); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOGGER.error("getCACertificate: unable to fetch requested uri '" + x509CertUri + "': " + e.getMessage()); return null; } if (response.getStatus() != HttpStatus.OK_200) { LOGGER.error("getCACertificate: unable to fetch requested uri '" + x509CertUri + "' status: " + response.getStatus()); return null; } String data = response.getContentAsString(); if (data == null || data.isEmpty()) { LOGGER.error("getCACertificate: received empty response from uri '" + x509CertUri + "' status: " + response.getStatus()); return null; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("getCACertificate: CA Certificate" + data); } X509CertSignObject pemCert = JSON.fromString(data, X509CertSignObject.class); return (pemCert != null) ? pemCert.getPem() : null; } HttpCertSigner(); @Override void close(); @Override int getMaxCertExpiryTimeMins(); @Override String generateX509Certificate(String csr, String keyUsage, int expireMins); @Override String getCACertificate();  }
@Test public void testGetCACertificate() throws Exception { HttpClient httpClient = Mockito.mock(HttpClient.class); HttpCertSignerFactory certFactory = new HttpCertSignerFactory(); HttpCertSigner certSigner = (HttpCertSigner) certFactory.create(); certSigner.setHttpClient(httpClient); ContentResponse response = Mockito.mock(ContentResponse.class); Mockito.when(httpClient.GET("https: Mockito.when(response.getStatus()).thenReturn(200); Mockito.when(response.getContentAsString()).thenReturn("{\"pem\": \"pem-value\"}"); String pem = certSigner.getCACertificate(); assertEquals(pem, "pem-value"); certSigner.close(); }