public CustomerDTO customer(final long customerId) { final Customer customer = customerService.customer(Customer.Id.of(customerId)); return CustomerDTOFactory.customer(customer); }
public static CustomerDTO customerDTO() { return CustomerDTOFactory.customer(customer()); }
@Test public void shouldCreateCustomer() throws Exception { final CustomerDTO customerDTO = CustomerDTOFactory.customer(customer()); customerAdapter.create(customerDTO); verify(customerEditService, times(1)).create(CustomerFactory.customer(customerDTO)); }
@Test public void shouldUpdateCustomer() throws Exception { final CustomerDTO customerDTO = CustomerDTOFactory.customer(customer()); customerAdapter.update(customerDTO); verify(customerEditService, times(1)).update(CustomerFactory.customer(customerDTO)); }
@Test public void shouldCreateCustomer() throws Exception { final ObjectMapper mapper = new ObjectMapper(); final CustomerDTO customerDTO = CustomerDTOFactory.customer(customer()); final String json = mapper.writeValueAsString(customerDTO); final ResultActions result = mvc.perform(post(API_CUSTOMERS_PATH).contentType(MediaTypes.APPLICATION_JSON_V1) .accept(MediaTypes.APPLICATION_JSON_V1) .content(json)) .andExpect(status().isCreated()); final String locationHeader = result.andReturn().getResponse().getHeader("Location"); assertThat(locationHeader).isNotBlank(); assertThat(locationHeader).endsWith(API_CUSTOMERS_PATH); }
@Test public void shouldUpdateCustomer() throws Exception { final ObjectMapper mapper = new ObjectMapper(); final CustomerDTO customerDTO = CustomerDTOFactory.customer(customer()); final String json = mapper.writeValueAsString(customerDTO); final String uri = API_CUSTOMERS_PATH + "/123"; final ResultActions result = mvc.perform(put(uri).contentType(MediaTypes.APPLICATION_JSON_V1) .accept(MediaTypes.APPLICATION_JSON_V1) .content(json)) .andExpect(status().isOk()); final String locationHeader = result.andReturn().getResponse().getHeader("Location"); assertThat(locationHeader).isNotBlank(); assertThat(locationHeader).endsWith(API_CUSTOMERS_PATH); }