Search in sources :

Example 1 with DefaultCredentialGenerateRequest

use of org.cloudfoundry.credhub.request.DefaultCredentialGenerateRequest in project credhub by cloudfoundry-incubator.

the class CredentialsControllerTypeSpecificGenerateTest method generatingACredential_validatesTheRequestBody.

@Test
public void generatingACredential_validatesTheRequestBody() throws Exception {
    MockHttpServletRequestBuilder request = createGenerateNewCredentialRequest();
    DefaultCredentialGenerateRequest requestBody = mock(DefaultCredentialGenerateRequest.class);
    Mockito.doThrow(new ParameterizedValidationException("error.bad_request")).when(requestBody).validate();
    doReturn(requestBody).when(objectMapper).readValue(anyString(), any(Class.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 : DefaultCredentialGenerateRequest(org.cloudfoundry.credhub.request.DefaultCredentialGenerateRequest) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)1 DefaultCredentialGenerateRequest (org.cloudfoundry.credhub.request.DefaultCredentialGenerateRequest)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1