use of com.github.wenqiglantz.service.customerservice.data.CustomerInfo in project customer-service by wenqiglantz.
the class CustomerServiceTest method getCustomers.
@Test
public void getCustomers() {
Pageable pageable = PageRequest.of(0, 20, Sort.by("firstName"));
context.checking(new Expectations() {
{
oneOf(customerRepository).findAll(pageable);
will(returnValue(new PageImpl<>(Collections.singletonList(CUSTOMER))));
}
});
CustomerService customerService = new CustomerServiceImpl(customerRepository);
Page<CustomerInfo> customerInfos = customerService.getCustomers(pageable);
assertThat(customerInfos.getTotalElements(), is(equalTo(1L)));
}
use of com.github.wenqiglantz.service.customerservice.data.CustomerInfo in project customer-service by wenqiglantz.
the class CustomerServiceTest method getCustomer.
@Test
public void getCustomer() {
context.checking(new Expectations() {
{
oneOf(customerRepository).findByCustomerId(CUSTOMER_ID);
will(returnValue(Optional.of(CUSTOMER)));
}
});
CustomerService customerService = new CustomerServiceImpl(customerRepository);
CustomerInfo customerInfo = customerService.getCustomer(CUSTOMER_ID);
assertThat(customerInfo.getFirstName(), is(equalTo(CUSTOMER.getFirstName())));
}
use of com.github.wenqiglantz.service.customerservice.data.CustomerInfo in project customer-service by wenqiglantz.
the class CustomerController method createCustomer.
@Operation(summary = "Create customer")
@ApiResponses(value = { @ApiResponse(responseCode = "201", description = "Successfully created a customer"), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "401", description = "Authorization denied"), @ApiResponse(responseCode = "500", description = "Unexpected system exception"), @ApiResponse(responseCode = "502", description = "An error has occurred with an upstream service") })
@PostMapping(consumes = JSON)
public ResponseEntity createCustomer(@Valid @RequestBody CustomerInfo customerInfo, UriComponentsBuilder uriBuilder) throws Exception {
CustomerInfo newCustomerInfo = customerService.saveCustomer(customerInfo);
URI location = uriBuilder.path("/customers/{customerId}").buildAndExpand(newCustomerInfo.getCustomerId()).toUri();
return ResponseEntity.created(location).contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_UTF8_VALUE)).body(Customer.builder().customerId(newCustomerInfo.getCustomerId()).firstName(newCustomerInfo.getFirstName()).lastName(newCustomerInfo.getLastName()).build());
}
use of com.github.wenqiglantz.service.customerservice.data.CustomerInfo in project customer-service by wenqiglantz.
the class CustomerEventsPublishPactVerificationTest method publishCustomerWasUpdated.
@PactVerifyProvider("valid CustomerWasUpdated from provider")
public String publishCustomerWasUpdated() throws Exception {
CustomerInfo customerInfo = CustomerInfo.builder().customerId("595eed0c-eff5-4278-90ad-b952f18dbee8").firstName("test123").lastName("last").build();
CustomerWasUpdated event = CustomerWasUpdated.builder().customerId("595eed0c-eff5-4278-90ad-b952f18dbee8").firstName("test123").lastName("last").status(CustomerStatus.UPDATED).build();
context.checking(new Expectations() {
{
oneOf(customerService).updateCustomer(customerInfo.getCustomerId(), customerInfo);
}
});
customerService.updateCustomer(customerInfo.getCustomerId(), customerInfo);
String eventString = objectMapper.writeValueAsString(event);
return eventString;
}
use of com.github.wenqiglantz.service.customerservice.data.CustomerInfo in project customer-service by wenqiglantz.
the class CustomerControllerTest method updateCustomer.
@Test
public void updateCustomer() throws Exception {
CustomerInfo customerInfoNew = CustomerInfo.builder().firstName(FIRST_NAME).lastName(LAST_NAME).build();
context.checking(new Expectations() {
{
oneOf(customerService).updateCustomer(CUSTOMER_ID, customerInfoNew);
}
});
CustomerController customerController = new CustomerController(customerService);
ResponseEntity responseEntity = customerController.updateCustomer(CUSTOMER_ID, customerInfoNew);
assertThat(responseEntity.getStatusCode(), is(equalTo(HttpStatus.NO_CONTENT)));
assertThat(responseEntity.getBody(), is(nullValue()));
}
Aggregations