@Test
public void whenTheCADoesNotHaveAPrivateKey_itThrowsAnException() throws Exception {

  final CertificateGenerationRequestParameters parameters = new CertificateGenerationRequestParameters();
  parameters.setCaName("/ca-without-private-key");
  parameters.setKeyLength(2048);
  parameters.setSelfSigned(false);
  final CertificateCredentialValue caWithoutPrivateKey = mock(CertificateCredentialValue.class);
  when(certificateAuthorityService.findActiveVersion("/ca-without-private-key"))
    .thenReturn(caWithoutPrivateKey);
  when(caWithoutPrivateKey.getPrivateKey()).thenReturn(null);
  when(keyGenerator.generateKeyPair(anyInt())).thenReturn(rootCaKeyPair);
  try {
    subject.generateCredential(new CertificateGenerationParameters(parameters));
    fail("Should throw exception");
  } catch (final ParameterizedValidationException e) {
    assertThat(e.getMessage(), equalTo(ErrorMessages.CA_MISSING_PRIVATE_KEY));
  }
}