http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PaymentMethodGatewayIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PaymentMethodGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PaymentMethodGatewayIntegrationTest.java new file mode 100644 index 0000000..fec897d --- /dev/null +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PaymentMethodGatewayIntegrationTest.java @@ -0,0 +1,205 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.braintree; + +import java.util.List; +import java.util.UUID; + +import com.braintreegateway.BraintreeGateway; +import com.braintreegateway.Customer; +import com.braintreegateway.CustomerRequest; +import com.braintreegateway.PaymentMethod; +import com.braintreegateway.PaymentMethodRequest; +import com.braintreegateway.Result; +import com.google.common.collect.Lists; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.braintree.internal.PaymentMethodGatewayApiMethod; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PaymentMethodGatewayIntegrationTest extends AbstractBraintreeTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(PaymentMethodGatewayIntegrationTest.class); + private static final String PATH_PREFIX = getApiNameAsString(PaymentMethodGatewayApiMethod.class); + + private BraintreeGateway gateway; + private Customer customer; + private final List<String> paymentMethodsTokens; + + // ************************************************************************* + // + // ************************************************************************* + + public PaymentMethodGatewayIntegrationTest() { + this.customer = null; + this.gateway = null; + this.paymentMethodsTokens = Lists.newLinkedList(); + } + + @Override + protected void doPostSetup() throws Exception { + this.gateway = getGateway(); + this.customer = gateway.customer().create( + new CustomerRequest() + .firstName("user") + .lastName(UUID.randomUUID().toString()) + ).getTarget(); + + if (customer != null) { + LOG.info("Customer created - id={}", this.customer.getId()); + } + } + + @Override + public void tearDown() throws Exception { + if (this.gateway != null) { + for (String token : this.paymentMethodsTokens) { + if (this.gateway.paymentMethod().delete(token).isSuccess()) { + LOG.info("PaymentMethod deleted - token={}", token); + } else { + LOG.warn("Unable to delete PaymentMethod - token={}", token); + } + } + + this.paymentMethodsTokens.clear(); + + if (this.gateway.customer().delete(this.customer.getId()).isSuccess()) { + LOG.info("Customer deleted - id={}", this.customer.getId()); + } else { + LOG.warn("Unable to delete customer - id={}", this.customer.getId()); + } + } + } + + private PaymentMethod createPaymentMethod() { + Result<? extends PaymentMethod> result = this.gateway.paymentMethod().create( + new PaymentMethodRequest() + .customerId(this.customer.getId()) + .paymentMethodNonce("fake-valid-payroll-nonce")); + + assertNotNull("create result", result); + assertTrue(result.isSuccess()); + + LOG.info("PaymentMethod created - token={}", result.getTarget().getToken()); + + return result.getTarget(); + } + + // ************************************************************************* + // + // ************************************************************************* + + @Test + public void testCreate() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + assertNotNull("Customer can't be null", this.customer); + + final Result<PaymentMethod> result = requestBody("direct://CREATE", + new PaymentMethodRequest() + .customerId(this.customer.getId()) + .paymentMethodNonce("fake-valid-payroll-nonce"), + Result.class); + + assertNotNull("create result", result); + assertTrue(result.isSuccess()); + + LOG.info("PaymentMethod created - token={}", result.getTarget().getToken()); + this.paymentMethodsTokens.add(result.getTarget().getToken()); + } + + @Test + public void testDelete() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + assertNotNull("Customer can't be null", this.customer); + + final PaymentMethod paymentMethod = createPaymentMethod(); + final Result<PaymentMethod> deleteResult = requestBody( + "direct://DELETE", paymentMethod.getToken(), Result.class); + + assertNotNull("create result", deleteResult); + assertTrue(deleteResult.isSuccess()); + + LOG.info("PaymentMethod deleted - token={}", paymentMethod.getToken()); + } + + @Test + public void testFind() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + assertNotNull("Customer can't be null", this.customer); + + final PaymentMethod paymentMethod = createPaymentMethod(); + this.paymentMethodsTokens.add(paymentMethod.getToken()); + + final PaymentMethod method = requestBody( + "direct://FIND", paymentMethod.getToken(), PaymentMethod.class + ); + + assertNotNull("find result", method); + LOG.info("PaymentMethod found - token={}", method.getToken()); + } + + @Test + public void testUpdate() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + assertNotNull("Customer can't be null", this.customer); + + final PaymentMethod paymentMethod = createPaymentMethod(); + this.paymentMethodsTokens.add(paymentMethod.getToken()); + + final Result<PaymentMethod> result = requestBodyAndHeaders( + "direct://UPDATE", null, + new BraintreeHeaderBuilder() + .add("token", paymentMethod.getToken()) + .add("request", new PaymentMethodRequest() + .billingAddress() + .company("Apache") + .streetAddress("100 Maple Lane") + .done()) + .build(), + Result.class); + + assertNotNull("update result", result); + assertTrue(result.isSuccess()); + + LOG.info("PaymentMethod updated - token={}", result.getTarget().getToken()); + } + + // ************************************************************************* + // ROUTES + // ************************************************************************* + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + // test route for create + from("direct://CREATE") + .to("braintree://" + PATH_PREFIX + "/create?inBody=request"); + // test route for delete + from("direct://DELETE") + .to("braintree://" + PATH_PREFIX + "/delete?inBody=token"); + // test route for find + from("direct://FIND") + .to("braintree://" + PATH_PREFIX + "/find?inBody=token"); + // test route for update + from("direct://UPDATE") + .to("braintree://" + PATH_PREFIX + "/update"); + } + }; + } +}
http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PaymentMethodNonceGatewayIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PaymentMethodNonceGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PaymentMethodNonceGatewayIntegrationTest.java new file mode 100644 index 0000000..99ddcd0 --- /dev/null +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PaymentMethodNonceGatewayIntegrationTest.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.braintree; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.braintree.internal.BraintreeApiCollection; +import org.apache.camel.component.braintree.internal.PaymentMethodNonceGatewayApiMethod; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PaymentMethodNonceGatewayIntegrationTest extends AbstractBraintreeTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(PaymentMethodNonceGatewayIntegrationTest.class); + private static final String PATH_PREFIX = BraintreeApiCollection.getCollection().getApiName(PaymentMethodNonceGatewayApiMethod.class).getName(); + + // TODO provide parameter values for create + @Ignore + @Test + public void testCreate() throws Exception { + // using String message body for single parameter "paymentMethodToken" + final com.braintreegateway.Result result = requestBody("direct://CREATE", null); + + assertNotNull("create result", result); + LOG.debug("create: " + result); + } + + // TODO provide parameter values for find + @Ignore + @Test + public void testFind() throws Exception { + // using String message body for single parameter "paymentMethodNonce" + final com.braintreegateway.PaymentMethodNonce result = requestBody("direct://FIND", null); + + assertNotNull("find result", result); + LOG.debug("find: " + result); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + // test route for create + from("direct://CREATE") + .to("braintree://" + PATH_PREFIX + "/create?inBody=paymentMethodToken"); + // test route for find + from("direct://FIND") + .to("braintree://" + PATH_PREFIX + "/find?inBody=paymentMethodNonce"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PlanGatewayIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PlanGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PlanGatewayIntegrationTest.java new file mode 100644 index 0000000..0ec6ee8 --- /dev/null +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/PlanGatewayIntegrationTest.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.braintree; + +import java.util.List; + +import com.braintreegateway.Plan; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.braintree.internal.PlanGatewayApiMethod; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PlanGatewayIntegrationTest extends AbstractBraintreeTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(PlanGatewayIntegrationTest.class); + private static final String PATH_PREFIX = getApiNameAsString(PlanGatewayApiMethod.class); + + @Ignore + @Test + public void testAll() throws Exception { + final List<Plan> result = requestBody("direct://ALL", null, List.class); + + assertNotNull("all result", result); + LOG.debug("all: " + result); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + // test route for all + from("direct://ALL") + .to("braintree://" + PATH_PREFIX + "/all"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/SettlementBatchSummaryGatewayIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/SettlementBatchSummaryGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/SettlementBatchSummaryGatewayIntegrationTest.java new file mode 100644 index 0000000..201ca8f --- /dev/null +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/SettlementBatchSummaryGatewayIntegrationTest.java @@ -0,0 +1,75 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.braintree; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.braintree.internal.BraintreeApiCollection; +import org.apache.camel.component.braintree.internal.SettlementBatchSummaryGatewayApiMethod; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SettlementBatchSummaryGatewayIntegrationTest extends AbstractBraintreeTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(SettlementBatchSummaryGatewayIntegrationTest.class); + private static final String PATH_PREFIX = BraintreeApiCollection.getCollection().getApiName(SettlementBatchSummaryGatewayApiMethod.class).getName(); + + // TODO provide parameter values for generate + @Ignore + @Test + public void testGenerate() throws Exception { + // using java.util.Calendar message body for single parameter "settlementDate" + final com.braintreegateway.Result result = requestBody("direct://GENERATE", null); + + assertNotNull("generate result", result); + LOG.debug("generate: " + result); + } + + // TODO provide parameter values for generate + @Ignore + @Test + public void testGenerateWithCustomFields() throws Exception { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is java.util.Calendar + headers.put("CamelBraintree.settlementDate", null); + // parameter type is String + headers.put("CamelBraintree.groupByCustomField", null); + + final com.braintreegateway.Result result = requestBodyAndHeaders("direct://GENERATE_1", null, headers); + + assertNotNull("generate result", result); + LOG.debug("generate: " + result); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + // test route for generate + from("direct://GENERATE") + .to("braintree://" + PATH_PREFIX + "/generate?inBody=settlementDate"); + // test route for generate + from("direct://GENERATE_1") + .to("braintree://" + PATH_PREFIX + "/generate"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/SubscriptionGatewayIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/SubscriptionGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/SubscriptionGatewayIntegrationTest.java new file mode 100644 index 0000000..0694ae9 --- /dev/null +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/SubscriptionGatewayIntegrationTest.java @@ -0,0 +1,169 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.braintree; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.braintree.internal.BraintreeApiCollection; +import org.apache.camel.component.braintree.internal.SubscriptionGatewayApiMethod; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SubscriptionGatewayIntegrationTest extends AbstractBraintreeTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(SubscriptionGatewayIntegrationTest.class); + private static final String PATH_PREFIX = BraintreeApiCollection.getCollection().getApiName(SubscriptionGatewayApiMethod.class).getName(); + + // TODO provide parameter values for cancel + @Ignore + @Test + public void testCancel() throws Exception { + // using String message body for single parameter "id" + final com.braintreegateway.Result result = requestBody("direct://CANCEL", null); + + assertNotNull("cancel result", result); + LOG.debug("cancel: " + result); + } + + // TODO provide parameter values for create + @Ignore + @Test + public void testCreate() throws Exception { + // using com.braintreegateway.SubscriptionRequest message body for single parameter "request" + final com.braintreegateway.Result result = requestBody("direct://CREATE", null); + + assertNotNull("create result", result); + LOG.debug("create: " + result); + } + + // TODO provide parameter values for delete + @Ignore + @Test + public void testDelete() throws Exception { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBraintree.customerId", null); + // parameter type is String + headers.put("CamelBraintree.id", null); + + final com.braintreegateway.Result result = requestBodyAndHeaders("direct://DELETE", null, headers); + + assertNotNull("delete result", result); + LOG.debug("delete: " + result); + } + + // TODO provide parameter values for find + @Ignore + @Test + public void testFind() throws Exception { + // using String message body for single parameter "id" + final com.braintreegateway.Subscription result = requestBody("direct://FIND", null); + + assertNotNull("find result", result); + LOG.debug("find: " + result); + } + + // TODO provide parameter values for retryCharge + @Ignore + @Test + public void testRetryCharge() throws Exception { + // using String message body for single parameter "subscriptionId" + final com.braintreegateway.Result result = requestBody("direct://RETRYCHARGE", null); + + assertNotNull("retryCharge result", result); + LOG.debug("retryCharge: " + result); + } + + // TODO provide parameter values for retryCharge + @Ignore + @Test + public void testRetryChargeWithAmount() throws Exception { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBraintree.subscriptionId", null); + // parameter type is java.math.BigDecimal + headers.put("CamelBraintree.amount", null); + + final com.braintreegateway.Result result = requestBodyAndHeaders("direct://RETRYCHARGE_1", null, headers); + + assertNotNull("retryCharge result", result); + LOG.debug("retryCharge: " + result); + } + + // TODO provide parameter values for search + @Ignore + @Test + public void testSearch() throws Exception { + // using com.braintreegateway.SubscriptionSearchRequest message body for single parameter "searchRequest" + final com.braintreegateway.ResourceCollection result = requestBody("direct://SEARCH", null); + + assertNotNull("search result", result); + LOG.debug("search: " + result); + } + + // TODO provide parameter values for update + @Ignore + @Test + public void testUpdate() throws Exception { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBraintree.id", null); + // parameter type is com.braintreegateway.SubscriptionRequest + headers.put("CamelBraintree.request", null); + + final com.braintreegateway.Result result = requestBodyAndHeaders("direct://UPDATE", null, headers); + + assertNotNull("update result", result); + LOG.debug("update: " + result); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + // test route for cancel + from("direct://CANCEL") + .to("braintree://" + PATH_PREFIX + "/cancel?inBody=id"); + // test route for create + from("direct://CREATE") + .to("braintree://" + PATH_PREFIX + "/create?inBody=request"); + // test route for delete + from("direct://DELETE") + .to("braintree://" + PATH_PREFIX + "/delete"); + // test route for find + from("direct://FIND") + .to("braintree://" + PATH_PREFIX + "/find?inBody=id"); + // test route for retryCharge + from("direct://RETRYCHARGE") + .to("braintree://" + PATH_PREFIX + "/retryCharge?inBody=subscriptionId"); + // test route for retryCharge + from("direct://RETRYCHARGE_1") + .to("braintree://" + PATH_PREFIX + "/retryCharge"); + // test route for search + from("direct://SEARCH") + .to("braintree://" + PATH_PREFIX + "/search?inBody=searchRequest"); + // test route for update + from("direct://UPDATE") + .to("braintree://" + PATH_PREFIX + "/update"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/TransactionGatewayIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/TransactionGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/TransactionGatewayIntegrationTest.java new file mode 100644 index 0000000..211628d --- /dev/null +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/TransactionGatewayIntegrationTest.java @@ -0,0 +1,431 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.braintree; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.braintreegateway.BraintreeGateway; +import com.braintreegateway.Result; +import com.braintreegateway.Transaction; +import com.braintreegateway.TransactionCloneRequest; +import com.braintreegateway.TransactionRequest; +import com.google.common.collect.Lists; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.braintree.internal.BraintreeApiCollection; +import org.apache.camel.component.braintree.internal.TransactionGatewayApiMethod; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TransactionGatewayIntegrationTest extends AbstractBraintreeTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(TransactionGatewayIntegrationTest.class); + private static final String PATH_PREFIX = BraintreeApiCollection.getCollection().getApiName(TransactionGatewayApiMethod.class).getName(); + + private BraintreeGateway gateway; + private final List<String> transactionIds; + + // ************************************************************************* + // + // ************************************************************************* + + public TransactionGatewayIntegrationTest() { + this.gateway = null; + this.transactionIds = Lists.newLinkedList(); + } + + @Override + protected void doPostSetup() throws Exception { + this.gateway = getGateway(); + } + + @Override + public void tearDown() throws Exception { + if (this.gateway != null) { + for (String token : this.transactionIds) { + // TODO: cleanup + } + + this.transactionIds.clear(); + } + } + + // ************************************************************************* + // + // ************************************************************************* + + @Test + public void testSale() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + + final Result<Transaction> result = requestBody( + "direct://SALE", + new TransactionRequest() + .amount(new BigDecimal("100.00")) + .paymentMethodNonce("fake-valid-nonce") + .options() + .submitForSettlement(true) + .done(), + Result.class); + + assertNotNull("sale result", result); + assertTrue(result.isSuccess()); + + LOG.info("Transaction done - id={}", result.getTarget().getId()); + this.transactionIds.add(result.getTarget().getId()); + } + + @Test + public void testCloneTransaction() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + + final Result<Transaction> createResult = requestBody( + "direct://SALE", + new TransactionRequest() + .amount(new BigDecimal("100.00")) + .paymentMethodNonce("fake-valid-nonce") + .options() + .submitForSettlement(false) + .done(), + Result.class); + + assertNotNull("sale result", createResult); + assertTrue(createResult.isSuccess()); + + LOG.info("Transaction done - id={}", createResult.getTarget().getId()); + this.transactionIds.add(createResult.getTarget().getId()); + + final Result<Transaction> cloneResult = requestBodyAndHeaders( + "direct://CLONETRANSACTION", + null, + new BraintreeHeaderBuilder() + .add("id", createResult.getTarget().getId()) + .add("cloneRequest", new TransactionCloneRequest() + .amount(new BigDecimal("99.00")) + .options() + .submitForSettlement(true) + .done()) + .build(), + Result.class); + + assertNotNull("clone result", cloneResult); + assertTrue(cloneResult.isSuccess()); + + LOG.info("Clone Transaction done - clonedId={}, id={}", + createResult.getTarget().getId(), cloneResult.getTarget().getId()); + + this.transactionIds.add(cloneResult.getTarget().getId()); + } + + @Test + public void testFind() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + + final Result<Transaction> createResult = requestBody( + "direct://SALE", + new TransactionRequest() + .amount(new BigDecimal("100.00")) + .paymentMethodNonce("fake-valid-nonce") + .options() + .submitForSettlement(false) + .done(), + Result.class); + + assertNotNull("sale result", createResult); + assertTrue(createResult.isSuccess()); + + LOG.info("Transaction done - id={}", createResult.getTarget().getId()); + this.transactionIds.add(createResult.getTarget().getId()); + + + // using String message body for single parameter "id" + final Transaction result = requestBody("direct://FIND", createResult.getTarget().getId()); + + assertNotNull("find result", result); + LOG.info("Transaction found - id={}", result.getId()); + } + + @Test + public void testSubmitForSettlementWithId() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + + final Result<Transaction> createResult = requestBody( + "direct://SALE", + new TransactionRequest() + .amount(new BigDecimal("100.00")) + .paymentMethodNonce("fake-valid-nonce") + .options() + .submitForSettlement(false) + .done(), + Result.class); + + assertNotNull("sale result", createResult); + assertTrue(createResult.isSuccess()); + + LOG.info("Transaction done - id={}", createResult.getTarget().getId()); + this.transactionIds.add(createResult.getTarget().getId()); + + final Result<Transaction> result = requestBody( + "direct://SUBMITFORSETTLEMENT_WITH_ID", + createResult.getTarget().getId(), + Result.class); + + assertNotNull("Submit For Settlement result", result); + LOG.debug("Transaction submitted for settlement - id={}" + result.getTarget().getId()); + } + + @Test + public void testSubmitForSettlementWithIdAndAmount() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + + final Result<Transaction> createResult = requestBody( + "direct://SALE", + new TransactionRequest() + .amount(new BigDecimal("100.00")) + .paymentMethodNonce("fake-valid-nonce") + .options() + .submitForSettlement(false) + .done(), + Result.class); + + assertNotNull("sale result", createResult); + assertTrue(createResult.isSuccess()); + + LOG.info("Transaction done - id={}", createResult.getTarget().getId()); + this.transactionIds.add(createResult.getTarget().getId()); + + final Result<Transaction> result = requestBodyAndHeaders( + "direct://SUBMITFORSETTLEMENT_WITH_ID_ADN_AMOUNT", + null, + new BraintreeHeaderBuilder() + .add("id", createResult.getTarget().getId()) + .add("amount", new BigDecimal("100.00")) + .build(), + Result.class); + + assertNotNull("Submit For Settlement result", result); + LOG.debug("Transaction submitted for settlement - id={}" + result.getTarget().getId()); + } + + @Test + public void testSubmitForSettlementWithRequest() throws Exception { + assertNotNull("BraintreeGateway can't be null", this.gateway); + + final Result<Transaction> createResult = requestBody( + "direct://SALE", + new TransactionRequest() + .amount(new BigDecimal("100.00")) + .paymentMethodNonce("fake-valid-nonce") + .options() + .submitForSettlement(false) + .done(), + Result.class); + + assertNotNull("sale result", createResult); + assertTrue(createResult.isSuccess()); + + LOG.info("Transaction done - id={}", createResult.getTarget().getId()); + this.transactionIds.add(createResult.getTarget().getId()); + + final Result<Transaction> result = requestBodyAndHeaders( + "direct://SUBMITFORSETTLEMENT_WITH_REQUEST", + null, + new BraintreeHeaderBuilder() + .add("id", createResult.getTarget().getId()) + .add("request", new TransactionRequest() + .amount(new BigDecimal("100.00"))) + .build(), + Result.class); + + assertNotNull("Submit For Settlement result", result); + LOG.debug("Transaction submitted for settlement - id={}" + result.getTarget().getId()); + } + + // ************************************************************************* + // Auto generated tests + // ************************************************************************* + + // TODO provide parameter values for cancelRelease + @Ignore + @Test + public void testCancelRelease() throws Exception { + // using String message body for single parameter "id" + final com.braintreegateway.Result result = requestBody("direct://CANCELRELEASE", null); + + assertNotNull("cancelRelease result", result); + LOG.debug("cancelRelease: " + result); + } + + // TODO provide parameter values for credit + @Ignore + @Test + public void testCredit() throws Exception { + // using com.braintreegateway.TransactionRequest message body for single parameter "request" + final com.braintreegateway.Result result = requestBody("direct://CREDIT", null); + + assertNotNull("credit result", result); + LOG.debug("credit: " + result); + } + + // TODO provide parameter values for holdInEscrow + @Ignore + @Test + public void testHoldInEscrow() throws Exception { + // using String message body for single parameter "id" + final com.braintreegateway.Result result = requestBody("direct://HOLDINESCROW", null); + + assertNotNull("holdInEscrow result", result); + LOG.debug("holdInEscrow: " + result); + } + + // TODO provide parameter values for refund + @Ignore + @Test + public void testRefund() throws Exception { + // using String message body for single parameter "id" + final com.braintreegateway.Result result = requestBody("direct://REFUND", null); + + assertNotNull("refund result", result); + LOG.debug("refund: " + result); + } + + // TODO provide parameter values for refund + @Ignore + @Test + public void testRefundWithAmount() throws Exception { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBraintree.id", null); + // parameter type is java.math.BigDecimal + headers.put("CamelBraintree.amount", null); + + final com.braintreegateway.Result result = requestBodyAndHeaders("direct://REFUND_1", null, headers); + + assertNotNull("refund result", result); + LOG.debug("refund: " + result); + } + + // TODO provide parameter values for releaseFromEscrow + @Ignore + @Test + public void testReleaseFromEscrow() throws Exception { + // using String message body for single parameter "id" + final com.braintreegateway.Result result = requestBody("direct://RELEASEFROMESCROW", null); + + assertNotNull("releaseFromEscrow result", result); + LOG.debug("releaseFromEscrow: " + result); + } + + // TODO provide parameter values for search + @Ignore + @Test + public void testSearch() throws Exception { + // using com.braintreegateway.TransactionSearchRequest message body for single parameter "query" + final com.braintreegateway.ResourceCollection result = requestBody("direct://SEARCH", null); + + assertNotNull("search result", result); + LOG.debug("search: " + result); + } + + // TODO provide parameter values for submitForPartialSettlement + @Ignore + @Test + public void testSubmitForPartialSettlement() throws Exception { + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBraintree.id", null); + // parameter type is java.math.BigDecimal + headers.put("CamelBraintree.amount", null); + + final com.braintreegateway.Result result = requestBodyAndHeaders("direct://SUBMITFORPARTIALSETTLEMENT", null, headers); + + assertNotNull("submitForPartialSettlement result", result); + LOG.debug("submitForPartialSettlement: " + result); + } + + // TODO provide parameter values for voidTransaction + @Ignore + @Test + public void testVoidTransaction() throws Exception { + // using String message body for single parameter "id" + final com.braintreegateway.Result result = requestBody("direct://VOIDTRANSACTION", null); + + assertNotNull("voidTransaction result", result); + LOG.debug("voidTransaction: " + result); + } + + // ************************************************************************* + // ROUTES + // ************************************************************************* + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + // test route for cancelRelease + from("direct://CANCELRELEASE") + .to("braintree://" + PATH_PREFIX + "/cancelRelease?inBody=id"); + // test route for cloneTransaction + from("direct://CLONETRANSACTION") + .to("braintree://" + PATH_PREFIX + "/cloneTransaction"); + // test route for credit + from("direct://CREDIT") + .to("braintree://" + PATH_PREFIX + "/credit?inBody=request"); + // test route for find + from("direct://FIND") + .to("braintree://" + PATH_PREFIX + "/find?inBody=id"); + // test route for holdInEscrow + from("direct://HOLDINESCROW") + .to("braintree://" + PATH_PREFIX + "/holdInEscrow?inBody=id"); + // test route for refund + from("direct://REFUND") + .to("braintree://" + PATH_PREFIX + "/refund?inBody=id"); + // test route for refund + from("direct://REFUND_1") + .to("braintree://" + PATH_PREFIX + "/refund"); + // test route for releaseFromEscrow + from("direct://RELEASEFROMESCROW") + .to("braintree://" + PATH_PREFIX + "/releaseFromEscrow?inBody=id"); + // test route for sale + from("direct://SALE") + .to("braintree://" + PATH_PREFIX + "/sale?inBody=request"); + // test route for search + from("direct://SEARCH") + .to("braintree://" + PATH_PREFIX + "/search?inBody=query"); + // test route for submitForPartialSettlement + from("direct://SUBMITFORPARTIALSETTLEMENT") + .to("braintree://" + PATH_PREFIX + "/submitForPartialSettlement"); + // test route for submitForSettlement + from("direct://SUBMITFORSETTLEMENT_WITH_ID") + .to("braintree://" + PATH_PREFIX + "/submitForSettlement?inBody=id"); + // test route for submitForSettlement + from("direct://SUBMITFORSETTLEMENT_WITH_ID_ADN_AMOUNT") + .to("braintree://" + PATH_PREFIX + "/submitForSettlement"); + // test route for submitForSettlement + from("direct://SUBMITFORSETTLEMENT_WITH_REQUEST") + .to("braintree://" + PATH_PREFIX + "/submitForSettlement"); + // test route for voidTransaction + from("direct://VOIDTRANSACTION") + .to("braintree://" + PATH_PREFIX + "/voidTransaction?inBody=id"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/WebhookNotificationGatewayIntegrationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/WebhookNotificationGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/WebhookNotificationGatewayIntegrationTest.java new file mode 100644 index 0000000..211a56c --- /dev/null +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/WebhookNotificationGatewayIntegrationTest.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.braintree; + +import java.util.HashMap; +import java.util.Map; + +import com.braintreegateway.BraintreeGateway; +import com.braintreegateway.WebhookNotification; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.braintree.internal.BraintreeApiCollection; +import org.apache.camel.component.braintree.internal.BraintreeConstants; +import org.apache.camel.component.braintree.internal.WebhookNotificationGatewayApiMethod; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class WebhookNotificationGatewayIntegrationTest extends AbstractBraintreeTestSupport { + + private static final String PATH_PREFIX = BraintreeApiCollection.getCollection().getApiName(WebhookNotificationGatewayApiMethod.class).getName(); + private static final Logger LOG = LoggerFactory.getLogger(WebhookNotificationGatewayIntegrationTest.class); + + @Test + public void testParse() throws Exception { + final BraintreeGateway gateway = getGateway(); + + Map<String, String> notification = gateway.webhookTesting().sampleNotification( + WebhookNotification.Kind.SUBSCRIPTION_WENT_PAST_DUE, + "my_id" + ); + + final Map<String, Object> headers = new HashMap<>(); + headers.put(BraintreeConstants.PROPERTY_PREFIX + "signature", notification.get("bt_signature")); + headers.put(BraintreeConstants.PROPERTY_PREFIX + "payload", notification.get("bt_payload")); + + final WebhookNotification result = requestBodyAndHeaders("direct://PARSE", null, headers); + + assertNotNull("parse result", result); + assertEquals("my_id", result.getSubscription().getId()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + // test route for parse + from("direct://PARSE") + .to("braintree://" + PATH_PREFIX + "/parse"); + // test route for verify + from("direct://VERIFY") + .to("braintree://" + PATH_PREFIX + "/verify?inBody=challenge"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/resources/log4j.properties b/components/camel-braintree/src/test/resources/log4j.properties new file mode 100644 index 0000000..befa085 --- /dev/null +++ b/components/camel-braintree/src/test/resources/log4j.properties @@ -0,0 +1,31 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# The logging properties used +# +log4j.rootLogger=INFO, out + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/camel-braintree/src/test/resources/test-options.properties ---------------------------------------------------------------------- diff --git a/components/camel-braintree/src/test/resources/test-options.properties b/components/camel-braintree/src/test/resources/test-options.properties new file mode 100644 index 0000000..ed68e7d --- /dev/null +++ b/components/camel-braintree/src/test/resources/test-options.properties @@ -0,0 +1,21 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#environment = SANDBOX +#merchantId = +#publicKey = +#privateKey = \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index 8529c15..33846eb 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -74,6 +74,7 @@ <module>camel-bindy</module> <module>camel-boon</module> <module>camel-box</module> + <module>camel-braintree</module> <module>camel-cache</module> <module>camel-cassandraql</module> <module>camel-castor</module> http://git-wip-us.apache.org/repos/asf/camel/blob/e8b00192/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 281388a..74c1b57 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -76,6 +76,8 @@ <boon-version>0.33</boon-version> <bouncycastle-version>1.53</bouncycastle-version> <boxjavalibv2.version>3.2.1</boxjavalibv2.version> + <braintree-gateway-version>2.53.0</braintree-gateway-version> + <braintree-gateway-bundle-version>2.53.0_1</braintree-gateway-bundle-version> <build-helper-maven-plugin-version>1.8</build-helper-maven-plugin-version> <c3p0-version>0.9.5.2</c3p0-version> <californium-version>1.0.0-M3</californium-version> @@ -732,6 +734,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-braintree</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-cache</artifactId> <version>${project.version}</version> </dependency>