Search in sources :

Example 6 with CustomerRequest

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

CustomerRequest (com.braintreegateway.CustomerRequest)6 Customer (com.braintreegateway.Customer)3 Test (org.junit.Test)3 CreditCardAddressRequest (com.braintreegateway.CreditCardAddressRequest)1 CreditCardRequest (com.braintreegateway.CreditCardRequest)1 CustomerSearchRequest (com.braintreegateway.CustomerSearchRequest)1 ValidationError (com.braintreegateway.ValidationError)1 ValidationErrors (com.braintreegateway.ValidationErrors)1 AuthenticationException (com.braintreegateway.exceptions.AuthenticationException)1 AuthorizationException (com.braintreegateway.exceptions.AuthorizationException)1 ConfigurationException (com.braintreegateway.exceptions.ConfigurationException)1 DownForMaintenanceException (com.braintreegateway.exceptions.DownForMaintenanceException)1 ForgedQueryStringException (com.braintreegateway.exceptions.ForgedQueryStringException)1 InvalidChallengeException (com.braintreegateway.exceptions.InvalidChallengeException)1 InvalidSignatureException (com.braintreegateway.exceptions.InvalidSignatureException)1 NotFoundException (com.braintreegateway.exceptions.NotFoundException)1 ServerException (com.braintreegateway.exceptions.ServerException)1 TimeoutException (com.braintreegateway.exceptions.TimeoutException)1 TooManyRequestsException (com.braintreegateway.exceptions.TooManyRequestsException)1 UnexpectedException (com.braintreegateway.exceptions.UnexpectedException)1