Search in sources :

Example 1 with CustomerSearchRequest

use of com.braintreegateway.CustomerSearchRequest in project camel by apache.

the class CustomerGatewayIntegrationTest method testCustomerManagementWorkflow.

/**
     * Customers management workflow:
     * - create a customer
     * - lookup by id
     * - update first name
     * - delete by id
     * - confirm deletion by searching again
     *
     * @throws Exception
     */
@Test
public void testCustomerManagementWorkflow() throws Exception {
    String customerLastName = UUID.randomUUID().toString();
    String customerId = null;
    // Create customer
    Result<Customer> createResult = requestBody("direct://CREATE_IN_BODY", new CustomerRequest().firstName("user").lastName(customerLastName).company("Apache").email("user@braintree.camel").website("http://user.braintree.camel"), Result.class);
    assertNotNull(createResult);
    assertTrue(createResult.isSuccess());
    assertNotNull(createResult.getTarget());
    assertNotNull(createResult.getTarget().getId());
    customerId = createResult.getTarget().getId();
    // Find customer by ID
    Customer customer1 = requestBody("direct://FIND_IN_BODY", customerId, Customer.class);
    assertNotNull(customer1);
    assertEquals("user", customer1.getFirstName());
    assertEquals(customerLastName, customer1.getLastName());
    assertEquals("Apache", customer1.getCompany());
    assertEquals("user@braintree.camel", customer1.getEmail());
    assertEquals("http://user.braintree.camel", customer1.getWebsite());
    // Update customer
    HashMap<String, Object> headers = new HashMap<>();
    headers.put("CamelBraintree.id", customerId);
    Result<Customer> updateResult = requestBodyAndHeaders("direct://UPDATE_IN_BODY", new CustomerRequest().firstName("user-mod"), headers, Result.class);
    assertNotNull(updateResult);
    assertTrue(updateResult.isSuccess());
    assertNotNull(updateResult.getTarget());
    assertEquals("user-mod", updateResult.getTarget().getFirstName());
    // Delete customer
    Result<Customer> customerResult = requestBody("direct://DELETE_IN_BODY", customerId, Result.class);
    assertNotNull(customerResult);
    assertTrue(customerResult.isSuccess());
    assertNull(customerResult.getTarget());
    // Check if customer has been deleted customer
    ResourceCollection<Customer> customers = requestBody("direct://SEARCH_IN_BODY", new CustomerSearchRequest().id().is(customerId), ResourceCollection.class);
    assertNotNull(customers);
    assertEquals(0, customers.getMaximumSize());
}
Also used : CustomerRequest(com.braintreegateway.CustomerRequest) Customer(com.braintreegateway.Customer) HashMap(java.util.HashMap) CustomerSearchRequest(com.braintreegateway.CustomerSearchRequest) Test(org.junit.Test)

Aggregations

Customer (com.braintreegateway.Customer)1 CustomerRequest (com.braintreegateway.CustomerRequest)1 CustomerSearchRequest (com.braintreegateway.CustomerSearchRequest)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1