use of com.poc.restfulpoc.entities.Customer in project POC by rajadilipkolli.
the class CustomerController method updateCustomer.
/**
* Update customer with given customer id.
*
* @param customer the customer
* @param customerId a {@link java.lang.Long} object.
* @return a {@link org.springframework.http.ResponseEntity} object.
* @throws com.poc.restfulpoc.exception.EntityNotFoundException if any.
*/
@PutMapping(value = { "/customers/{customerId}" })
public ResponseEntity<Customer> updateCustomer(@RequestBody Customer customer, @PathVariable("customerId") Long customerId) throws EntityNotFoundException {
log.info("Updating Customer {}", customerId);
final Customer currentUser = customerService.getCustomer(customerId);
currentUser.setFirstName(customer.getFirstName());
currentUser.setLastName(customer.getLastName());
currentUser.setDateOfBirth(customer.getDateOfBirth());
currentUser.setAddress(customer.getAddress());
customerService.updateCustomer(currentUser);
return new ResponseEntity<>(currentUser, HttpStatus.OK);
}
use of com.poc.restfulpoc.entities.Customer in project POC by rajadilipkolli.
the class CustomerControllerITTest method testGetCustomerById.
@Test
public void testGetCustomerById() throws Exception {
final Long customerId = getCustomerIdByFirstName("Raja");
final ResponseEntity<Customer> response = template.getForEntity(String.format("%s%s", base, customerId), Customer.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().getContentType().toString()).isEqualTo(JSON_CONTENT_TYPE);
final Customer customer = response.getBody();
assertThat(customer.getFirstName()).isEqualTo("Raja");
assertThat(customer.getLastName()).isEqualTo("Kolli");
assertThat(customer.getDateOfBirth()).hasDayOfMonth(10).hasMonth(1).hasYear(1982);
assertThat(customer.getAddress().getStreet()).isEqualTo("High Street");
assertThat(customer.getAddress().getTown()).isEqualTo("Belfast");
assertThat(customer.getAddress().getCounty()).isEqualTo("India");
assertThat(customer.getAddress().getPostcode()).isEqualTo("BT893PY");
}
use of com.poc.restfulpoc.entities.Customer in project POC by rajadilipkolli.
the class CustomerControllerITTest method testRemoveCustomer.
@Test
public void testRemoveCustomer() throws Exception {
final Long customerId = getCustomerIdByFirstName("Raja");
final ResponseEntity<Customer> response = template.getForEntity(String.format("%s/%s", base, customerId), Customer.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().getContentType().toString()).isEqualTo(JSON_CONTENT_TYPE);
final Customer customer = response.getBody();
assertThat(customer.getFirstName()).isEqualTo("Raja");
assertThat(customer.getLastName()).isEqualTo("Kolli");
assertThat(customer.getDateOfBirth()).hasDayOfMonth(10).hasMonth(1).hasYear(1982);
assertThat(customer.getAddress().getStreet()).isEqualTo("High Street");
assertThat(customer.getAddress().getTown()).isEqualTo("Belfast");
assertThat(customer.getAddress().getCounty()).isEqualTo("India");
assertThat(customer.getAddress().getPostcode()).isEqualTo("BT893PY");
/* delete customer */
template.delete(String.format("%s/%s", base, customerId), Customer.class);
// Sleeping for 1 second so that JMS message is consumed
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
/* attempt to get customer and ensure we get a 404 */
final ResponseEntity<Customer> secondCallResponse = template.getForEntity(String.format("%s/%s", base, customerId), Customer.class);
assertThat(secondCallResponse.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
use of com.poc.restfulpoc.entities.Customer in project POC by rajadilipkolli.
the class CXFRSServiceImplTest method testGetCustomers.
@Test
@DisplayName("Test Customers")
void testGetCustomers() throws Exception {
final WebClient wc = WebClient.create("http://localhost:" + port + API_PATH);
wc.accept("application/json");
wc.path("/customers/");
Response response = wc.get(Response.class);
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
final List<Customer> custList = convertJsonToCustomers(replyString);
assertThat(custList).isNotEmpty().size().isGreaterThan(1);
// Reverse to the starting URI
wc.back(true);
wc.path("/customers/").path(custList.get(0).getId());
response = wc.get(Response.class);
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
replyString = response.readEntity(String.class);
final ObjectMapper mapper = new ObjectMapper();
final Customer cust = mapper.readValue(replyString, Customer.class);
assertThat(replyString).isNotNull();
assertThat(cust.getId()).isEqualTo(custList.get(0).getId());
}
use of com.poc.restfulpoc.entities.Customer in project POC by rajadilipkolli.
the class DataBuilder method run.
public void run() throws Exception {
log.debug("Loading test data...");
final ZoneId defaultZoneId = ZoneId.of("UTC");
// @formatter:off
final Customer customer1 = Customer.builder().firstName("Raja").lastName("Kolli").dateOfBirth(Date.from(LocalDate.of(1982, Month.JANUARY, 10).atStartOfDay(defaultZoneId).toInstant())).address(Address.builder().county("India").postcode("BT893PY").street("High Street").town("Belfast").build()).build();
final Customer customer2 = Customer.builder().firstName("Paul").lastName("Jones").dateOfBirth(Date.from(LocalDate.of(1973, Month.JANUARY, 03).atStartOfDay(defaultZoneId).toInstant())).address(Address.builder().street("Main Street").town("Lurgan").county("Armagh").postcode("BT283FG").build()).build();
final Customer customer3 = Customer.builder().firstName("Steve").lastName("Toale").dateOfBirth(Date.from(LocalDate.of(1979, Month.MARCH, 8).atStartOfDay(defaultZoneId).toInstant())).address(Address.builder().street("Main Street").town("Newry").county("Down").postcode("BT359JK").build()).build();
// @formatter:on
customerRepository.saveAll(Stream.of(customer1, customer2, customer3).collect(Collectors.toList()));
log.debug("Test data loaded...");
}
Aggregations