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());
}
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);
}
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();
}
}
Aggregations