Search in sources :

Example 1 with Customer

use of com.braintreegateway.Customer 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)

Example 2 with Customer

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

the class CustomerGatewayIntegrationTest method testWrongCustomerCreateRequest.

@Test
public void testWrongCustomerCreateRequest() throws Exception {
    // Create customer
    Result<Customer> createResult = requestBody("direct://CREATE_IN_BODY", new CustomerRequest().firstName("user").lastName(UUID.randomUUID().toString()).company("Apache").email("wrongEmail").website("http://user.braintree.camel"), Result.class);
    assertNotNull(createResult);
    assertFalse(createResult.isSuccess());
    final ValidationErrors errors = createResult.getErrors();
    assertNotNull(errors);
    assertNotNull(errors.getAllDeepValidationErrors());
    ValidationError invalidMailError = null;
    for (ValidationError error : errors.getAllDeepValidationErrors()) {
        if (error.getCode() == ValidationErrorCode.CUSTOMER_EMAIL_FORMAT_IS_INVALID) {
            invalidMailError = error;
            break;
        }
    }
    assertNotNull(invalidMailError);
}
Also used : CustomerRequest(com.braintreegateway.CustomerRequest) Customer(com.braintreegateway.Customer) ValidationErrors(com.braintreegateway.ValidationErrors) ValidationError(com.braintreegateway.ValidationError) Test(org.junit.Test)

Example 3 with Customer

use of com.braintreegateway.Customer in project wildfly-camel by wildfly-extras.

the class BraintreeIntegrationTest method testBraintreeCustomerGateway.

@Test
public void testBraintreeCustomerGateway() throws Exception {
    Map<String, Object> braintreeOptions = createBraintreeOptions();
    // Do nothing if the required credentials are not present
    Assume.assumeTrue(braintreeOptions.size() == BraintreeOption.values().length);
    final CountDownLatch latch = new CountDownLatch(2);
    final CamelContext camelctx = new DefaultCamelContext();
    final BraintreeConfiguration configuration = new BraintreeConfiguration();
    IntrospectionSupport.setProperties(configuration, braintreeOptions);
    // add BraintreeComponent to Camel context
    final BraintreeComponent component = new BraintreeComponent(camelctx);
    component.setConfiguration(configuration);
    camelctx.addComponent("braintree", component);
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:create").to("braintree:customer/create?inBody=request").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    latch.countDown();
                }
            });
            from("direct:delete").to("braintree:customer/delete?inBody=id").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    latch.countDown();
                }
            });
        }
    });
    camelctx.start();
    // ****************************
    // Create a customer
    // ****************************
    @SuppressWarnings("unchecked") Result<Customer> createResult = camelctx.createProducerTemplate().requestBody("direct:create", new CustomerRequest().firstName("user").lastName(UUID.randomUUID().toString()).company("Apache").email("user@braintree.camel").website("http://user.braintree.camel"), Result.class);
    Assert.assertNotNull(createResult);
    Assert.assertTrue(createResult.isSuccess());
    Assert.assertNotNull(createResult.getTarget());
    Assert.assertNotNull(createResult.getTarget().getId());
    // ****************************
    // Delete the customer
    // ****************************
    @SuppressWarnings("unchecked") Result<Customer> deleteResult = camelctx.createProducerTemplate().requestBody("direct:delete", createResult.getTarget().getId(), Result.class);
    Assert.assertNotNull(deleteResult);
    Assert.assertTrue(deleteResult.isSuccess());
    Assert.assertNull(deleteResult.getTarget());
    try {
        Assert.assertTrue("Countdown reached zero", latch.await(5, TimeUnit.MINUTES));
    } finally {
        camelctx.close();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Customer(com.braintreegateway.Customer) BraintreeComponent(org.apache.camel.component.braintree.BraintreeComponent) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) BraintreeConfiguration(org.apache.camel.component.braintree.BraintreeConfiguration) Exchange(org.apache.camel.Exchange) CustomerRequest(com.braintreegateway.CustomerRequest) Test(org.junit.Test)

Aggregations

Customer (com.braintreegateway.Customer)3 CustomerRequest (com.braintreegateway.CustomerRequest)3 Test (org.junit.Test)3 CustomerSearchRequest (com.braintreegateway.CustomerSearchRequest)1 ValidationError (com.braintreegateway.ValidationError)1 ValidationErrors (com.braintreegateway.ValidationErrors)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 BraintreeComponent (org.apache.camel.component.braintree.BraintreeComponent)1 BraintreeConfiguration (org.apache.camel.component.braintree.BraintreeConfiguration)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1