Search in sources :

Example 1 with BaseCredentialSetRequest

use of org.cloudfoundry.credhub.request.BaseCredentialSetRequest 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.\"}"));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) InputStream(java.io.InputStream) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) BaseCredentialSetRequest(org.cloudfoundry.credhub.request.BaseCredentialSetRequest) ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)1 InputStream (java.io.InputStream)1 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)1 BaseCredentialSetRequest (org.cloudfoundry.credhub.request.BaseCredentialSetRequest)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1