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