HttpCertSigner implements CertSigner { void setupHttpClient(HttpClient client, long requestTimeout, long connectTimeout) { client.setFollowRedirects(false); client.setConnectTimeout(connectTimeout); client.setStopTimeout(TimeUnit.MILLISECONDS.convert(requestTimeout, TimeUnit.SECONDS)); try { client.start(); } catch (Exception ex) { LOGGER.error("HttpCertSigner: unable to start http client", ex); throw new ResourceException(ResourceException.INTERNAL_SERVER_ERROR, "Http client not available"); } } HttpCertSigner(); @Override void close(); @Override int getMaxCertExpiryTimeMins(); @Override String generateX509Certificate(String csr, String keyUsage, int expireMins); @Override String getCACertificate();  }
@Test public void testSetupHttpClient() throws Exception { HttpCertSignerFactory certFactory = new HttpCertSignerFactory(); HttpCertSigner certSigner = (HttpCertSigner) certFactory.create(); HttpClient client = Mockito.mock(HttpClient.class); Mockito.doThrow(new Exception("Invalid client")).when(client).start(); try { certSigner.setupHttpClient(client, 120, 120); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), 500); } }