use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method validationExceptionsAreReturnedAsErrorMessages.
@Test
public void validationExceptionsAreReturnedAsErrorMessages() throws Exception {
MockHttpServletRequestBuilder request = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\":\"" + CREDENTIAL_NAME + "\"," + "\"type\":\"" + parametizer.credentialType + "\"," + "\"value\":" + parametizer.credentialValue + "," + "\"overwrite\":" + false + "," + "\"additional_permissions\": [" + "{\"actor\": \"app1-guid\"," + "\"operations\": [\"read\"]}]" + "}");
BaseCredentialSetRequest requestObject = mock(BaseCredentialSetRequest.class);
doThrow(new ParameterizedValidationException("error.bad_request")).when(requestObject).validate();
doReturn(requestObject).when(objectMapper).readValue(any(InputStream.class), any(JavaType.class));
mockMvc.perform(request).andExpect(status().isBadRequest()).andExpect(content().json("{\"error\":\"The request could not be fulfilled because the request path or body did not meet expectation. Please check the documentation for required formatting and retry your request.\"}"));
}
use of org.cloudfoundry.credhub.exceptions.ParameterizedValidationException in project credhub by cloudfoundry-incubator.
the class CertificateAuthorityServiceTest method findActiveVersion_whenCertificateIsNotACa_throwsException.
@Test
public void findActiveVersion_whenCertificateIsNotACa_throwsException() {
CertificateCredentialVersion notACertificateAuthority = mock(CertificateCredentialVersion.class);
when(notACertificateAuthority.getParsedCertificate()).thenReturn(mock(CertificateReader.class));
when(notACertificateAuthority.getCertificate()).thenReturn(CertificateStringConstants.SIMPLE_SELF_SIGNED_TEST_CERT);
when(certificateVersionDataService.findActive(CREDENTIAL_NAME)).thenReturn(notACertificateAuthority);
try {
certificateAuthorityService.findActiveVersion(CREDENTIAL_NAME);
} catch (ParameterizedValidationException pe) {
assertThat(pe.getMessage(), equalTo("error.cert_not_ca"));
}
}
Aggregations