From 1f091b2d26a88d1eb2045f05528a586fa5bea4f6 Mon Sep 17 00:00:00 2001 From: Braintree Date: Mon, 29 Feb 2016 20:53:58 +0000 Subject: [PATCH 1/3] 2.57.0 --- CHANGELOG.md | 3 + pom.xml | 5 +- .../com/braintreegateway/Configuration.java | 19 +++ .../java/com/braintreegateway/util/Http.java | 72 ++++++++++-- .../integrationtest/AddOnIT.java | 8 +- .../integrationtest/AddressIT.java | 10 +- .../integrationtest/ClientTokenIT.java | 15 +-- .../integrationtest/CoinbaseIT.java | 10 +- .../integrationtest/CreditCardIT.java | 11 +- .../CreditCardVerificationIT.java | 10 +- .../integrationtest/CustomerIT.java | 10 +- .../integrationtest/DisbursementIT.java | 9 +- .../integrationtest/DiscountIT.java | 9 +- .../integrationtest/EuropeBankAccountIT.java | 10 +- .../HttpTestIT.java} | 108 ++++++++++++++++-- .../integrationtest/IntegrationTest.java | 34 ++++++ .../integrationtest/MerchantAccountIT.java | 11 +- .../integrationtest/MerchantIT.java | 11 +- .../integrationtest/OAuthIT.java | 10 +- .../integrationtest/PayPalAccountIT.java | 10 +- .../integrationtest/PaymentMethodIT.java | 10 +- .../integrationtest/PaymentMethodNonceIT.java | 10 +- .../integrationtest/PlanIT.java | 8 +- .../SettlementBatchSummaryIT.java | 6 +- .../integrationtest/SubscriptionIT.java | 8 +- .../integrationtest/TestingGatewayIT.java | 1 - .../integrationtest/TransactionIT.java | 9 +- .../TransparentRedirectIT.java | 9 +- .../WebhookNotificationIT.java | 9 +- 29 files changed, 263 insertions(+), 192 deletions(-) rename src/test/java/com/braintreegateway/{util/HttpTest.java => integrationtest/HttpTestIT.java} (66%) create mode 100644 src/test/java/com/braintreegateway/integrationtest/IntegrationTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fbe2ef4..768ec06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.57.0 +* Add support for logging. Thanks @yatsenko-ihor! + ## 2.56.0 * Add AccountUpdaterDailyReport webhook parsing diff --git a/pom.xml b/pom.xml index e102ae87..15780402 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.braintreepayments.gateway braintree-java - 2.56.1-SNAPSHOT + 2.57.0-SNAPSHOT Java Client Library for Braintree Payments Gateway bundle Braintree Gateway Java Client Library @@ -33,7 +33,7 @@ ${scmConnection} - 2.56.0 + 2.57.0 @@ -179,7 +179,6 @@ **/integrationtest/** - **/HttpTest.java true false diff --git a/src/main/java/com/braintreegateway/Configuration.java b/src/main/java/com/braintreegateway/Configuration.java index e90b869a..aa29f3b0 100644 --- a/src/main/java/com/braintreegateway/Configuration.java +++ b/src/main/java/com/braintreegateway/Configuration.java @@ -1,8 +1,12 @@ package com.braintreegateway; import com.braintreegateway.util.ClientLibraryProperties; + import java.net.Proxy; import java.net.InetSocketAddress; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; public class Configuration { private Environment environment; @@ -13,6 +17,13 @@ public class Configuration { private String clientSecret; private String accessToken; private Proxy proxy; + private static Logger logger; + + static { + logger = Logger.getLogger("Braintree"); + logger.addHandler(new ConsoleHandler()); + logger.setLevel(Level.INFO); + } public static final String VERSION = new ClientLibraryProperties().version(); @@ -99,4 +110,12 @@ public void setProxy(String url, Integer port) { public Proxy getProxy() { return proxy; } + + public Logger getLogger() { + return logger; + } + + public void setLogger(Logger log) { + logger = log; + } } diff --git a/src/main/java/com/braintreegateway/util/Http.java b/src/main/java/com/braintreegateway/util/Http.java index cb0c86bc..6aea9b42 100644 --- a/src/main/java/com/braintreegateway/util/Http.java +++ b/src/main/java/com/braintreegateway/util/Http.java @@ -1,11 +1,5 @@ package com.braintreegateway.util; -import com.braintreegateway.Configuration; -import com.braintreegateway.Request; -import com.braintreegateway.exceptions.*; -import com.braintreegateway.org.apache.commons.codec.binary.Base64; - -import javax.net.ssl.*; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -19,10 +13,33 @@ import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.Arrays; +import java.text.SimpleDateFormat; import java.util.Collection; +import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManagerFactory; + +import com.braintreegateway.Configuration; +import com.braintreegateway.Request; +import com.braintreegateway.exceptions.AuthenticationException; +import com.braintreegateway.exceptions.AuthorizationException; +import com.braintreegateway.exceptions.DownForMaintenanceException; +import com.braintreegateway.exceptions.NotFoundException; +import com.braintreegateway.exceptions.ServerException; +import com.braintreegateway.exceptions.UnexpectedException; +import com.braintreegateway.exceptions.UpgradeRequiredException; +import com.braintreegateway.org.apache.commons.codec.binary.Base64; + public class Http { enum RequestMethod { @@ -70,6 +87,11 @@ private NodeWrapper httpRequest(RequestMethod requestMethod, String url, String try { connection = buildConnection(requestMethod, url); + Logger logger = configuration.getLogger(); + if (postBody != null) { + logger.log(Level.FINE, formatSanitizeBodyForLog(postBody)); + } + if (connection instanceof HttpsURLConnection) { ((HttpsURLConnection) connection).setSSLSocketFactory(getSSLSocketFactory()); } @@ -100,6 +122,14 @@ private NodeWrapper httpRequest(RequestMethod requestMethod, String url, String } String xml = StringUtils.inputStreamToString(responseStream); + + logger.log(Level.INFO, "[Braintree] [{0}]] {1} {2}", new Object[] { getCurrentTime(), requestMethod.toString(), url }); + logger.log(Level.FINE, "[Braintree] [{0}] {1} {2} {3}", new Object[] { getCurrentTime(), requestMethod.toString(), url, connection.getResponseCode() }); + + if (xml != null) { + logger.log(Level.FINE, formatSanitizeBodyForLog(xml)); + } + nodeWrapper = NodeWrapperFactory.instance.create(xml); } finally { if (responseStream != null) { @@ -117,6 +147,32 @@ private NodeWrapper httpRequest(RequestMethod requestMethod, String url, String return nodeWrapper; } + private String formatSanitizeBodyForLog(String body) { + if (body == null) { + return body; + } + + Pattern regex = Pattern.compile("(^)", Pattern.MULTILINE); + Matcher regexMatcher = regex.matcher(body); + if (regexMatcher.find()) { + body = regexMatcher.replaceAll("[Braintree] $1"); + } + + regex = Pattern.compile("(.{6}).+?(.{4})"); + regexMatcher = regex.matcher(body); + if (regexMatcher.find()) { + body = regexMatcher.replaceAll("$1******$2"); + } + + body = body.replaceAll(".+?", "***"); + + return body; + } + + private String getCurrentTime() { + return new SimpleDateFormat("d/MMM/yyyy HH:mm:ss Z").format(new Date()); + } + private SSLSocketFactory getSSLSocketFactory() { try { KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); @@ -154,6 +210,8 @@ private SSLSocketFactory getSSLSocketFactory() { return sslContext.getSocketFactory(); } catch (Exception e) { + Logger logger = configuration.getLogger(); + logger.log(Level.SEVERE, "SSL Verification failed. Error message: {0}", new Object[] { e.getMessage() }); throw new UnexpectedException(e.getMessage(), e); } } diff --git a/src/test/java/com/braintreegateway/integrationtest/AddOnIT.java b/src/test/java/com/braintreegateway/integrationtest/AddOnIT.java index 4a3fec07..090cdd83 100644 --- a/src/test/java/com/braintreegateway/integrationtest/AddOnIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/AddOnIT.java @@ -13,14 +13,12 @@ import static org.junit.Assert.assertEquals; -public class AddOnIT { - private BraintreeGateway gateway; +public class AddOnIT extends IntegrationTest { private Http http; @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - http = new Http(gateway.getConfiguration()); + public void createHttp() { + http = new Http(this.gateway.getConfiguration()); } @Test diff --git a/src/test/java/com/braintreegateway/integrationtest/AddressIT.java b/src/test/java/com/braintreegateway/integrationtest/AddressIT.java index cddb824f..eed0c37e 100644 --- a/src/test/java/com/braintreegateway/integrationtest/AddressIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/AddressIT.java @@ -2,7 +2,6 @@ import com.braintreegateway.*; import com.braintreegateway.exceptions.NotFoundException; -import org.junit.Before; import org.junit.Test; import java.util.Calendar; @@ -11,14 +10,7 @@ import static org.junit.Assert.*; -public class AddressIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class AddressIT extends IntegrationTest { @Test public void create() { diff --git a/src/test/java/com/braintreegateway/integrationtest/ClientTokenIT.java b/src/test/java/com/braintreegateway/integrationtest/ClientTokenIT.java index 6f2fe446..2b365094 100644 --- a/src/test/java/com/braintreegateway/integrationtest/ClientTokenIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/ClientTokenIT.java @@ -4,7 +4,6 @@ import java.util.List; import org.junit.Test; -import org.junit.Before; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -16,9 +15,7 @@ import com.braintreegateway.util.NodeWrapper; import com.braintreegateway.*; -public class ClientTokenIT { - private BraintreeGateway gateway; - +public class ClientTokenIT extends IntegrationTest { private String urlencode(String string) { String encodedString = ""; try { @@ -47,16 +44,6 @@ private String _getFingerprint(String rawClientToken) { return TestHelper.extractParamFromJson("authorizationFingerprint", decodedClientToken); } - @Before - public void createGateway() { - this.gateway = new BraintreeGateway( - Environment.DEVELOPMENT, - "integration_merchant_id", - "integration_public_key", - "integration_private_key" - ); - } - @Test public void fingerprintIsAcceptedByTheGateway() { String clientToken = gateway.clientToken().generate(); diff --git a/src/test/java/com/braintreegateway/integrationtest/CoinbaseIT.java b/src/test/java/com/braintreegateway/integrationtest/CoinbaseIT.java index c0bbfc7e..8814d688 100644 --- a/src/test/java/com/braintreegateway/integrationtest/CoinbaseIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/CoinbaseIT.java @@ -8,20 +8,12 @@ import com.braintreegateway.test.*; import org.junit.Test; -import org.junit.Before; import org.junit.Rule; import org.junit.rules.ExpectedException; import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; -public class CoinbaseIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class CoinbaseIT extends IntegrationTest{ @Test public void canCreateTransaction() { diff --git a/src/test/java/com/braintreegateway/integrationtest/CreditCardIT.java b/src/test/java/com/braintreegateway/integrationtest/CreditCardIT.java index 2594330d..d2f22c8c 100644 --- a/src/test/java/com/braintreegateway/integrationtest/CreditCardIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/CreditCardIT.java @@ -10,7 +10,6 @@ import com.braintreegateway.testhelpers.TestHelper; import com.braintreegateway.testhelpers.HttpHelper; import com.braintreegateway.util.QueryString; -import org.junit.Before; import org.junit.Test; import java.math.BigDecimal; @@ -18,15 +17,7 @@ import static org.junit.Assert.*; -public class CreditCardIT implements MerchantAccountTestConstants { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", - "integration_private_key"); - } +public class CreditCardIT extends IntegrationTest implements MerchantAccountTestConstants { @SuppressWarnings("deprecation") @Test diff --git a/src/test/java/com/braintreegateway/integrationtest/CreditCardVerificationIT.java b/src/test/java/com/braintreegateway/integrationtest/CreditCardVerificationIT.java index ad0620d3..b201e991 100644 --- a/src/test/java/com/braintreegateway/integrationtest/CreditCardVerificationIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/CreditCardVerificationIT.java @@ -5,7 +5,6 @@ import com.braintreegateway.SandboxValues.CreditCardNumber; import com.braintreegateway.util.NodeWrapper; import com.braintreegateway.util.NodeWrapperFactory; -import org.junit.Before; import org.junit.Test; import java.util.ArrayList; @@ -15,14 +14,7 @@ import static org.junit.Assert.*; -public class CreditCardVerificationIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class CreditCardVerificationIT extends IntegrationTest { @Test public void createVerification() { diff --git a/src/test/java/com/braintreegateway/integrationtest/CustomerIT.java b/src/test/java/com/braintreegateway/integrationtest/CustomerIT.java index 18bc80e3..14a028cc 100644 --- a/src/test/java/com/braintreegateway/integrationtest/CustomerIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/CustomerIT.java @@ -6,7 +6,6 @@ import com.braintreegateway.test.Nonce; import com.braintreegateway.test.VenmoSdk; import com.braintreegateway.testhelpers.TestHelper; -import org.junit.Before; import org.junit.Test; import java.util.*; @@ -14,14 +13,7 @@ import static org.junit.Assert.*; @SuppressWarnings("deprecation") -public class CustomerIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class CustomerIT extends IntegrationTest { @Test public void transparentRedirectURLForCreate() { diff --git a/src/test/java/com/braintreegateway/integrationtest/DisbursementIT.java b/src/test/java/com/braintreegateway/integrationtest/DisbursementIT.java index bfc9398d..9d6b214e 100644 --- a/src/test/java/com/braintreegateway/integrationtest/DisbursementIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/DisbursementIT.java @@ -5,7 +5,6 @@ import com.braintreegateway.*; import com.braintreegateway.util.NodeWrapperFactory; import com.braintreegateway.testhelpers.CalendarTestUtils; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; @@ -17,13 +16,7 @@ import java.util.List; -public class DisbursementIT { - private BraintreeGateway gateway; - - @Before - public void setUp() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class DisbursementIT extends IntegrationTest { @Test public void createDisbursement() { diff --git a/src/test/java/com/braintreegateway/integrationtest/DiscountIT.java b/src/test/java/com/braintreegateway/integrationtest/DiscountIT.java index 2a6fb94e..4b9b8ebf 100644 --- a/src/test/java/com/braintreegateway/integrationtest/DiscountIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/DiscountIT.java @@ -13,14 +13,13 @@ import static org.junit.Assert.assertEquals; -public class DiscountIT { - private BraintreeGateway gateway; +public class DiscountIT extends IntegrationTest { + private Http http; @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - http = new Http(gateway.getConfiguration()); + public void createHttp() { + http = new Http(this.gateway.getConfiguration()); } @Test diff --git a/src/test/java/com/braintreegateway/integrationtest/EuropeBankAccountIT.java b/src/test/java/com/braintreegateway/integrationtest/EuropeBankAccountIT.java index f6d3d596..60775383 100644 --- a/src/test/java/com/braintreegateway/integrationtest/EuropeBankAccountIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/EuropeBankAccountIT.java @@ -3,20 +3,12 @@ import com.braintreegateway.*; import com.braintreegateway.testhelpers.TestHelper; import com.braintreegateway.exceptions.NotFoundException; -import org.junit.Before; import org.junit.Test; import java.util.Random; import static org.junit.Assert.*; -public class EuropeBankAccountIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "altpay_merchant", "altpay_merchant_public_key", "altpay_merchant_private_key"); - } +public class EuropeBankAccountIT extends IntegrationTest { @Test public void canExchangeNonceForEuropeBankAccount() { diff --git a/src/test/java/com/braintreegateway/util/HttpTest.java b/src/test/java/com/braintreegateway/integrationtest/HttpTestIT.java similarity index 66% rename from src/test/java/com/braintreegateway/util/HttpTest.java rename to src/test/java/com/braintreegateway/integrationtest/HttpTestIT.java index 7bea21dc..623eb799 100644 --- a/src/test/java/com/braintreegateway/util/HttpTest.java +++ b/src/test/java/com/braintreegateway/integrationtest/HttpTestIT.java @@ -1,31 +1,59 @@ -package com.braintreegateway.util; +package com.braintreegateway.integrationtest; import com.braintreegateway.BraintreeGateway; +import com.braintreegateway.Configuration; +import com.braintreegateway.CreditCard; +import com.braintreegateway.CreditCardRequest; +import com.braintreegateway.Customer; import com.braintreegateway.CustomerRequest; import com.braintreegateway.Environment; -import com.braintreegateway.Configuration; import com.braintreegateway.exceptions.AuthenticationException; import com.braintreegateway.exceptions.DownForMaintenanceException; +import com.braintreegateway.exceptions.UnexpectedException; import com.braintreegateway.exceptions.UpgradeRequiredException; import com.braintreegateway.org.apache.commons.codec.binary.Base64; +import com.braintreegateway.Result; import com.braintreegateway.testhelpers.TestHelper; +import com.braintreegateway.util.Http; +import com.braintreegateway.util.NodeWrapper; +import com.braintreegateway.util.StringUtils; + import org.junit.Before; import org.junit.Test; -import java.io.File; -import java.io.FileInputStream; +import java.util.logging.StreamHandler; +import java.util.logging.Logger; +import java.util.logging.Level; +import java.util.logging.Handler; +import java.io.OutputStream; import java.io.IOException; +import java.io.FileInputStream; +import java.io.File; +import java.io.ByteArrayOutputStream; import static org.junit.Assert.*; @SuppressWarnings("deprecation") -public class HttpTest { +public class HttpTestIT extends IntegrationTest { - private BraintreeGateway gateway; + private static OutputStream logCapturingStream; + private static StreamHandler customLogHandler; - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); + public void attachLogCapturer() + { + Configuration configuration = this.gateway.getConfiguration(); + Logger logger = configuration.getLogger(); + logCapturingStream = new ByteArrayOutputStream(); + Handler[] handlers = logger.getParent().getHandlers(); + customLogHandler = new StreamHandler(logCapturingStream, handlers[0].getFormatter()); + customLogHandler.setLevel(Level.FINE); + logger.addHandler(customLogHandler); + } + + public String getTestCapturedLog() + { + customLogHandler.flush(); + return logCapturingStream.toString(); } @Test @@ -58,6 +86,68 @@ public void smokeTestDelete() { new Http(gateway.getConfiguration()).delete(configuration.getMerchantPath() + "/customers/" + node.findString("id")); } + @Test + public void smokeTestLogsRequests() { + Configuration configuration = gateway.getConfiguration(); + attachLogCapturer(); + + NodeWrapper node = new Http(configuration).get(configuration.getMerchantPath() + "/customers/131866"); + String capturedLog = getTestCapturedLog(); + + assertTrue(capturedLog.contains("[Braintree]")); + assertTrue(capturedLog.contains("GET /merchants/integration_merchant_id/customers")); + } + + @Test + public void smokeTestLogsFullRequestInDebugMode() { + Configuration configuration = gateway.getConfiguration(); + configuration.getLogger().setLevel(Level.FINEST); + attachLogCapturer(); + + Customer customer = gateway.customer().create(new CustomerRequest()).getTarget(); + CreditCardRequest request = new CreditCardRequest(). + customerId(customer.getId()). + cardholderName("John Doe"). + cvv("123"). + number("5105105105105100"). + expirationDate("05/12"); + Result result = gateway.creditCard().create(request); + + String capturedLog = getTestCapturedLog(); + assertTrue(capturedLog.contains("[Braintree]")); + assertTrue(capturedLog.contains("POST /merchants/integration_merchant_id/payment_methods")); + assertTrue(capturedLog.contains("John Doe")); + assertTrue(capturedLog.contains("510510******5100")); + assertTrue(capturedLog.contains("***")); + } + + @Test + public void smokeTestLogsErrors() { + Environment fake_environment = new Environment( + "https://api.sandbox.braintreegateway.com:443", + "http://auth.sandbox.venmo.com", + new String[] {"fake_ca_cert"}, + "sandbox" + ); + this.gateway = new BraintreeGateway( + fake_environment, + "integration_merchant_id", + "integration_public_key", + "integration_private_key" + ); + + String capturedLog = ""; + try { + Configuration configuration = this.gateway.getConfiguration(); + attachLogCapturer(); + NodeWrapper node = new Http(configuration).get(configuration.getMerchantPath() + "/customers/131866"); + } catch (UnexpectedException e) { + } finally { + capturedLog = getTestCapturedLog(); + assertTrue(capturedLog.contains("SEVERE: SSL Verification failed. Error message: Missing input stream")); + } + } + @Test(expected = AuthenticationException.class) public void authenticationException() { BraintreeGateway gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "bad_public_key", "bad_private_key"); diff --git a/src/test/java/com/braintreegateway/integrationtest/IntegrationTest.java b/src/test/java/com/braintreegateway/integrationtest/IntegrationTest.java new file mode 100644 index 00000000..c3be695c --- /dev/null +++ b/src/test/java/com/braintreegateway/integrationtest/IntegrationTest.java @@ -0,0 +1,34 @@ +package com.braintreegateway.integrationtest; + +import com.braintreegateway.*; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.junit.Before; + +public class IntegrationTest { + + protected BraintreeGateway gateway; + + @Before + public void createGateway() { + this.gateway = new BraintreeGateway( + Environment.DEVELOPMENT, + "integration_merchant_id", + "integration_public_key", + "integration_private_key" + ); + } + + @Before + public void ignoreLogging(){ + if (this.gateway == null) { + createGateway(); + } + + this.gateway.getConfiguration().setLogger(Logger.getLogger("null")); + this.gateway.getConfiguration().getLogger().setLevel(Level.INFO); + this.gateway.getConfiguration().getLogger().setUseParentHandlers(false); + } +} diff --git a/src/test/java/com/braintreegateway/integrationtest/MerchantAccountIT.java b/src/test/java/com/braintreegateway/integrationtest/MerchantAccountIT.java index a14fbd8b..20239758 100644 --- a/src/test/java/com/braintreegateway/integrationtest/MerchantAccountIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/MerchantAccountIT.java @@ -1,7 +1,6 @@ package com.braintreegateway.integrationtest; import com.braintreegateway.*; -import org.junit.Before; import org.junit.Test; import com.braintreegateway.exceptions.NotFoundException; @@ -10,15 +9,7 @@ import static org.junit.Assert.*; -public class MerchantAccountIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", - "integration_private_key"); - } +public class MerchantAccountIT extends IntegrationTest { @Test public void deprecatedCreateSucceeds() { diff --git a/src/test/java/com/braintreegateway/integrationtest/MerchantIT.java b/src/test/java/com/braintreegateway/integrationtest/MerchantIT.java index 3c53fa64..00762fbf 100644 --- a/src/test/java/com/braintreegateway/integrationtest/MerchantIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/MerchantIT.java @@ -5,21 +5,22 @@ import com.braintreegateway.SandboxValues.TransactionAmount; import com.braintreegateway.test.Nonce; import com.braintreegateway.testhelpers.TestHelper; -import org.junit.Before; import org.junit.Test; +import org.junit.Before; import java.net.URL; import java.util.*; import static org.junit.Assert.*; -public class MerchantIT { - - private BraintreeGateway gateway; +public class MerchantIT extends IntegrationTest { @Before public void createGateway() { - this.gateway = new BraintreeGateway("client_id$development$integration_client_id", "client_secret$development$integration_client_secret"); + this.gateway = new BraintreeGateway( + "client_id$development$integration_client_id", + "client_secret$development$integration_client_secret" + ); } @Test diff --git a/src/test/java/com/braintreegateway/integrationtest/OAuthIT.java b/src/test/java/com/braintreegateway/integrationtest/OAuthIT.java index 8e81acda..e6387c4d 100644 --- a/src/test/java/com/braintreegateway/integrationtest/OAuthIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/OAuthIT.java @@ -2,21 +2,21 @@ import com.braintreegateway.*; import com.braintreegateway.testhelpers.TestHelper; -import org.junit.Before; import org.junit.Test; +import org.junit.Before; import java.util.*; import java.net.URL; import static org.junit.Assert.*; -public class OAuthIT { - - private BraintreeGateway gateway; +public class OAuthIT extends IntegrationTest { @Before public void createGateway() { - this.gateway = new BraintreeGateway("client_id$development$integration_client_id", "client_secret$development$integration_client_secret"); + this.gateway = new BraintreeGateway("client_id$development$integration_client_id", + "client_secret$development$integration_client_secret" + ); } @Test diff --git a/src/test/java/com/braintreegateway/integrationtest/PayPalAccountIT.java b/src/test/java/com/braintreegateway/integrationtest/PayPalAccountIT.java index d0bee7c9..a3b1037c 100644 --- a/src/test/java/com/braintreegateway/integrationtest/PayPalAccountIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/PayPalAccountIT.java @@ -4,20 +4,12 @@ import com.braintreegateway.*; import com.braintreegateway.testhelpers.TestHelper; import com.braintreegateway.exceptions.NotFoundException; -import org.junit.Before; import org.junit.Test; import java.util.Random; import static org.junit.Assert.*; -public class PayPalAccountIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class PayPalAccountIT extends IntegrationTest { @Test public void findsPayPalAccountsByToken() { diff --git a/src/test/java/com/braintreegateway/integrationtest/PaymentMethodIT.java b/src/test/java/com/braintreegateway/integrationtest/PaymentMethodIT.java index 5eebfce2..951d0a90 100644 --- a/src/test/java/com/braintreegateway/integrationtest/PaymentMethodIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/PaymentMethodIT.java @@ -6,19 +6,11 @@ import com.braintreegateway.testhelpers.TestHelper; import com.braintreegateway.exceptions.NotFoundException; import com.braintreegateway.test.Nonce; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; -public class PaymentMethodIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class PaymentMethodIT extends IntegrationTest { @Test public void createPayPalAccountWithNonce() { diff --git a/src/test/java/com/braintreegateway/integrationtest/PaymentMethodNonceIT.java b/src/test/java/com/braintreegateway/integrationtest/PaymentMethodNonceIT.java index b581dcd7..9027be16 100644 --- a/src/test/java/com/braintreegateway/integrationtest/PaymentMethodNonceIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/PaymentMethodNonceIT.java @@ -3,19 +3,11 @@ import com.braintreegateway.*; import com.braintreegateway.testhelpers.TestHelper; import com.braintreegateway.exceptions.NotFoundException; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; -public class PaymentMethodNonceIT { - - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class PaymentMethodNonceIT extends IntegrationTest { @Test public void createFromExistingPaymentMethod() { diff --git a/src/test/java/com/braintreegateway/integrationtest/PlanIT.java b/src/test/java/com/braintreegateway/integrationtest/PlanIT.java index c51095d7..d8c90503 100644 --- a/src/test/java/com/braintreegateway/integrationtest/PlanIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/PlanIT.java @@ -11,14 +11,12 @@ import static org.junit.Assert.assertEquals; -public class PlanIT { - private BraintreeGateway gateway; +public class PlanIT extends IntegrationTest { private Http http; @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - http = new Http(gateway.getConfiguration()); + public void createHttp() { + http = new Http(this.gateway.getConfiguration()); } @Test diff --git a/src/test/java/com/braintreegateway/integrationtest/SettlementBatchSummaryIT.java b/src/test/java/com/braintreegateway/integrationtest/SettlementBatchSummaryIT.java index ecabd4b2..ac57c4b3 100644 --- a/src/test/java/com/braintreegateway/integrationtest/SettlementBatchSummaryIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/SettlementBatchSummaryIT.java @@ -14,15 +14,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class SettlementBatchSummaryIT { +public class SettlementBatchSummaryIT extends IntegrationTest { - private BraintreeGateway gateway; private TimeZone eastern_timezone; @Before - public void createGateway() { + public void setTimezone() { this.eastern_timezone = TimeZone.getTimeZone("America/New_York"); - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); } @Test diff --git a/src/test/java/com/braintreegateway/integrationtest/SubscriptionIT.java b/src/test/java/com/braintreegateway/integrationtest/SubscriptionIT.java index 18f17296..c885c90b 100644 --- a/src/test/java/com/braintreegateway/integrationtest/SubscriptionIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/SubscriptionIT.java @@ -17,15 +17,13 @@ import static org.junit.Assert.*; -public class SubscriptionIT implements MerchantAccountTestConstants { +public class SubscriptionIT extends IntegrationTest implements MerchantAccountTestConstants { - private BraintreeGateway gateway; private Customer customer; private CreditCard creditCard; @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); + public void createCustomer() { CustomerRequest request = new CustomerRequest(); request. creditCard(). @@ -34,7 +32,7 @@ public void createGateway() { expirationDate("05/12"). done(); - Result result = gateway.customer().create(request); + Result result = this.gateway.customer().create(request); assertTrue(result.isSuccess()); this.customer = result.getTarget(); this.creditCard = customer.getCreditCards().get(0); diff --git a/src/test/java/com/braintreegateway/integrationtest/TestingGatewayIT.java b/src/test/java/com/braintreegateway/integrationtest/TestingGatewayIT.java index d58c0cb8..4edd2841 100644 --- a/src/test/java/com/braintreegateway/integrationtest/TestingGatewayIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/TestingGatewayIT.java @@ -11,7 +11,6 @@ import com.braintreegateway.testhelpers.TestHelper; import com.braintreegateway.testhelpers.ThreeDSecureRequestForTests; import com.braintreegateway.util.NodeWrapperFactory; -import org.junit.Before; import org.junit.Test; import java.math.BigDecimal; diff --git a/src/test/java/com/braintreegateway/integrationtest/TransactionIT.java b/src/test/java/com/braintreegateway/integrationtest/TransactionIT.java index 0246d7d4..f9be9a2e 100644 --- a/src/test/java/com/braintreegateway/integrationtest/TransactionIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/TransactionIT.java @@ -15,7 +15,6 @@ import com.braintreegateway.testhelpers.TestHelper; import com.braintreegateway.testhelpers.ThreeDSecureRequestForTests; import com.braintreegateway.util.NodeWrapperFactory; -import org.junit.Before; import org.junit.Test; import java.math.BigDecimal; @@ -24,18 +23,12 @@ import static org.junit.Assert.*; -public class TransactionIT implements MerchantAccountTestConstants { +public class TransactionIT extends IntegrationTest implements MerchantAccountTestConstants { - private BraintreeGateway gateway; public static final String DISBURSEMENT_TRANSACTION_ID = "deposittransaction"; public static final String DISPUTED_TRANSACTION_ID = "disputedtransaction"; public static final String TWO_DISPUTE_TRANSACTION_ID = "2disputetransaction"; - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } - @SuppressWarnings("deprecation") @Test public void transparentRedirectURLForCreate() { diff --git a/src/test/java/com/braintreegateway/integrationtest/TransparentRedirectIT.java b/src/test/java/com/braintreegateway/integrationtest/TransparentRedirectIT.java index 0a8ca204..a74cf027 100644 --- a/src/test/java/com/braintreegateway/integrationtest/TransparentRedirectIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/TransparentRedirectIT.java @@ -5,20 +5,13 @@ import com.braintreegateway.SandboxValues.TransactionAmount; import com.braintreegateway.testhelpers.MerchantAccountTestConstants; import com.braintreegateway.testhelpers.TestHelper; -import org.junit.Before; import org.junit.Test; import java.math.BigDecimal; import static org.junit.Assert.*; -public class TransparentRedirectIT implements MerchantAccountTestConstants { - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class TransparentRedirectIT extends IntegrationTest implements MerchantAccountTestConstants { @Test public void createTransactionFromTransparentRedirect() { diff --git a/src/test/java/com/braintreegateway/integrationtest/WebhookNotificationIT.java b/src/test/java/com/braintreegateway/integrationtest/WebhookNotificationIT.java index 30cddf66..d2cf1546 100644 --- a/src/test/java/com/braintreegateway/integrationtest/WebhookNotificationIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/WebhookNotificationIT.java @@ -11,7 +11,6 @@ import com.braintreegateway.util.NodeWrapper; import com.braintreegateway.util.NodeWrapperFactory; import com.braintreegateway.ValidationErrorCode; -import org.junit.Before; import org.junit.Test; import java.util.Calendar; @@ -20,13 +19,7 @@ import static org.junit.Assert.*; -public class WebhookNotificationIT { - private BraintreeGateway gateway; - - @Before - public void createGateway() { - this.gateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_id", "integration_public_key", "integration_private_key"); - } +public class WebhookNotificationIT extends IntegrationTest { @Test public void createNotificationWithUnrecognizedKind() { From ae684783d97b9f638ebc63e4d34cf030da89f269 Mon Sep 17 00:00:00 2001 From: Braintree Date: Mon, 29 Feb 2016 20:55:39 +0000 Subject: [PATCH 2/3] [maven-release-plugin] prepare release 2.57.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 15780402..39029304 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.braintreepayments.gateway braintree-java - 2.57.0-SNAPSHOT + 2.57.0 Java Client Library for Braintree Payments Gateway bundle Braintree Gateway Java Client Library From d2f00dfe725db07ef32810e42a11652f612d3516 Mon Sep 17 00:00:00 2001 From: Braintree Date: Mon, 29 Feb 2016 20:55:44 +0000 Subject: [PATCH 3/3] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 39029304..15780402 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.braintreepayments.gateway braintree-java - 2.57.0 + 2.57.0-SNAPSHOT Java Client Library for Braintree Payments Gateway bundle Braintree Gateway Java Client Library