From e90cd61c04d87fb4ee016c45d8433fe037321862 Mon Sep 17 00:00:00 2001 From: Otavio Rodolfo Piske Date: Thu, 15 Apr 2021 10:58:09 +0200 Subject: [PATCH] camel-braintree: test fixes and improvements - do not reuse amount values otherwise the test fails due to duplicates - log result messages for easier debug - skip certain tests when environment variables are not provided - added documentation --- components/camel-braintree/README.md | 27 +++++++++++++++++++ .../DisputeGatewayIntegrationTest.java | 22 ++++++++++++++- .../ReportGatewayIntegrationTest.java | 7 +++++ .../TransactionGatewayIntegrationTest.java | 25 +++++++++++------ 4 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 components/camel-braintree/README.md diff --git a/components/camel-braintree/README.md b/components/camel-braintree/README.md new file mode 100644 index 0000000000000..605ed44f7ba05 --- /dev/null +++ b/components/camel-braintree/README.md @@ -0,0 +1,27 @@ +# Camel Braintree Component + +# Running the integration tests + +This component contains integration tests that must be executed against the Braintree sandbox. In +order to do so, you need to setup an account as explained in the [testing guide](https://developers.braintreepayments.com/reference/general/testing/java). + +Then, login to the Sandbox instance, collect the merchantId, publicKey and privateKey and edit the +test-options.properties file in the test resources directory. Also, uncomment the environment option. + +``` +environment = SANDBOX +merchantId = merchant ID taken from sandbox ui +publicKey = key from sandbox ui +privateKey = private key from sandbox ui +``` + +Then, you can use the following commands to run the tests: + +``` +CAMEL_BRAINTREE_REPORT_DATE=$(date '+%Y-%m-%d') CAMEL_BRAINTREE_MERCHANT_ACCOUNT_ID="merchant ID taken from sandbox" ui mvn -Pbraintree-test clean verify +``` + +It's also possible to run a smaller set of tests by running them without the environment variables: +``` +mvn -Pbraintree-test clean verify +``` diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DisputeGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DisputeGatewayIntegrationTest.java index 69942f70dd28f..12946b18d542e 100644 --- a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DisputeGatewayIntegrationTest.java +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DisputeGatewayIntegrationTest.java @@ -73,6 +73,8 @@ public void testAccept() throws Exception { final Result result = requestBody( "direct://ACCEPT", createdDispute.getId()); + + LOG.info("Result message: {}", result.getMessage()); assertNotNull(result, "accept result"); assertTrue(result.isSuccess(), "accept result success"); @@ -98,6 +100,7 @@ public void testAddFileEvidence() throws Exception { null, headers); + LOG.info("Result message: {}", result.getMessage()); assertNotNull(result, "addFileEvidence result"); assertTrue(result.isSuccess(), "addFileEvidence result success"); } @@ -118,6 +121,7 @@ public void testAddFileEvidenceOne() throws Exception { null, headers); + LOG.info("Result message: {}", result.getMessage()); assertNotNull(result, "addFileEvidence result"); assertTrue(result.isSuccess(), "addFileEvidence result success"); } @@ -137,6 +141,7 @@ public void testAddTextEvidence() throws Exception { null, headers); + LOG.info("Result message: {}", result.getMessage()); assertNotNull(result, "addTextEvidence result"); assertTrue(result.isSuccess(), "addTextEvidence result success"); @@ -161,6 +166,7 @@ public void testAddTextEvidenceOne() throws Exception { null, headers); + LOG.info("Result message: {}", result.getMessage()); assertNotNull(result, "addTextEvidence result"); assertTrue(result.isSuccess(), "addTextEvidence result success"); @@ -176,12 +182,15 @@ public void testFinalize() throws Exception { final Result result = requestBody( "direct://FINALIZE", createdDispute.getId()); + + LOG.info("Result message: {}", result.getMessage()); assertNotNull(result, "finalize result"); assertTrue(result.isSuccess(), "finalize result success"); final Dispute finalizedDispute = requestBody( "direct://FIND", createdDispute.getId()); + assertNotNull(finalizedDispute, "finalized dispute"); assertEquals(Dispute.Status.DISPUTED, finalizedDispute.getStatus()); } @@ -214,6 +223,7 @@ public void testRemoveEvidence() throws Exception { null, addTextEvidenceHeaders); + LOG.info("Result message: {}", addTextEvidenceResult.getMessage()); assertNotNull(addTextEvidenceResult, "addTextEvidence result"); assertTrue(addTextEvidenceResult.isSuccess(), "addTextEvidence result success"); @@ -229,6 +239,7 @@ public void testRemoveEvidence() throws Exception { null, removeTextEvidenceHeaders); + LOG.info("Result message: {}", removeTextEvidenceResult.getMessage()); assertNotNull(removeTextEvidenceResult, "removeEvidence result"); assertTrue(removeTextEvidenceResult.isSuccess(), "removeEvidence result success"); } @@ -301,11 +312,19 @@ public void configure() { }; } + private static int randomWithRange(int min, int max) { + int range = (max - min) + 1; + + return (int) (Math.random() * range) + min; + } + private Dispute createDispute() { - return createDispute(100.00); + double initialAmount = randomWithRange(100, 200); + return createDispute(initialAmount); } private Dispute createDispute(double amount) { + LOG.info("Creating dispute with amount {}", amount); final Result transactionResult = requestBody( "direct://SALE", new TransactionRequest() @@ -319,6 +338,7 @@ private Dispute createDispute(double amount) { .done(), Result.class); + LOG.info("Result message: {}", transactionResult.getMessage()); assertTrue(transactionResult.isSuccess()); List disputes = transactionResult.getTarget().getDisputes(); assertListSize(disputes, 1); diff --git a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/ReportGatewayIntegrationTest.java b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/ReportGatewayIntegrationTest.java index 6b0c1190961e2..ea6a8458c809c 100644 --- a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/ReportGatewayIntegrationTest.java +++ b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/ReportGatewayIntegrationTest.java @@ -25,6 +25,8 @@ import org.apache.camel.component.braintree.internal.BraintreeApiCollection; import org.apache.camel.component.braintree.internal.ReportGatewayApiMethod; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,6 +42,10 @@ public class ReportGatewayIntegrationTest extends AbstractBraintreeTestSupport { private static final String PATH_PREFIX = BraintreeApiCollection.getCollection().getApiName(ReportGatewayApiMethod.class).getName(); + @EnabledIfEnvironmentVariables({ + @EnabledIfEnvironmentVariable(named = "CAMEL_BRAINTREE_MERCHANT_ACCOUNT_ID", matches = ".*"), + @EnabledIfEnvironmentVariable(named = "CAMEL_BRAINTREE_REPORT_DATE", matches = ".*") + }) @Test public void testTransactionLevelFees() throws Exception { String merchantAccountId = System.getenv("CAMEL_BRAINTREE_MERCHANT_ACCOUNT_ID"); @@ -57,6 +63,7 @@ public void testTransactionLevelFees() throws Exception { "direct://TRANSACTIONLEVELFEES", request); + LOG.info("Result message: {}", result.getMessage()); assertNotNull(result, "transactionLevelFees result"); assertTrue(result.isSuccess(), "transactionLevelFees success"); TransactionLevelFeeReport report = result.getTarget(); 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 index 1eeba2c0129f9..474664cd43f2d 100644 --- 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 @@ -92,6 +92,7 @@ public void testSale() throws Exception { .done(), Result.class); + LOG.info("Result message: {}", result.getMessage()); assertNotNull(result, "sale result"); assertTrue(result.isSuccess()); @@ -106,13 +107,14 @@ public void testCloneTransaction() throws Exception { final Result createResult = requestBody( "direct://SALE", new TransactionRequest() - .amount(new BigDecimal("100.00")) + .amount(new BigDecimal("100.01")) .paymentMethodNonce("fake-valid-nonce") .options() .submitForSettlement(false) .done(), Result.class); + LOG.info("Result message: {}", createResult.getMessage()); assertNotNull(createResult, "sale result"); assertTrue(createResult.isSuccess()); @@ -148,13 +150,14 @@ public void testFind() throws Exception { final Result createResult = requestBody( "direct://SALE", new TransactionRequest() - .amount(new BigDecimal("100.00")) + .amount(new BigDecimal("100.02")) .paymentMethodNonce("fake-valid-nonce") .options() .submitForSettlement(false) .done(), Result.class); + LOG.info("Result message: {}", createResult.getMessage()); assertNotNull(createResult, "sale result"); assertTrue(createResult.isSuccess()); @@ -175,13 +178,14 @@ public void testSubmitForSettlementWithId() throws Exception { final Result createResult = requestBody( "direct://SALE", new TransactionRequest() - .amount(new BigDecimal("100.00")) + .amount(new BigDecimal("100.03")) .paymentMethodNonce("fake-valid-nonce") .options() .submitForSettlement(false) .done(), Result.class); + LOG.info("Result message: {}", createResult.getMessage()); assertNotNull(createResult, "sale result"); assertTrue(createResult.isSuccess()); @@ -204,13 +208,14 @@ public void testSubmitForSettlementWithIdAndAmount() throws Exception { final Result createResult = requestBody( "direct://SALE", new TransactionRequest() - .amount(new BigDecimal("100.00")) + .amount(new BigDecimal("100.04")) .paymentMethodNonce("fake-valid-nonce") .options() .submitForSettlement(false) .done(), Result.class); + LOG.info("Result message: {}", createResult.getMessage()); assertNotNull(createResult, "sale result"); assertTrue(createResult.isSuccess()); @@ -237,13 +242,14 @@ public void testSubmitForSettlementWithRequest() throws Exception { final Result createResult = requestBody( "direct://SALE", new TransactionRequest() - .amount(new BigDecimal("100.00")) + .amount(new BigDecimal("100.05")) .paymentMethodNonce("fake-valid-nonce") .options() .submitForSettlement(false) .done(), Result.class); + LOG.info("Result message: {}", createResult.getMessage()); assertNotNull(createResult, "sale result"); assertTrue(createResult.isSuccess()); @@ -271,13 +277,14 @@ public void testRefund() throws Exception { final Result createResult = requestBody( "direct://SALE", new TransactionRequest() - .amount(new BigDecimal("100.00")) + .amount(new BigDecimal("100.06")) .paymentMethodNonce("fake-valid-nonce") .options() .submitForSettlement(true) .done(), Result.class); + LOG.info("Result message: {}", createResult.getMessage()); assertNotNull(createResult, "sale result"); assertTrue(createResult.isSuccess()); @@ -304,13 +311,14 @@ public void testRefundWithAmount() throws Exception { final Result createResult = requestBody( "direct://SALE", new TransactionRequest() - .amount(new BigDecimal("100.00")) + .amount(new BigDecimal("100.07")) .paymentMethodNonce("fake-valid-nonce") .options() .submitForSettlement(true) .done(), Result.class); + LOG.info("Result message: {}", createResult.getMessage()); assertNotNull(createResult, "sale result"); assertTrue(createResult.isSuccess()); @@ -341,13 +349,14 @@ public void testRefundWithRequest() throws Exception { final Result createResult = requestBody( "direct://SALE", new TransactionRequest() - .amount(new BigDecimal("100.00")) + .amount(new BigDecimal("100.08")) .paymentMethodNonce("fake-valid-nonce") .options() .submitForSettlement(true) .done(), Result.class); + LOG.info("Result message: {}", createResult.getMessage()); assertNotNull(createResult, "sale result"); assertTrue(createResult.isSuccess());