Search in sources :

Example 1 with CustomerInfo

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)));
}
Also used : Expectations(org.jmock.Expectations) CustomerServiceImpl(com.github.wenqiglantz.service.customerservice.service.impl.CustomerServiceImpl) CustomerInfo(com.github.wenqiglantz.service.customerservice.data.CustomerInfo) Test(org.junit.jupiter.api.Test)

Example 2 with CustomerInfo

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())));
}
Also used : Expectations(org.jmock.Expectations) CustomerServiceImpl(com.github.wenqiglantz.service.customerservice.service.impl.CustomerServiceImpl) CustomerInfo(com.github.wenqiglantz.service.customerservice.data.CustomerInfo) Test(org.junit.jupiter.api.Test)

Example 3 with CustomerInfo

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());
}
Also used : CustomerInfo(com.github.wenqiglantz.service.customerservice.data.CustomerInfo) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 4 with CustomerInfo

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;
}
Also used : Expectations(org.jmock.Expectations) CustomerInfo(com.github.wenqiglantz.service.customerservice.data.CustomerInfo) CustomerWasUpdated(com.github.wenqiglantz.service.customerservice.data.event.CustomerWasUpdated) PactVerifyProvider(au.com.dius.pact.provider.PactVerifyProvider)

Example 5 with CustomerInfo

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()));
}
Also used : Expectations(org.jmock.Expectations) ResponseEntity(org.springframework.http.ResponseEntity) CustomerInfo(com.github.wenqiglantz.service.customerservice.data.CustomerInfo) Test(org.junit.jupiter.api.Test)

Aggregations

CustomerInfo (com.github.wenqiglantz.service.customerservice.data.CustomerInfo)7 Expectations (org.jmock.Expectations)5 Test (org.junit.jupiter.api.Test)3 PactVerifyProvider (au.com.dius.pact.provider.PactVerifyProvider)2 CustomerServiceImpl (com.github.wenqiglantz.service.customerservice.service.impl.CustomerServiceImpl)2 CustomerWasCreated (com.github.wenqiglantz.service.customerservice.data.event.CustomerWasCreated)1 CustomerWasUpdated (com.github.wenqiglantz.service.customerservice.data.event.CustomerWasUpdated)1 NotFoundException (com.github.wenqiglantz.service.customerservice.data.exception.NotFoundException)1 Customer (com.github.wenqiglantz.service.customerservice.persistence.entity.Customer)1 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)1 URI (java.net.URI)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1