diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorAccountInformationTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorAccountInformationTest.java deleted file mode 100644 index 2296ae8..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorAccountInformationTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.payxpert.connect2pay.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; - -import com.payxpert.connect2pay.client.requests.AccountInformationRequest; -import com.payxpert.connect2pay.client.response.AccountInformationResponse; -import com.payxpert.connect2pay.client.response.PaymentMethodInformation; -import com.payxpert.connect2pay.constants.ResultCode; - -public class ConnectorAccountInformationTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Account information request - * - */ - @Test - public void accountInformationTest() { - AccountInformationResponse response = null; - AccountInformationRequest infoRequest = new AccountInformationRequest(); - - try { - response = connector.getAccountInformation(infoRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(response); - assertNotNull(response.getCode()); - assertEquals(ResultCode.SUCCESS, response.getCode()); - assertEquals("002.60", response.getApiVersion()); - - // Don't test values in details as this is dependent on remote application configuration - assertNotNull(response.getName()); - assertNotNull(response.getDisplayTerms()); - assertNotNull(response.getMaxAttempts()); - assertNotNull(response.getNotificationSenderName()); - assertNotNull(response.getNotificationSenderEmail()); - assertNotNull(response.getNotificationOnSuccess()); - assertNotNull(response.getNotificationOnFailure()); - assertNotNull(response.getMerchantNotification()); - assertNotNull(response.getMerchantNotificationTo()); - assertNotNull(response.getMerchantNotificationLang()); - - List paymentMethods = response.getPaymentMethods(); - - assertNotNull(paymentMethods); - assertTrue(paymentMethods.size() > 0); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorBasicTransactionTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorBasicTransactionTest.java deleted file mode 100644 index 26117e5..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorBasicTransactionTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.payxpert.connect2pay.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; - -import com.payxpert.connect2pay.client.requests.PaymentRequestTest; -import com.payxpert.connect2pay.client.response.PaymentResponse; -import com.payxpert.connect2pay.constants.ResultCode; - -public class ConnectorBasicTransactionTest extends ConnectorTransactionTest { - /** - * Test with an invalid originator - */ - @Test - public void transactionWithBadOriginator() { - this.connector = new Connect2payClient(TEST_URL, "9999999", DEFAULT_PASSWORD); - - PaymentResponse response = null; - - try { - response = connector.preparePayment(PaymentRequestTest.getDefaultRequest()); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(response); - assertEquals(ResultCode.AUTH_FAILED, response.getCode()); - } - - /** - * Test with an invalid password - */ - @Test - public void transactionWithBadPassword() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, "AZERTY"); - - PaymentResponse response = null; - - try { - response = connector.preparePayment(PaymentRequestTest.getDefaultRequest()); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(response); - assertEquals(ResultCode.AUTH_FAILED, response.getCode()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorConnectionTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorConnectionTest.java deleted file mode 100644 index 077c1fb..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorConnectionTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.payxpert.connect2pay.client; - -import static org.junit.Assert.fail; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.payxpert.connect2pay.client.requests.PaymentRequestTest; -import com.payxpert.connect2pay.client.response.PaymentResponse; - -public class ConnectorConnectionTest extends ConnectorTransactionTest { - private static final String TEST_URL = "https://10.1.222.222"; - private static final Integer TIMEOUT = 5000; - - private static final Logger logger = LoggerFactory.getLogger(ConnectorConnectionTest.class); - - /** - * Test the connection fails to invalid IP address - */ - @Test - public void connection2InvalidIpAddressFails() { - Connect2payClient connector = new Connect2payClient("https://127.0.0.255", DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - long duration = 0; - connector.setTimeOutInMilliSeconds(TIMEOUT); - PaymentResponse response = null; - - long start = System.currentTimeMillis(); - - try { - response = connector.preparePayment(PaymentRequestTest.getDefaultRequest()); - // This must not be executed - Assert.assertNotNull(null); - } catch (Exception e) { - logger.info("connection2InvalidIpAddressFails, catched error : " + e.getMessage()); - Assert.assertTrue(e.getMessage().startsWith("java.net.ConnectException:")); - } - - duration = (System.currentTimeMillis() - start); - logger.info("connection2InvalidIpAddressFails : Execution time was " + duration + " ms."); - Assert.assertNull(response); - } - - /** - * Test the connection fails to a unknown host - */ - @Test - public void connection2UnknowHost() { - Connect2payClient connector = new Connect2payClient("https://UnknownHostException.payxpert.com", DEFAULT_ORIGINATOR, - DEFAULT_PASSWORD); - - connector.setTimeOutInMilliSeconds(TIMEOUT); - PaymentResponse response = null; - long duration = 0; - - long start = System.currentTimeMillis(); - - try { - response = connector.preparePayment(PaymentRequestTest.getDefaultRequest()); - // This must not be executed - fail("Exception not present: An Exception must have been thrown"); - } catch (Exception e) { - logger.info("connection2UnknowHost, catched error : " + e.getMessage()); - Assert.assertTrue(e.getMessage().startsWith("java.net.UnknownHostException: UnknownHostException.payxpert.com")); - } - - duration = (System.currentTimeMillis() - start); - logger.info("connection2UnknowHost: Execution time was " + duration + " ms."); - Assert.assertNull(response); - } - - /** - * Test the connection fails to a host unreachable - */ - @Test - public void connection2HostUnreachable() { - Connect2payClient connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - - connector.setTimeOutInMilliSeconds(TIMEOUT); - PaymentResponse response = null; - long duration = 0; - long start = System.currentTimeMillis(); - - try { - response = connector.preparePayment(PaymentRequestTest.getDefaultRequest()); - // This must not be executed - Assert.assertNotNull(null); - } catch (Exception e) { - String errorMessage = ""; - URL url = null; - try { - url = new URL(TEST_URL); - } catch (MalformedURLException e1) { - fail(String.format("Cannot resolve the URL: %s. Details: %s", TEST_URL, e.getMessage())); - } - errorMessage = String.format("java.net.ConnectException: connection timed out: /%s:%d", url.getHost(), - url.getDefaultPort()); - if (!errorMessage.equals(e.getMessage())) { - logger.error( - "To run this test, the URL " + TEST_URL + " must not be on a directly attached network (or change it)."); - } - Assert.assertEquals(errorMessage, e.getMessage()); - } - - duration = (System.currentTimeMillis() - start); - logger.info("connection2HostUnreachable: Execution time was " + duration + " ms."); - Assert.assertNull(response); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorHandleCallbackTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorHandleCallbackTest.java deleted file mode 100644 index be59cd9..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorHandleCallbackTest.java +++ /dev/null @@ -1,376 +0,0 @@ -package com.payxpert.connect2pay.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; - -import com.fasterxml.jackson.databind.exc.InvalidFormatException; -import com.payxpert.connect2pay.client.containers.BankAccount; -import com.payxpert.connect2pay.client.containers.BankTransferPaymentMeanInfo; -import com.payxpert.connect2pay.client.containers.CreditCardPaymentMeanInfo; -import com.payxpert.connect2pay.client.containers.Shopper; -import com.payxpert.connect2pay.client.containers.TransactionAttempt; -import com.payxpert.connect2pay.client.response.PaymentStatusResponse; -import com.payxpert.connect2pay.constants.PaymentMethod; -import com.payxpert.connect2pay.constants.ResultCode; -import com.payxpert.connect2pay.constants.TransactionOperation; -import com.payxpert.connect2pay.constants.PaymentStatusValue; - -public class ConnectorHandleCallbackTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Successful callback data handling - */ - @Test - public void handleCallbackCreditTestSuccessfull() { - StringBuilder receivedData = new StringBuilder(); - receivedData.append('{'); - receivedData.append("\"merchantToken\":").append("\"2NmIsxITW2hrzAowK44nZA\""); - receivedData.append(",\"operation\":").append("\"sale\""); - receivedData.append(",\"errorCode\":").append("\"000\""); - receivedData.append(",\"errorMessage\":").append("\"Transaction successfully completed\""); - receivedData.append(",\"status\":").append("\"Authorized\""); - receivedData.append(",\"ctrlCustomData\":").append("\"Give that back to me please !!\""); - receivedData.append(",\"orderID\":").append("\"2014-04-02-14.32.45\""); - receivedData.append(",\"currency\":").append("\"EUR\""); - receivedData.append(",\"amount\":").append("1000"); - - receivedData.append(",\"transactions\":["); - receivedData.append('{'); - receivedData.append("\"paymentType\":").append("\"CreditCard\""); - receivedData.append(",\"paymentMeanInfo\":"); - receivedData.append('{'); - receivedData.append("\"cardNumber\":").append("\"411111XXXXXX1111\""); - receivedData.append(",\"cardExpireYear\":").append("\"2024\""); - receivedData.append(",\"cardExpireMonth\":").append("\"10\""); - receivedData.append(",\"cardHolderName\":").append("\"Tech Payxpert\""); - receivedData.append(",\"cardBrand\":").append("\"VISA\""); - receivedData.append(",\"cardLevel\":").append("\"other\""); - receivedData.append(",\"cardSubType\":").append("\"credit\""); - receivedData.append(",\"iinCountry\":").append("\"US\""); - receivedData.append(",\"iinBankName\":").append("\"jpmorgan chase bank na\""); - receivedData.append(",\"is3DSecure\":").append("false"); - receivedData.append(",\"statementDescriptor\":").append("\"My statement\""); - receivedData.append('}'); - - receivedData.append(",\"shopper\":"); - receivedData.append('{'); - - receivedData.append("\"name\":").append("\"Tech Payxpert\""); - receivedData.append(",\"address\":").append("\"NA\""); - receivedData.append(",\"zipcode\":").append("\"NA\""); - receivedData.append(",\"city\":").append("\"Barcelona\""); - receivedData.append(",\"state\":").append("\"barcelona\""); - receivedData.append(",\"countryCode\":").append("\"FR\""); - receivedData.append(",\"phone\":").append("\"+34666666666\""); - receivedData.append(",\"email\":").append("\"support@payxpert.com\""); - receivedData.append(",\"birthDate\":").append("\"20160808\""); - receivedData.append(",\"idNumber\":").append("\"ABC123456\""); - receivedData.append(",\"ipAddress\":").append("\"127.0.0.1\""); - receivedData.append('}'); - - receivedData.append(",\"operation\":").append("\"sale\""); - receivedData.append(",\"resultCode\":").append("\"000\""); - receivedData.append(",\"resultMessage\":").append("\"Transaction successfully completed\""); - receivedData.append(",\"status\":").append("\"Authorized\""); - - receivedData.append(",\"transactionID\":").append("\"18253\""); - receivedData.append(",\"subscriptionID\":").append("null"); - receivedData.append('}'); - receivedData.append(']'); - receivedData.append('}'); - - PaymentStatusResponse response = null; - try { - response = connector.handleCallbackStatus(receivedData.toString()); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(response); - assertNotNull(response.getMerchantToken()); - - assertEquals(ResultCode.SUCCESS, response.getCode()); - assertNull(response.getMessage()); - - assertEquals("2NmIsxITW2hrzAowK44nZA", response.getMerchantToken()); - assertEquals("000", response.getErrorCode()); - assertEquals("Transaction successfully completed", response.getErrorMessage()); - - assertEquals(TransactionOperation.SALE, response.getOperation()); - assertEquals(PaymentStatusValue.AUTHORIZED, response.getStatus()); - assertEquals("Give that back to me please !!", response.getCtrlCustomData()); - assertEquals("2014-04-02-14.32.45", response.getOrderId()); - - assertEquals("EUR", response.getCurrency()); - assertEquals(Integer.valueOf(1000), response.getAmount()); - assertEquals("2014-04-02-14.32.45", response.getOrderId()); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(1, transactionAttempts.size()); - - TransactionAttempt transactionAttempt = transactionAttempts.get(0); - assertNotNull(transactionAttempt); - - assertEquals(PaymentMethod.CREDIT_CARD, transactionAttempt.getPaymentType()); - assertEquals("18253", transactionAttempt.getTransactionId()); - assertEquals(TransactionOperation.SALE, transactionAttempt.getOperation()); - assertEquals("000", transactionAttempt.getResultCode()); - assertEquals("Transaction successfully completed", transactionAttempt.getResultMessage()); - assertEquals(PaymentStatusValue.AUTHORIZED, transactionAttempt.getStatus()); - assertEquals("18253", transactionAttempt.getTransactionId()); - assertNull(transactionAttempt.getSubscriptionId()); - - CreditCardPaymentMeanInfo pmInfo = transactionAttempt.getCreditCardPaymentMeanInfo(); - assertNotNull(pmInfo); - assertEquals("411111XXXXXX1111", pmInfo.getCardNumber()); - assertEquals("2024", pmInfo.getCardExpireYear()); - assertEquals("10", pmInfo.getCardExpireMonth()); - assertEquals("Tech Payxpert", pmInfo.getCardHolderName()); - assertEquals("VISA", pmInfo.getCardBrand()); - assertEquals("other", pmInfo.getCardLevel()); - assertEquals("credit", pmInfo.getCardSubType()); - assertEquals("US", pmInfo.getIinCountry()); - assertEquals("jpmorgan chase bank na", pmInfo.getIinBankName()); - assertEquals("My statement", pmInfo.getStatementDescriptor()); - assertFalse(pmInfo.getIs3DSecure()); - - Shopper shopper = transactionAttempt.getShopper(); - assertNotNull(shopper); - - assertEquals("Tech Payxpert", shopper.getName()); - assertEquals("NA", shopper.getAddress()); - assertEquals("NA", shopper.getZipcode()); - assertEquals("Barcelona", shopper.getCity()); - assertEquals("barcelona", shopper.getState()); - assertEquals("FR", shopper.getCountryCode()); - assertEquals("+34666666666", shopper.getPhone()); - assertEquals("support@payxpert.com", shopper.getEmail()); - assertEquals("20160808", shopper.getBirthDate()); - assertEquals("ABC123456", shopper.getIdNumber()); - assertEquals("127.0.0.1", shopper.getIpAddress()); - } - - /** - * Successful callback data handling - */ - @Test - public void handleCallbackBankTransferTestSuccessfull() { - StringBuilder receivedData = new StringBuilder(); - receivedData.append('{'); - receivedData.append("\"merchantToken\":").append("\"2NmIsxITW2hrzAowK44nZA\""); - receivedData.append(",\"operation\":").append("\"sale\""); - receivedData.append(",\"errorCode\":").append("\"000\""); - receivedData.append(",\"errorMessage\":").append("\"Transaction successfully completed\""); - receivedData.append(",\"status\":").append("\"Authorized\""); - receivedData.append(",\"ctrlCustomData\":").append("\"Give that back to me please !!\""); - receivedData.append(",\"orderID\":").append("\"2014-04-02-14.32.45\""); - receivedData.append(",\"currency\":").append("\"EUR\""); - receivedData.append(",\"amount\":").append("1000"); - - receivedData.append(",\"transactions\":["); - receivedData.append('{'); - receivedData.append("\"paymentType\":").append("\"BankTransfer\""); - receivedData.append(",\"paymentMeanInfo\":"); - receivedData.append('{'); - receivedData.append("\"sender\":"); - receivedData.append('{'); - receivedData.append("\"holderName\":").append("\"Henry\""); - receivedData.append(",\"bankName\":").append("\"Bnp\""); - receivedData.append(",\"iban\":").append("\"FR 2024 554 5454545 45\""); - receivedData.append(",\"bic\":").append("\"TFEE4445454\""); - receivedData.append(",\"countryCode\":").append("\"FR\""); - receivedData.append('}'); - receivedData.append(",\"recipient\":"); - receivedData.append('{'); - receivedData.append("\"holderName\":").append("\"Guibet\""); - receivedData.append(",\"bankName\":").append("\"HSBC\""); - receivedData.append(",\"iban\":").append("\"UK 2555 2555 6655 4545\""); - receivedData.append(",\"bic\":").append("\"ERDD545454\""); - receivedData.append(",\"countryCode\":").append("\"UK\""); - receivedData.append('}'); - receivedData.append('}'); - - receivedData.append(",\"shopper\":"); - receivedData.append('{'); - receivedData.append("\"name\":").append("\"Tech Payxpert\""); - receivedData.append(",\"address\":").append("\"NA\""); - receivedData.append(",\"zipcode\":").append("\"NA\""); - receivedData.append(",\"city\":").append("\"Barcelona\""); - receivedData.append(",\"state\":").append("\"barcelona\""); - receivedData.append(",\"countryCode\":").append("\"FR\""); - receivedData.append(",\"phone\":").append("\"+34666666666\""); - receivedData.append(",\"email\":").append("\"support@payxpert.com\""); - receivedData.append(",\"birthDate\":").append("\"20160808\""); - receivedData.append(",\"idNumber\":").append("\"ABC123456\""); - receivedData.append(",\"ipAddress\":").append("\"127.0.0.1\""); - receivedData.append('}'); - - receivedData.append(",\"operation\":").append("\"sale\""); - receivedData.append(",\"resultCode\":").append("\"000\""); - receivedData.append(",\"resultMessage\":").append("\"Transaction successfully completed\""); - receivedData.append(",\"status\":").append("\"Authorized\""); - - receivedData.append(",\"transactionID\":").append("\"18253\""); - receivedData.append(",\"subscriptionID\":").append("null"); - receivedData.append('}'); - receivedData.append(']'); - receivedData.append('}'); - - PaymentStatusResponse response = null; - try { - response = connector.handleCallbackStatus(receivedData.toString()); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(response); - assertNotNull(response.getMerchantToken()); - - assertEquals(ResultCode.SUCCESS, response.getCode()); - assertNull(response.getMessage()); - - assertEquals("2NmIsxITW2hrzAowK44nZA", response.getMerchantToken()); - assertEquals("000", response.getErrorCode()); - assertEquals("Transaction successfully completed", response.getErrorMessage()); - - assertEquals(TransactionOperation.SALE, response.getOperation()); - assertEquals(PaymentStatusValue.AUTHORIZED, response.getStatus()); - assertEquals("Give that back to me please !!", response.getCtrlCustomData()); - assertEquals("2014-04-02-14.32.45", response.getOrderId()); - - assertEquals("EUR", response.getCurrency()); - assertEquals(Integer.valueOf(1000), response.getAmount()); - assertEquals("2014-04-02-14.32.45", response.getOrderId()); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(1, transactionAttempts.size()); - - TransactionAttempt transactionAttempt = transactionAttempts.get(0); - assertNotNull(transactionAttempt); - - assertEquals(PaymentMethod.BANK_TRANSFER, transactionAttempt.getPaymentType()); - assertEquals("18253", transactionAttempt.getTransactionId()); - assertEquals(TransactionOperation.SALE, transactionAttempt.getOperation()); - assertEquals("000", transactionAttempt.getResultCode()); - assertEquals("Transaction successfully completed", transactionAttempt.getResultMessage()); - assertEquals(PaymentStatusValue.AUTHORIZED, transactionAttempt.getStatus()); - assertEquals("18253", transactionAttempt.getTransactionId()); - assertNull(transactionAttempt.getSubscriptionId()); - - BankTransferPaymentMeanInfo pmInfo = transactionAttempt.getBankTransferPaymentMeanInfo(); - assertNotNull(pmInfo); - - BankAccount senderBankAccount = pmInfo.getSender(); - assertNotNull(senderBankAccount); - - assertEquals("Henry", senderBankAccount.getHolderName()); - assertEquals("Bnp", senderBankAccount.getBankName()); - assertEquals("FR 2024 554 5454545 45", senderBankAccount.getIban()); - assertEquals("TFEE4445454", senderBankAccount.getBic()); - assertEquals("FR", senderBankAccount.getCountryCode()); - - BankAccount recipientBankAccount = pmInfo.getRecipient(); - assertNotNull(recipientBankAccount); - assertEquals("Guibet", recipientBankAccount.getHolderName()); - assertEquals("HSBC", recipientBankAccount.getBankName()); - assertEquals("UK 2555 2555 6655 4545", recipientBankAccount.getIban()); - assertEquals("ERDD545454", recipientBankAccount.getBic()); - assertEquals("UK", recipientBankAccount.getCountryCode()); - - Shopper shopper = transactionAttempt.getShopper(); - assertNotNull(shopper); - - assertEquals("Tech Payxpert", shopper.getName()); - assertEquals("NA", shopper.getAddress()); - assertEquals("NA", shopper.getZipcode()); - assertEquals("Barcelona", shopper.getCity()); - assertEquals("barcelona", shopper.getState()); - assertEquals("FR", shopper.getCountryCode()); - assertEquals("+34666666666", shopper.getPhone()); - assertEquals("support@payxpert.com", shopper.getEmail()); - assertEquals("20160808", shopper.getBirthDate()); - assertEquals("ABC123456", shopper.getIdNumber()); - assertEquals("127.0.0.1", shopper.getIpAddress()); - } - - /** - * Callback data handling with incorrect value - * - * @throws Exception - * - */ - @Test(expected = InvalidFormatException.class) - public void handleCallbackTestInvalidData() throws Exception { - StringBuilder receivedData = new StringBuilder(); - receivedData.append('{'); - receivedData.append("\"merchantToken\":").append("\"2NmIsxITW2hrzAowK44nZA\""); - receivedData.append(",\"operation\":").append("\"sale\""); - receivedData.append(",\"errorCode\":").append("\"000\""); - receivedData.append(",\"errorMessage\":").append("\"Transaction successfully completed\""); - receivedData.append(",\"status\":").append("\"Authorized\""); - receivedData.append(",\"ctrlCustomData\":").append("\"Give that back to me please !!\""); - receivedData.append(",\"orderID\":").append("\"2014-04-02-14.32.45\""); - receivedData.append(",\"currency\":").append("\"EUR\""); - receivedData.append(",\"amount\":").append("1000"); - - receivedData.append(",\"transactions\":["); - receivedData.append('{'); - receivedData.append("\"paymentType\":").append("\"CreditCardZZZ\""); - receivedData.append(",\"paymentMeanInfo\":"); - receivedData.append('{'); - receivedData.append("\"cardNumber\":").append("\"411111XXXXXX1111\""); - receivedData.append(",\"cardExpireYear\":").append("\"2024\""); - receivedData.append(",\"cardExpireMonth\":").append("\"10\""); - receivedData.append(",\"cardHolderName\":").append("\"Tech Payxpert\""); - receivedData.append(",\"cardBrand\":").append("\"VISA\""); - receivedData.append(",\"cardLevel\":").append("\"other\""); - receivedData.append(",\"cardSubType\":").append("\"credit\""); - receivedData.append(",\"iinCountry\":").append("\"US\""); - receivedData.append(",\"iinBankName\":").append("\"jpmorgan chase bank na\""); - receivedData.append(",\"is3DSecure\":").append("false"); - receivedData.append(",\"statementDescriptor\":").append("\"My statement\""); - receivedData.append('}'); - - receivedData.append(",\"shopper\":"); - receivedData.append('{'); - - receivedData.append("\"name\":").append("\"Tech Payxpert\""); - receivedData.append(",\"address\":").append("\"NA\""); - receivedData.append(",\"zipcode\":").append("\"NA\""); - receivedData.append(",\"city\":").append("\"Barcelona\""); - receivedData.append(",\"state\":").append("\"barcelona\""); - receivedData.append(",\"countryCode\":").append("\"FR\""); - receivedData.append(",\"phone\":").append("\"+34666666666\""); - receivedData.append(",\"email\":").append("\"support@payxpert.com\""); - receivedData.append(",\"birthDate\":").append("\"20160808\""); - receivedData.append(",\"idNumber\":").append("\"ABC123456\""); - receivedData.append(",\"ipAddress\":").append("\"127.0.0.1\""); - receivedData.append('}'); - - receivedData.append(",\"operation\":").append("\"sale\""); - receivedData.append(",\"resultCode\":").append("\"000\""); - receivedData.append(",\"resultMessage\":").append("\"Transaction successfully completed\""); - receivedData.append(",\"status\":").append("\"Authorized\""); - - receivedData.append(",\"transactionID\":").append("\"18253\""); - receivedData.append(",\"subscriptionID\":").append("null"); - receivedData.append('}'); - receivedData.append(']'); - receivedData.append('}'); - - connector.handleCallbackStatus(receivedData.toString()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorHandleRedirectTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorHandleRedirectTest.java deleted file mode 100644 index eda9e19..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorHandleRedirectTest.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.payxpert.connect2pay.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.security.InvalidKeyException; -import java.util.List; - -import javax.crypto.IllegalBlockSizeException; - -import org.junit.Before; -import org.junit.Test; - -import com.payxpert.connect2pay.client.containers.Shopper; -import com.payxpert.connect2pay.client.containers.TransactionAttempt; -import com.payxpert.connect2pay.client.response.PaymentStatusResponse; -import com.payxpert.connect2pay.constants.PaymentMethod; -import com.payxpert.connect2pay.constants.ResultCode; -import com.payxpert.connect2pay.utils.CryptoHelper; - -public class ConnectorHandleRedirectTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Successful redirect data handling - */ - @Test - public void handleRedirectTestSuccessfull() { - String merchantToken = "W2n1yR8UXNJBrJxbsqOy3g"; - String encryptedData = this.getEncryptedData(merchantToken); - PaymentStatusResponse response = null; - try { - response = connector.handleRedirectStatus(encryptedData, merchantToken); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(response); - assertNotNull(response.getMerchantToken()); - assertEquals(merchantToken, response.getMerchantToken()); - assertEquals(ResultCode.SUCCESS, response.getCode()); - - assertEquals("000", response.getErrorCode()); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(1, transactionAttempts.size()); - - TransactionAttempt transactionAttempt = transactionAttempts.get(0); - assertEquals(PaymentMethod.CREDIT_CARD, transactionAttempt.getPaymentType()); - - Shopper shopper = transactionAttempt.getShopper(); - assertNotNull(shopper); - assertEquals("Bernard Menez", shopper.getName()); - assertEquals("bernard.menez@gmail.com", shopper.getEmail()); - } - - /** - * Redirect data handling with incorrect key - * - * @throws Exception - * - */ - @Test(expected = InvalidKeyException.class) - public void handleRedirectTestInvalidKey() throws Exception { - String merchantToken = "W2n1yR8UXNJBrJxbsqOy3g"; - String encryptedData = this.getEncryptedData("W2n1yR8UXNJBrJxbsqOy3g"); - // Set an invalid Key - merchantToken = "W2n1yR8UXNJBrJxbsqOy"; - - PaymentStatusResponse response = connector.handleRedirectStatus(encryptedData, merchantToken); - - assertNull(response); - } - - /** - * Redirect data handling with incorrect data - * - * @throws Exception - */ - @Test(expected = IllegalBlockSizeException.class) - public void handleRedirectTestInvalidData() throws Exception { - String merchantToken = "W2n1yR8UXNJBrJxbsqOy3g"; - String encryptedData = this.getEncryptedData(merchantToken); - encryptedData = encryptedData.substring(0, encryptedData.length() - 5); - - PaymentStatusResponse response = connector.handleRedirectStatus(encryptedData, merchantToken); - - assertNull(response); - } - - public String getEncryptedData(String key) { - StringBuilder strBuilderStatus = new StringBuilder(); - strBuilderStatus.append('{'); - strBuilderStatus.append("\"transactions\":"); - strBuilderStatus.append('['); - strBuilderStatus.append('{'); - strBuilderStatus.append("\"paymentType\":\"CreditCard\""); - strBuilderStatus.append(",\"paymentMeanInfo\":"); - strBuilderStatus.append('{'); - strBuilderStatus.append("\"cardHolderName\":\"Bernard Ménez\""); - strBuilderStatus.append(",\"is3DSecure\":false}"); - strBuilderStatus.append(",\"shopper\":"); - strBuilderStatus.append('{'); - strBuilderStatus.append("\"name\":\"Bernard Menez\""); - strBuilderStatus.append(",\"address\":\"Passeig de Gracia, 55\""); - strBuilderStatus.append(",\"zipcode\":\"08008\""); - strBuilderStatus.append(",\"city\":\"Barcelona\""); - strBuilderStatus.append(",\"state\":\"Barcelona\""); - strBuilderStatus.append(",\"countryCode\":\"ES\""); - strBuilderStatus.append(",\"phone\":\"+34666666666\""); - strBuilderStatus.append(",\"email\":\"bernard.menez@gmail.com\""); - strBuilderStatus.append(",\"birthDate\":\"19700101\""); - strBuilderStatus.append(",\"idNumber\":\"ID12345\""); - strBuilderStatus.append('}'); - strBuilderStatus.append(",\"operation\":\"sale\""); - strBuilderStatus.append('}'); - strBuilderStatus.append(']'); - strBuilderStatus.append(",\"merchantToken\":\"W2n1yR8UXNJBrJxbsqOy3g\""); - strBuilderStatus.append(",\"paymentType\":\"CreditCard\""); - strBuilderStatus.append(",\"operation\":\"sale\""); - strBuilderStatus.append(",\"errorCode\":\"000\""); - strBuilderStatus.append(",\"status\":\"Not processed\""); - strBuilderStatus.append(",\"orderId\":\"20170505155125300\""); - strBuilderStatus.append(",\"currency\":\"EUR\""); - strBuilderStatus.append(",\"amount\":100"); - strBuilderStatus.append('}'); - - try { - return CryptoHelper.encryptAESURLBase64(strBuilderStatus.toString().getBytes("utf-8"), - CryptoHelper.fromBase64(key)); - } catch (Exception e1) { - } - - return "C1w0nrYb6B_2yc3mheyRX9vXvuIr2b3-OZSM8RKzKJqYVZlHOPa4seVUmBOeTJ49xqlPR9DoUskBQsyEzTs74rQYdEDqwYk0n4Vac4wF3t_FxkG-GNd2sBcTmrKaeJXLnRuKP1KHHEIi-fZTzwe5pNnOon4bgxJJF_L-PuSHq4xs2P6OJjCUPW_pg3s9bRxdJKHAYaV11EOfwmX_O0dSIyPMCBhOGilmeC7obVY1ePYUW_9w1SgGMZJBslm6LYT3g_adsb2FxfUErJM9wH1eHjAQCG-OJbKx7Ii_4xzMDYM7a3V8DwZZPXBXW9EQI9kQLY2M9kD65uKYvFZd-bmTSAM03n5_bcyUtSznlIG3jE6ZMQmBwDcHAXKzpjtVTqAMa_VfRe-YhGVNdGRebxLjc_Ko96xHxJfMgai6k5P5mCNqIYEDvcCCqHlUU7LCY7yjJSBdAlG-AUPjy62Jmy-G_AHcrFycVgcl4IMvxhaS3Oll2h1ismzU_7qy7XQzcWyDKY8SLuYEoJdQ1u0mTO-u9WlmlQI13Gtwt9V0zDJsWwV8uIaUStX0CFMNDTxAFc8bQIsTST1s1GTb5vJ6vhA4Yawc_kkvfTn43GShjBoy6ahiUID02K6v7qZQrkluOcPT5REyVBFre6BQdDYFzCbAblMQQnD_CBquK7yFHDq8Cu4uJ5LTA_I2ZFtJpatNm1_eqen7QhFLpGZXrrU-rIK9grb44-RximkMjgi5rbropALtPXr5nA3RWZTaHr5h_Lw675pXHJfaf9piOpazuJ45m5RyHk7tgW0u2cf6NYuESt-ozXDyf59XLneSERlt24btK5UE3bB7AfKUQRp10"; - - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorPaymentStatusTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorPaymentStatusTest.java deleted file mode 100644 index f47587f..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorPaymentStatusTest.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.payxpert.connect2pay.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; - -import com.payxpert.connect2pay.client.containers.TransactionAttempt; -import com.payxpert.connect2pay.client.requests.PaymentRequest; -import com.payxpert.connect2pay.client.requests.PaymentStatusRequest; -import com.payxpert.connect2pay.client.requests.PaymentRequestTest; -import com.payxpert.connect2pay.client.response.PaymentResponse; -import com.payxpert.connect2pay.client.response.PaymentStatusResponse; -import com.payxpert.connect2pay.constants.PaymentStatusValue; -import com.payxpert.connect2pay.constants.ResultCode; - -public class ConnectorPaymentStatusTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Successful payment status request (creation + status) - */ - @Test - public void paymentStatusTestSuccessfull() { - PaymentResponse response = null; - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - - try { - response = connector.preparePayment(request); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(response); - assertNotNull(response.getMerchantToken()); - assertEquals(ResultCode.SUCCESS, response.getCode()); - - PaymentStatusResponse statusResponse = null; - PaymentStatusRequest statusRequest = new PaymentStatusRequest(); - statusRequest.setMerchantToken(response.getMerchantToken()); - - try { - statusResponse = connector.getPaymentStatus(statusRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(statusResponse); - assertNotNull(statusResponse.getCode()); - assertEquals(ResultCode.SUCCESS, statusResponse.getCode()); - assertEquals(PaymentStatusValue.NOT_PROCESSED, statusResponse.getStatus()); - - List transactionAttempts = statusResponse.getTransactions(); - assertNotNull(transactionAttempts); - // API does not return not processed transaction - assertEquals(0, transactionAttempts.size()); - - // TODO: process the transaction and check updated status - } - - /** - * Successful payment status request (creation + status) with an old API version - */ - @Test - public void paymentStatusTestSuccessfullOldApiVersion() { - PaymentResponse response = null; - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - - try { - response = connector.preparePayment(request); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(response); - assertNotNull(response.getMerchantToken()); - assertEquals(ResultCode.SUCCESS, response.getCode()); - - PaymentStatusResponse statusResponse = null; - PaymentStatusRequest statusRequest = new PaymentStatusRequest(); - statusRequest.setMerchantToken(response.getMerchantToken()); - statusRequest.setApiVersion("002"); - - try { - statusResponse = connector.getPaymentStatus(statusRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(statusResponse); - assertNotNull(statusResponse.getCode()); - assertEquals(ResultCode.SUCCESS, statusResponse.getCode()); - assertEquals(PaymentStatusValue.NOT_PROCESSED, statusResponse.getStatus()); - } - - /** - * Payment status request with an invalid merchant token - * - */ - @Test - public void paymentStatusTestInvalidToken() { - PaymentStatusResponse statusResponse = null; - PaymentStatusRequest statusRequest = new PaymentStatusRequest(); - statusRequest.setMerchantToken("666999666"); - - try { - statusResponse = connector.getPaymentStatus(statusRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(statusResponse); - assertNotNull(statusResponse.getCode()); - assertEquals(ResultCode.NOT_FOUND, statusResponse.getCode()); - - List transactionAttempts = statusResponse.getTransactions(); - assertNull(transactionAttempts); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorPrepareTransactionTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorPrepareTransactionTest.java deleted file mode 100644 index 7a1f575..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorPrepareTransactionTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.payxpert.connect2pay.client; - -import org.junit.Assert; -import org.junit.Test; - -import com.payxpert.connect2pay.client.requests.PaymentRequest; -import com.payxpert.connect2pay.client.requests.PaymentRequestTest; -import com.payxpert.connect2pay.client.response.PaymentResponse; -import com.payxpert.connect2pay.constants.ResultCode; - -public class ConnectorPrepareTransactionTest extends ConnectorTransactionTest { - /** - * Test with a card number considered as valid by the Payment Gateway Test Provider - */ - @Test - public void prepareTransactionTestSuccessfull() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - PaymentResponse response = null; - - try { - response = this.connector.preparePayment(PaymentRequestTest.getDefaultRequest()); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(response); - Assert.assertEquals(ResultCode.SUCCESS, response.getCode()); - Assert.assertNotNull(response.getMerchantToken()); - Assert.assertNotNull(response.getCustomerToken()); - Assert.assertEquals(TEST_URL + "/payment/" + response.getCustomerToken(), response.getCustomerRedirectURL()); - } - - /** - * Test with invalid credentials - */ - @Test - public void prepareTransactionAuthFailed() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, "BadPassword"); - PaymentResponse response = null; - - try { - response = this.connector.preparePayment(PaymentRequestTest.getDefaultRequest()); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(response); - Assert.assertEquals(ResultCode.AUTH_FAILED, response.getCode()); - Assert.assertNull(response.getMerchantToken()); - Assert.assertNull(response.getCustomerToken()); - } - - /** - * Test with an invalid request - * - */ - @Test - public void prepareTransactionTestInvalidRequest() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - PaymentResponse response = null; - - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - request.setCurrency(null); - - try { - response = this.connector.preparePayment(request); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(response); - Assert.assertEquals(ResultCode.DATA_MISSING_PARAMETER, response.getCode()); - Assert.assertNull(response.getMerchantToken()); - Assert.assertNull(response.getCustomerToken()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorSubscriptionCancelTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorSubscriptionCancelTest.java deleted file mode 100644 index 7c15c3c..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorSubscriptionCancelTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.payxpert.connect2pay.client; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import com.payxpert.connect2pay.client.Connect2payClient; -import com.payxpert.connect2pay.client.requests.SubscriptionCancelRequest; -import com.payxpert.connect2pay.client.response.SubscriptionCancelResponse; -import com.payxpert.connect2pay.constants.ResultCode; -import com.payxpert.connect2pay.constants.SubscriptionCancelReason; - -public class ConnectorSubscriptionCancelTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Subscription cancel request with an invalid ID - * - */ - @Test - public void subscriptionCancelTestInvalidId() { - SubscriptionCancelResponse cancelResponse = null; - SubscriptionCancelRequest cancelRequest = new SubscriptionCancelRequest(); - cancelRequest.setSubscriptionId(666999666L); - cancelRequest.setCancelReason(SubscriptionCancelReason.CHARGEBACK); - - try { - cancelResponse = connector.cancelSubscription(cancelRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(cancelResponse); - Assert.assertNotNull(cancelResponse.getCode()); - Assert.assertEquals(ResultCode.INVALID_SUBSCRIPTIONID, cancelResponse.getCode()); - } - - /** - * Subscription cancel request with a missing reason - * - */ - @Test - public void subscriptionCancelTestMissingReason() { - SubscriptionCancelResponse cancelResponse = null; - SubscriptionCancelRequest cancelRequest = new SubscriptionCancelRequest(); - cancelRequest.setSubscriptionId(666999666L); - - try { - cancelResponse = connector.cancelSubscription(cancelRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(cancelResponse); - Assert.assertNotNull(cancelResponse.getCode()); - Assert.assertEquals(ResultCode.DATA_MISSING_PARAMETER, cancelResponse.getCode()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionCancelTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionCancelTest.java deleted file mode 100644 index 04035e7..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionCancelTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.payxpert.connect2pay.client; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import com.payxpert.connect2pay.client.requests.TransactionCancelRequest; -import com.payxpert.connect2pay.client.response.TransactionCancelResponse; - -public class ConnectorTransactionCancelTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Transaction cancel request with an invalid ID - */ - @Test - public void transactionCancelTestInvalidId() { - TransactionCancelResponse cancelResponse = null; - TransactionCancelRequest cancelRequest = new TransactionCancelRequest(); - cancelRequest.setTransactionId("666999666"); - cancelRequest.setAmount(100); - - try { - cancelResponse = connector.cancelTransaction(cancelRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(cancelResponse); - Assert.assertNotNull(cancelResponse.getCode()); - Assert.assertEquals("312", cancelResponse.getCode()); - } - - /** - * Transaction cancel request with a missing amount - */ - @Test - public void transactionCancelTestMissingAmount() { - TransactionCancelResponse cancelResponse = null; - TransactionCancelRequest cancelRequest = new TransactionCancelRequest(); - cancelRequest.setTransactionId("666999666"); - - try { - cancelResponse = connector.cancelTransaction(cancelRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(cancelResponse); - Assert.assertNotNull(cancelResponse.getCode()); - Assert.assertEquals("401", cancelResponse.getCode()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionInfoTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionInfoTest.java deleted file mode 100644 index f53fa5c..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionInfoTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.payxpert.connect2pay.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Before; -import org.junit.Test; - -import com.payxpert.connect2pay.client.requests.TransactionInfoRequest; -import com.payxpert.connect2pay.client.response.TransactionInfoResponse; -import com.payxpert.connect2pay.constants.ResultCode; - -public class ConnectorTransactionInfoTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Transaction info request with an invalid transaction Id - * - */ - @Test - public void transactionInfoTestInvalidId() { - TransactionInfoResponse infoResponse = null; - TransactionInfoRequest infoRequest = new TransactionInfoRequest(); - infoRequest.setTransactionId("666999666"); - - try { - infoResponse = connector.getTransactionInfo(infoRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - assertNotNull(infoResponse); - assertNotNull(infoResponse.getCode()); - assertEquals(ResultCode.NOT_FOUND, infoResponse.getCode()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionRebillTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionRebillTest.java deleted file mode 100644 index 602b0b3..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionRebillTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.payxpert.connect2pay.client; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import com.payxpert.connect2pay.client.requests.TransactionRebillRequest; -import com.payxpert.connect2pay.client.response.TransactionRebillResponse; - -public class ConnectorTransactionRebillTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Transaction rebill request with an invalid ID - */ - @Test - public void transactionRebillTestInvalidId() { - TransactionRebillResponse rebillResponse = null; - TransactionRebillRequest rebillRequest = new TransactionRebillRequest(); - rebillRequest.setTransactionId("666999666"); - rebillRequest.setAmount(100); - - try { - rebillResponse = connector.rebillTransaction(rebillRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(rebillResponse); - Assert.assertNotNull(rebillResponse.getCode()); - Assert.assertEquals("312", rebillResponse.getCode()); - } - - /** - * Transaction rebill request with a missing amount - * - */ - @Test - public void transactionRebillTestMissingAmount() { - TransactionRebillResponse rebillResponse = null; - TransactionRebillRequest rebillRequest = new TransactionRebillRequest(); - rebillRequest.setTransactionId("666999666"); - - try { - rebillResponse = connector.rebillTransaction(rebillRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(rebillResponse); - Assert.assertNotNull(rebillResponse.getCode()); - Assert.assertEquals("401", rebillResponse.getCode()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionRefundTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionRefundTest.java deleted file mode 100644 index b11cf1a..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionRefundTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.payxpert.connect2pay.client; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.payxpert.connect2pay.client.requests.TransactionRefundRequest; -import com.payxpert.connect2pay.client.response.TransactionRefundResponse; - -public class ConnectorTransactionRefundTest extends ConnectorTransactionTest { - @Before - public void init() { - this.connector = new Connect2payClient(TEST_URL, DEFAULT_ORIGINATOR, DEFAULT_PASSWORD); - } - - /** - * Transaction refund request with an invalid ID - * - */ - @Test - public void transactionRefundTestInvalidId() { - TransactionRefundResponse refundResponse = null; - TransactionRefundRequest refundRequest = new TransactionRefundRequest(); - refundRequest.setTransactionId("666999666"); - refundRequest.setAmount(100); - - try { - refundResponse = connector.refundTransaction(refundRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(refundResponse); - Assert.assertNotNull(refundResponse.getCode()); - Assert.assertEquals("312", refundResponse.getCode()); - } - - /** - * Transaction refund request with a missing amount - * - */ - @Test - @Ignore("Can't be done as we don't have a valid transactionId") - public void transactionRefundTestMissingAmount() { - TransactionRefundResponse refundResponse = null; - TransactionRefundRequest refundRequest = new TransactionRefundRequest(); - refundRequest.setTransactionId("666999666"); - - try { - refundResponse = connector.refundTransaction(refundRequest); - } catch (Exception e) { - e.printStackTrace(); - } - - Assert.assertNotNull(refundResponse); - Assert.assertNotNull(refundResponse.getCode()); - Assert.assertEquals("401", refundResponse.getCode()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionTest.java b/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionTest.java deleted file mode 100644 index 9023f9b..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/ConnectorTransactionTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.payxpert.connect2pay.client; - -public abstract class ConnectorTransactionTest { - protected static final String TEST_URL = "http://connect2pay:9001"; - protected static final String DEFAULT_ORIGINATOR = "102019"; - protected static final String DEFAULT_PASSWORD = "525c563011420f4d7a230ea1fc2fbe024031febb34da9f1508d564c5c72e0284"; - - protected Connect2payClient connector; -} diff --git a/src/test/java/com/payxpert/connect2pay/client/containers/ShopperTest.java b/src/test/java/com/payxpert/connect2pay/client/containers/ShopperTest.java deleted file mode 100644 index 6ad3fcd..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/containers/ShopperTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.payxpert.connect2pay.client.containers; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class ShopperTest { - - /** - * Test Transaction Attempt creation - */ - @Test - public void shopperCreationTest() { - Shopper shopper = new Shopper(); - shopper.setAddress("35 Milton Avenue"); - shopper.setBirthDate("20000101"); - shopper.setCity("New York"); - shopper.setCountryCode("US"); - shopper.setEmail("james.bond@bss.uk"); - shopper.setIdNumber("ADV123456"); - shopper.setIpAddress("123.456.789.123"); - shopper.setName("James Bond"); - shopper.setPhone("+22 456 789 456"); - shopper.setState("New York state"); - - assertEquals("35 Milton Avenue", shopper.getAddress()); - assertEquals("20000101", shopper.getBirthDate()); - assertEquals("New York", shopper.getCity()); - assertEquals("US", shopper.getCountryCode()); - assertEquals("james.bond@bss.uk", shopper.getEmail()); - assertEquals("ADV123456", shopper.getIdNumber()); - assertEquals("123.456.789.123", shopper.getIpAddress()); - assertEquals("James Bond", shopper.getName()); - assertEquals("+22 456 789 456", shopper.getPhone()); - assertEquals("New York state", shopper.getState()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/containers/TransactionAttemptTest.java b/src/test/java/com/payxpert/connect2pay/client/containers/TransactionAttemptTest.java deleted file mode 100644 index c614a9d..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/containers/TransactionAttemptTest.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.payxpert.connect2pay.client.containers; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Calendar; - -import org.junit.Test; - -import com.payxpert.connect2pay.constants.PaymentStatusValue; -import com.payxpert.connect2pay.constants.PaymentMethod; -import com.payxpert.connect2pay.constants.TransactionOperation; - -public class TransactionAttemptTest { - - /** - * Test Transaction Attempt creation - */ - @Test - public void TransactionAttemptCreationTest() { - TransactionAttempt trans1 = getDefaultTransactionAttempt(); - - // Test getter - Calendar calendar = Calendar.getInstance(); - calendar.set(2017, 11, 10, 8, 12, 35); - calendar.set(Calendar.MILLISECOND, 12); - - assertEquals(calendar.getTime(), trans1.getDate()); - assertEquals(Integer.valueOf(1234), trans1.getAmount()); - assertEquals(TransactionOperation.SALE, trans1.getOperation()); - assertEquals(PaymentMethod.CREDIT_CARD, trans1.getPaymentType()); - assertEquals("000", trans1.getResultCode()); - assertEquals("Success", trans1.getResultMessage()); - - assertEquals(PaymentStatusValue.AUTHORIZED, trans1.getStatus()); - assertEquals(Long.valueOf(123456L), trans1.getSubscriptionId()); - assertEquals("QWERTY01234", trans1.getTransactionId()); - - Shopper shopperObj = trans1.getShopper(); - assertNotNull(shopperObj); - assertEquals("35 Milton Avenue", shopperObj.getAddress()); - assertEquals("20000101", shopperObj.getBirthDate()); - assertEquals("New York", shopperObj.getCity()); - assertEquals("US", shopperObj.getCountryCode()); - assertEquals("james.bond@bss.uk", shopperObj.getEmail()); - assertEquals("ADV123456", shopperObj.getIdNumber()); - assertEquals("123.456.789.123", shopperObj.getIpAddress()); - assertEquals("James Bond", shopperObj.getName()); - assertEquals("+22 456 789 456", shopperObj.getPhone()); - assertEquals("New York state", shopperObj.getState()); - - CreditCardPaymentMeanInfo paymentMean = trans1.getCreditCardPaymentMeanInfo(); - assertNotNull(paymentMean); - - assertEquals("411111XXXXXX1111", paymentMean.getCardNumber()); - assertEquals("2024", paymentMean.getCardExpireYear()); - assertEquals("10", paymentMean.getCardExpireMonth()); - assertEquals("Charles Ingals", paymentMean.getCardHolderName()); - assertEquals("VISA", paymentMean.getCardBrand()); - assertEquals("other", paymentMean.getCardLevel()); - assertEquals("credit", paymentMean.getCardSubType()); - assertEquals("US", paymentMean.getIinCountry()); - assertEquals("bank of hawaii", paymentMean.getIinBankName()); - assertEquals(false, paymentMean.getIs3DSecure()); - assertEquals("My bank statement", paymentMean.getStatementDescriptor()); - } - - /** - * Test the connection fails to invalid IP address - */ - @Test - public void TransactionAttemptComparatorTest() { - Calendar calendar = Calendar.getInstance(); - calendar.set(2017, 11, 10, 8, 12, 35); - calendar.set(Calendar.MILLISECOND, 12); - TransactionAttempt trans1 = getDefaultTransactionAttempt(); - trans1.setDate(calendar.getTime()); - - TransactionAttempt trans2 = getDefaultTransactionAttempt(); - assertEquals(0, trans1.compareTo(trans2)); - - calendar.set(2016, 11, 10, 8, 13, 35); - trans2.setDate(calendar.getTime()); - assertEquals(1, trans1.compareTo(trans2)); - - calendar.set(2017, 11, 10, 8, 13, 35); - trans2.setDate(calendar.getTime()); - assertEquals(-1, trans1.compareTo(trans2)); - } - - public TransactionAttempt getDefaultTransactionAttempt() { - Calendar calendar = Calendar.getInstance(); - calendar.set(2017, 11, 10, 8, 12, 35); - calendar.set(Calendar.MILLISECOND, 12); - - TransactionAttempt trans1 = new TransactionAttempt(); - trans1.setDate(calendar.getTime()); - trans1.setAmount(1234); - trans1.setOperation(TransactionOperation.SALE); - trans1.setPaymentType(PaymentMethod.CREDIT_CARD); - trans1.setResultCode("000"); - trans1.setResultMessage("Success"); - Shopper shopper = new Shopper(); - shopper.setAddress("35 Milton Avenue"); - shopper.setBirthDate("20000101"); - shopper.setCity("New York"); - shopper.setCountryCode("US"); - shopper.setEmail("james.bond@bss.uk"); - shopper.setIdNumber("ADV123456"); - shopper.setIpAddress("123.456.789.123"); - shopper.setName("James Bond"); - shopper.setPhone("+22 456 789 456"); - shopper.setState("New York state"); - - trans1.setShopper(shopper); - trans1.setStatus(PaymentStatusValue.AUTHORIZED); - trans1.setSubscriptionId(123456L); - trans1.setTransactionId("QWERTY01234"); - - StringBuilder strBuilder = new StringBuilder(50); - strBuilder.append('{'); - - strBuilder.append("\"cardNumber\":").append('"').append("411111XXXXXX1111").append('"'); - strBuilder.append(',').append("\"cardExpireYear\":").append('"').append("2024").append('"'); - strBuilder.append(',').append("\"cardExpireMonth\":").append('"').append("10").append('"'); - strBuilder.append(',').append("\"cardHolderName\":").append('"').append("Charles Ingals").append('"'); - strBuilder.append(',').append("\"cardBrand\":").append('"').append("VISA").append('"'); - strBuilder.append(',').append("\"cardLevel\":").append('"').append("other").append('"'); - strBuilder.append(',').append("\"cardSubType\":").append('"').append("credit").append('"'); - strBuilder.append(',').append("\"iinCountry\":").append('"').append("US").append('"'); - strBuilder.append(',').append("\"iinBankName\":").append('"').append("bank of hawaii").append('"'); - strBuilder.append(',').append("\"is3DSecure\":").append('"').append("false").append('"'); - strBuilder.append(',').append("\"statementDescriptor\":").append('"').append("My bank statement").append('"'); - strBuilder.append('}'); - - trans1.setPaymentMeanInfo(strBuilder.toString()); - return trans1; - } -} \ No newline at end of file diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/AlipayDirectProcessRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/AlipayDirectProcessRequestTest.java deleted file mode 100644 index f9d8fda..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/AlipayDirectProcessRequestTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Assert; -import org.junit.Test; - -import com.payxpert.connect2pay.constants.AlipayIdentityCodeType; -import com.payxpert.connect2pay.constants.AlipayPaymentMode; -import com.payxpert.connect2pay.exception.BadRequestException; - -public class AlipayDirectProcessRequestTest { - - @Test - public void testPosRequestWellformed() throws Exception { - AlipayDirectProcessRequest request = new AlipayDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(AlipayPaymentMode.POS); - - // No exception must be thrown - request.validate(); - } - - @Test - public void testPosRequestToJson() throws Exception { - AlipayDirectProcessRequest request = new AlipayDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(AlipayPaymentMode.POS); - - String json = "{\"apiVersion\":\"002.60\",\"mode\":\"pos\"}"; - - Assert.assertEquals(json, request.toJson()); - } - - @Test - public void testAppRequestWellformed() throws Exception { - AlipayDirectProcessRequest request = new AlipayDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(AlipayPaymentMode.APP); - request.setBuyerIdentityCode("123456789012345678"); - request.setIdentityCodeType(AlipayIdentityCodeType.QRCODE); - - // No exception must be thrown - request.validate(); - } - - @Test - public void testAppRequestToJson() throws Exception { - AlipayDirectProcessRequest request = new AlipayDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(AlipayPaymentMode.APP); - request.setBuyerIdentityCode("123456789012345678"); - request.setIdentityCodeType(AlipayIdentityCodeType.QRCODE); - - String json = "{\"apiVersion\":\"002.60\",\"mode\":\"app\",\"identityCodeType\":\"qrcode\",\"buyerIdentityCode\":\"123456789012345678\"}"; - - Assert.assertEquals(json, request.toJson()); - } - - @Test - public void testPosRequestLongField() throws Exception { - AlipayDirectProcessRequest request = new AlipayDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(AlipayPaymentMode.POS); - request.setNotificationLang("123456789012"); - request.setNotificationTimeZone("1234567890123456789012345678901234567890123456789012345678901234567890"); - - // No exception must be thrown - request.validate(); - Assert.assertTrue(request.getNotificationLang().length() <= 10); - Assert.assertTrue(request.getNotificationTimeZone().length() <= 64); - } - - @Test(expected = BadRequestException.class) - public void testMissingMode() throws Exception { - AlipayDirectProcessRequest request = new AlipayDirectProcessRequest(); - - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testMissingAppBuyerIdentityCode() throws Exception { - AlipayDirectProcessRequest request = new AlipayDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(AlipayPaymentMode.APP); - request.setIdentityCodeType(AlipayIdentityCodeType.QRCODE); - - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testMissingAppIdentityCodeType() throws Exception { - AlipayDirectProcessRequest request = new AlipayDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(AlipayPaymentMode.APP); - request.setBuyerIdentityCode("123456789012345678"); - - request.validate(); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/FieldState.java b/src/test/java/com/payxpert/connect2pay/client/requests/FieldState.java deleted file mode 100644 index 9c4f45b..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/FieldState.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -public class FieldState { - - public String name; - public String group; - public boolean isMandatory; - - FieldState(String group, String name, boolean isMandatory) { - this.group = group; - this.name = name; - this.isMandatory = isMandatory; - } - -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/PaymentRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/PaymentRequestTest.java deleted file mode 100644 index c703c1f..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/PaymentRequestTest.java +++ /dev/null @@ -1,238 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; - -import org.junit.Assert; -import org.junit.Test; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.payxpert.connect2pay.constants.C2PLang; -import com.payxpert.connect2pay.constants.PaymentMethod; -import com.payxpert.connect2pay.constants.PaymentMode; -import com.payxpert.connect2pay.constants.ShippingType; -import com.payxpert.connect2pay.constants.SubscriptionType; -import com.payxpert.connect2pay.exception.BadRequestException; - -import net.sf.oval.ConstraintViolation; -import net.sf.oval.Validator; - -public class PaymentRequestTest { - - private final static List REQUEST_FIELDS = new ArrayList<>(); - - public PaymentRequestTest() { - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperEmail", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToFirstName", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToLastName", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToCompany", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToPhone", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToAddress", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToState", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToZipcode", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToCity", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shipToCountryCode", false)); - - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperFirstName", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperLastName", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperPhone", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperAddress", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperState", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperZipcode", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperCity", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperCountryCode", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperCompany", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperLoyaltyProgram", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperBirthDate", false)); - REQUEST_FIELDS.add(new FieldState("shopperFields", "shopperIDNumber", false)); - - REQUEST_FIELDS.add(new FieldState("affiliationFields", "affiliateId", false)); - REQUEST_FIELDS.add(new FieldState("affiliationFields", "campaignName", false)); - - REQUEST_FIELDS.add(new FieldState("commonFields", "orderID", true)); - REQUEST_FIELDS.add(new FieldState("commonFields", "currency", true)); - REQUEST_FIELDS.add(new FieldState("commonFields", "amount", true)); - - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "orderTotalWithoutShipping", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "orderShippingPrice", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "orderDiscount", false)); - - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "orderFOLanguage", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "orderDescription", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "orderCartContent", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shippingType", true)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "shippingName", false)); - - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "paymentMode", true)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "paymentType", true)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "operation", false)); - REQUEST_FIELDS.add(new FieldState("ecommerceFields", "secure3d", false)); - - REQUEST_FIELDS.add(new FieldState("subscriptionFields", "offerID", false)); - REQUEST_FIELDS.add(new FieldState("subscriptionFields", "subscriptionType", false)); - REQUEST_FIELDS.add(new FieldState("subscriptionFields", "trialPeriod", false)); - REQUEST_FIELDS.add(new FieldState("subscriptionFields", "rebillAmount", false)); - REQUEST_FIELDS.add(new FieldState("subscriptionFields", "rebillPeriod", false)); - REQUEST_FIELDS.add(new FieldState("subscriptionFields", "rebillMaxIteration", false)); - - REQUEST_FIELDS.add(new FieldState("controlFields", "ctrlRedirectURL", false)); - REQUEST_FIELDS.add(new FieldState("controlFields", "ctrlCallbackURL", false)); - REQUEST_FIELDS.add(new FieldState("controlFields", "ctrlCustomData", false)); - REQUEST_FIELDS.add(new FieldState("controlFields", "timeOut", false)); - REQUEST_FIELDS.add(new FieldState("controlFields", "merchantNotification", false)); - REQUEST_FIELDS.add(new FieldState("controlFields", "merchantNotificationTo", false)); - REQUEST_FIELDS.add(new FieldState("controlFields", "merchantNotificationLang", false)); - REQUEST_FIELDS.add(new FieldState("controlFields", "themeID", false)); - } - - @Test - public void testSaleRequestWellformed() throws Exception { - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - - // No exception must be thrown - request.validate(); - } - - @Test - public void testRequestLongField() throws Exception { - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - request.setShopperFirstName( - "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); - - // No exception must be thrown - request.validate(); - Assert.assertTrue(request.getShopperFirstName().length() <= 35); - } - - @Test(expected = BadRequestException.class) - public void testSaleRequestMissingAmount() throws Exception { - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - request.setAmount(null); - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testSaleRequestMissingCurrency() throws Exception { - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - request.setCurrency(""); - request.validate(); - } - - @Test - public void testSaleRequestValidShopperEmailValidation() { - Validator validation = new Validator(); - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - - String[] validEmails = new String[] { "NA", "test@test.com" }; - for (String email : validEmails) { - request.setShopperEmail(email); - List constraintViolations = validation.validate(request); - assertEquals("Error found on email " + email, 0, constraintViolations.size()); - } - } - - @Test - public void testSaleRequestInvalidShopperEmailValidation() { - Validator validation = new Validator(); - PaymentRequest request = PaymentRequestTest.getDefaultRequest(); - - String[] invalidEmails = new String[] { "na", "on", "test@test", "test#test.com.test" }; - for (String email : invalidEmails) { - request.setShopperEmail(email); - List constraintViolations = validation.validate(request); - assertEquals("No error found on email " + email, 1, constraintViolations.size()); - } - } - - @Test - public void testJsonFormating() { - PaymentRequest request = getDefaultFullRequest(); - - String json = ""; - try { - json = request.toJson(); - } catch (JsonGenerationException e) { - e.printStackTrace(); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - for (FieldState field : REQUEST_FIELDS) { - if (field.isMandatory) { - assertTrue("Sale Request : field=" + field.group + "[" + field.name + "] must be present in " + json, - json.contains(field.name)); - } - } - } - - @Test - public void testSetBirthDate() { - PaymentRequest request = getDefaultFullRequest(); - Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Etc/UTC")); - - request.setShopperBirthDate("19700208"); - assertEquals("19700208", request.getShopperBirthDate()); - request.setShopperBirthDate("197002/08"); - assertEquals("197002/0", request.getShopperBirthDate()); - request.setShopperBirthDate("1970/02/08"); - assertEquals("1970/02/", request.getShopperBirthDate()); - - calendar.set(1970, Calendar.FEBRUARY, 8); - request.setShopperBirthDate(calendar.getTime()); - assertEquals("19700208", request.getShopperBirthDate()); - - calendar.set(2000, Calendar.DECEMBER, 15); - request.setShopperBirthDate(calendar.getTime()); - assertEquals("20001215", request.getShopperBirthDate()); - - calendar.set(2016, Calendar.JANUARY, 01); - request.setShopperBirthDate(calendar.getTime()); - assertEquals("20160101", request.getShopperBirthDate()); - - calendar.set(2016, Calendar.AUGUST, 31); - request.setShopperBirthDate(calendar.getTime()); - assertEquals("20160831", request.getShopperBirthDate()); - } - - public static PaymentRequest getDefaultRequest() { - PaymentRequest request = new PaymentRequest(); - - request.setPaymentMethod(PaymentMethod.CREDIT_CARD).setPaymentMode(PaymentMode.SINGLE) - .setOrderId(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())); - request.setAmount(100).setCurrency("EUR").setShopperFirstName("Bernard").setShopperLastName("Ménez") - .setShopperAddress("Passeig de Gracia, 55").setShopperZipcode("08008").setShopperCity("Barcelona") - .setShopperState("Barcelona").setShopperCountryCode("ES").setShopperPhone("+34666666666") - .setShopperEmail("bernard.menez@gmail.com").setShopperBirthDate("19700101").setShopperIDNumber("ID12345") - .setShippingType(ShippingType.VIRTUAL).setCtrlRedirectURL("https://redirect.here/"); - - return request; - } - - public static PaymentRequest getDefaultFullRequest() { - PaymentRequest request = getDefaultRequest(); - - request.setShipToFirstName("Bernard").setShipToLastName("Ménez").setShipToAddress("Passeig de Gracia, 55") - .setShipToZipcode("08008").setShipToCity("Barcelona").setShipToState("Barcelona").setShipToCountryCode("ES") - .setShipToPhone("+34666666666").setMerchantNotification(true).setMerchantNotificationTo("dev@payxpert.com") - .setMerchantNotificationLang(C2PLang.EN); - - request.setOrderDescription("orderDescription"); - request.setOfferId(1L); - request.setSubscriptionType(SubscriptionType.NORMAL).setRebillAmount(100).setRebillPeriod("P1M") - .setRebillMaxIteration(10).setTrialPeriod("P1M"); - request.setAffiliateId("3526378").setCampaignName("Unit Test Campaign"); - - return request; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/PaymentStatusRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/PaymentStatusRequestTest.java deleted file mode 100644 index 4f2cb42..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/PaymentStatusRequestTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Test; - -import com.payxpert.connect2pay.exception.BadRequestException; - -public class PaymentStatusRequestTest { - @Test - public void testPaymentStatusRequestWellformed() throws Exception { - PaymentStatusRequest request = getDefaultRequest(); - - // No exception must be thrown - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testPaymentStatusRequestMissingTransactionId() throws Exception { - PaymentStatusRequest request = getDefaultRequest(); - request.setMerchantToken(null); - request.validate(); - } - - public static PaymentStatusRequest getDefaultRequest() { - PaymentStatusRequest request = new PaymentStatusRequest(); - - request.setMerchantToken("a2xta2VyKm1sw6lrbWFza2ZtKmHDqW1MS8OpbWZ6YWxmZGs="); - - return request; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/SubscriptionCancelRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/SubscriptionCancelRequestTest.java deleted file mode 100644 index 7d05684..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/SubscriptionCancelRequestTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Test; - -import com.payxpert.connect2pay.constants.SubscriptionCancelReason; -import com.payxpert.connect2pay.exception.BadRequestException; - -public class SubscriptionCancelRequestTest { - @Test - public void testSubscriptionRequestWellformed() throws Exception { - SubscriptionCancelRequest request = getDefaultRequest(); - - // No exception must be thrown - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testSubscriptionRequestMissingSubscriptionId() throws Exception { - SubscriptionCancelRequest request = getDefaultRequest(); - request.setSubscriptionId(null); - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testSubscriptionRequestMissingReason() throws Exception { - SubscriptionCancelRequest request = getDefaultRequest(); - request.setCancelReason(null); - request.validate(); - } - - public static SubscriptionCancelRequest getDefaultRequest() { - SubscriptionCancelRequest request = new SubscriptionCancelRequest(); - - request.setSubscriptionId(123456L).setCancelReason(SubscriptionCancelReason.CHARGEBACK); - - return request; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionCancelRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/TransactionCancelRequestTest.java deleted file mode 100644 index 9cb1bef..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionCancelRequestTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Test; - -import com.payxpert.connect2pay.exception.BadRequestException; - -public class TransactionCancelRequestTest { - @Test - public void testTransactionCancelRequestWellformed() throws Exception { - TransactionCancelRequest request = getDefaultRequest(); - - // No exception must be thrown - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionCancelRequestMissingTransactionId() throws Exception { - TransactionCancelRequest request = getDefaultRequest(); - request.setTransactionId(null); - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionCancelRequestMissingAmount() throws Exception { - TransactionCancelRequest request = getDefaultRequest(); - request.setAmount(null); - request.validate(); - } - - public static TransactionCancelRequest getDefaultRequest() { - TransactionCancelRequest request = new TransactionCancelRequest(); - - request.setTransactionId("123456-01").setAmount(1599); - - return request; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionInfoRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/TransactionInfoRequestTest.java deleted file mode 100644 index 3b08124..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionInfoRequestTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Test; - -import com.payxpert.connect2pay.exception.BadRequestException; - -public class TransactionInfoRequestTest { - @Test - public void testTransactionInfoRequestWellformed() throws Exception { - TransactionInfoRequest request = getDefaultRequest(); - - // No exception must be thrown - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionInfoRequestMissingTransactionId() throws Exception { - TransactionInfoRequest request = getDefaultRequest(); - request.setTransactionId(null); - request.validate(); - } - - public static TransactionInfoRequest getDefaultRequest() { - TransactionInfoRequest request = new TransactionInfoRequest(); - - request.setTransactionId("a2xta2VyKm1sw6lr"); - - return request; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRebillRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRebillRequestTest.java deleted file mode 100644 index 9e3e847..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRebillRequestTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Test; - -import com.payxpert.connect2pay.exception.BadRequestException; - -public class TransactionRebillRequestTest { - @Test - public void testTransactionRebillRequestWellformed() throws Exception { - TransactionRebillRequest request = getDefaultRequest(); - - // No exception must be thrown - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionRebillRequestMissingTransactionId() throws Exception { - TransactionRebillRequest request = getDefaultRequest(); - request.setTransactionId(null); - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionRebillRequestMissingAmount() throws Exception { - TransactionRebillRequest request = getDefaultRequest(); - request.setAmount(null); - request.validate(); - } - - public static TransactionRebillRequest getDefaultRequest() { - TransactionRebillRequest request = new TransactionRebillRequest(); - - request.setTransactionId("123456-01").setAmount(1599); - - return request; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRefundConfirmRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRefundConfirmRequestTest.java deleted file mode 100644 index 8e7b642..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRefundConfirmRequestTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Test; - -import com.payxpert.connect2pay.exception.BadRequestException; - -public class TransactionRefundConfirmRequestTest { - @Test - public void testTransactionRefundConfirmRequestWellformed() throws Exception { - TransactionRefundConfirmRequest request = getDefaultRequest(); - - // No exception must be thrown - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionRefundConfirmRequestMissingSubscriptionId() throws Exception { - TransactionRefundConfirmRequest request = getDefaultRequest(); - request.setTransactionId(null); - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionRefundConfirmRequestMissingReason() throws Exception { - TransactionRefundConfirmRequest request = getDefaultRequest(); - request.setTransactionId(null); - request.validate(); - } - - public static TransactionRefundConfirmRequest getDefaultRequest() { - TransactionRefundConfirmRequest request = new TransactionRefundConfirmRequest(); - - request.setTransactionId("123456-01"); - - return request; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRefundRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRefundRequestTest.java deleted file mode 100644 index 3dcad82..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/TransactionRefundRequestTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Test; - -import com.payxpert.connect2pay.exception.BadRequestException; - -public class TransactionRefundRequestTest { - @Test - public void testTransactionRefundRequestWellformed() throws Exception { - TransactionRefundRequest request = getDefaultRequest(); - - // No exception must be thrown - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionRefundRequestMissingSubscriptionId() throws Exception { - TransactionRefundRequest request = getDefaultRequest(); - request.setTransactionId(null); - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testTransactionRefundRequestMissingReason() throws Exception { - TransactionRefundRequest request = getDefaultRequest(); - request.setAmount(null); - request.validate(); - } - - public static TransactionRefundRequest getDefaultRequest() { - TransactionRefundRequest request = new TransactionRefundRequest(); - - request.setTransactionId("123456-01").setAmount(1599); - - return request; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/requests/WeChatDirectProcessRequestTest.java b/src/test/java/com/payxpert/connect2pay/client/requests/WeChatDirectProcessRequestTest.java deleted file mode 100644 index 8846dc3..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/requests/WeChatDirectProcessRequestTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.payxpert.connect2pay.client.requests; - -import org.junit.Assert; -import org.junit.Test; - -import com.payxpert.connect2pay.constants.WeChatPaymentMode; -import com.payxpert.connect2pay.exception.BadRequestException; - -public class WeChatDirectProcessRequestTest { - - @Test - public void testNativeRequestWellformed() throws Exception { - WeChatDirectProcessRequest request = new WeChatDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(WeChatPaymentMode.NATIVE); - - // No exception must be thrown - request.validate(); - } - - @Test - public void testQuickPayRequestWellformed() throws Exception { - WeChatDirectProcessRequest request = new WeChatDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(WeChatPaymentMode.QUICKPAY); - request.setQuickPayCode("123456789012345678"); - - // No exception must be thrown - request.validate(); - } - - @Test - public void testNativeRequestLongField() throws Exception { - WeChatDirectProcessRequest request = new WeChatDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(WeChatPaymentMode.NATIVE); - request.setNotificationLang("123456789012"); - request.setNotificationTimeZone("1234567890123456789012345678901234567890123456789012345678901234567890"); - - // No exception must be thrown - request.validate(); - Assert.assertTrue(request.getNotificationLang().length() <= 10); - Assert.assertTrue(request.getNotificationTimeZone().length() <= 64); - } - - @Test(expected = BadRequestException.class) - public void testMissingMode() throws Exception { - WeChatDirectProcessRequest request = new WeChatDirectProcessRequest(); - - request.validate(); - } - - @Test(expected = BadRequestException.class) - public void testMissingQuickPayAuthCode() throws Exception { - WeChatDirectProcessRequest request = new WeChatDirectProcessRequest(); - request.setCustomerToken("12345678"); - request.setMode(WeChatPaymentMode.QUICKPAY); - - request.validate(); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/AccountInformationResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/AccountInformationResponseTest.java deleted file mode 100644 index 53742c1..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/AccountInformationResponseTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Test; - -import com.payxpert.connect2pay.constants.PaymentMethod; - -public class AccountInformationResponseTest { - @Test - public void testAccountInformationResponse() throws Exception { - String json = "{\"apiVersion\":\"002.60\",\"name\":\"Unit Test Website\",\"displayTerms\":false," - + "\"termsUrl\":\"\",\"supportUrl\":\"http://example.com/support\",\"maxAttempts\":1,\"notificationSenderName\":\"PayXpert Payment Service\"," - + "\"notificationSenderEmail\":\"support@payxpert.com\",\"notificationOnSuccess\":true," - + "\"notificationOnFailure\":false,\"merchantNotification\":true,\"merchantNotificationTo\":\"support@payxpert.com\"," - + "\"merchantNotificationLang\":\"fr\"," + "\"paymentMethods\":[" - + "{\"paymentMethod\":\"BankTransfer\",\"paymentNetwork\":\"eps\",\"currencies\":[\"EUR\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"DirectDebit\",\"currencies\":[\"EUR\"],\"defaultOperation\":\"submission\"}," - + "{\"paymentMethod\":\"Line\",\"currencies\":[\"TWD\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"WeChat\",\"currencies\":[\"USD\",\"EUR\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"BankTransfer\",\"paymentNetwork\":\"ideal\",\"currencies\":[\"EUR\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"BankTransfer\",\"paymentNetwork\":\"dragonpay\",\"currencies\":[\"EUR\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"BankTransfer\",\"paymentNetwork\":\"poli\",\"currencies\":[\"EUR\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"BankTransfer\",\"paymentNetwork\":\"przelewy24\",\"currencies\":[\"PLN\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"ToditoCash\",\"currencies\":[\"MXN\",\"EUR\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"CreditCard\",\"currencies\":[\"EUR\",\"USD\"],\"defaultOperation\":\"authorize\",\"options\":[{\"name\":\"3dsMode\",\"value\":\"honor\"}]}," - + "{\"paymentMethod\":\"BankTransfer\",\"paymentNetwork\":\"sofort\",\"currencies\":[\"EUR\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"Alipay\",\"currencies\":[\"USD\",\"EUR\"],\"defaultOperation\":\"sale\"}," - + "{\"paymentMethod\":\"BankTransfer\",\"paymentNetwork\":\"giropay\",\"currencies\":[\"EUR\"],\"defaultOperation\":\"sale\"}]}"; - - AccountInformationResponse response = new AccountInformationResponse().fromJson(json); - assertNotNull(response); - assertEquals("002.60", response.getApiVersion()); - assertEquals("Unit Test Website", response.getName()); - assertFalse(response.getDisplayTerms()); - assertEquals("http://example.com/support", response.getSupportUrl()); - assertEquals(new Integer(1), response.getMaxAttempts()); - assertEquals("PayXpert Payment Service", response.getNotificationSenderName()); - assertEquals("support@payxpert.com", response.getNotificationSenderEmail()); - assertTrue(response.getNotificationOnSuccess()); - assertFalse(response.getNotificationOnFailure()); - assertTrue(response.getMerchantNotification()); - assertEquals("support@payxpert.com", response.getMerchantNotificationTo()); - assertEquals("fr", response.getMerchantNotificationLang()); - - List paymentMethods = response.getPaymentMethods(); - - assertNotNull(paymentMethods); - assertEquals(13, paymentMethods.size()); - - PaymentMethodInformation ccMethod = null; - for (PaymentMethodInformation paymentMethod : paymentMethods) { - if (PaymentMethod.CREDIT_CARD.equals(paymentMethod.getPaymentMethod())) { - ccMethod = paymentMethod; - } - } - - assertNotNull(ccMethod); - assertNull(ccMethod.getPaymentNetwork()); - assertEquals("authorize", ccMethod.getDefaultOperation()); - assertEquals(2, ccMethod.getCurrencies().size()); - assertTrue(ccMethod.getCurrencies().contains("EUR")); - assertTrue(ccMethod.getCurrencies().contains("USD")); - - List pmOptions = ccMethod.getOptions(); - assertNotNull(pmOptions); - assertEquals(1, pmOptions.size()); - assertEquals("3dsMode", pmOptions.get(0).getName()); - assertEquals("honor", pmOptions.get(0).getValue()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/CallbackResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/CallbackResponseTest.java deleted file mode 100644 index aa7ac23..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/CallbackResponseTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import org.junit.Assert; -import org.junit.Test; - -public class CallbackResponseTest { - - @Test - public void testCallbackResponseJSONExport() throws Exception { - CallbackStatusResponse response = new CallbackStatusResponse(); - response.setStatus("Oh yeah").setMessage("That's it"); - - Assert.assertEquals("{\"status\":\"Oh yeah\",\"message\":\"That's it\"}", response.toJson()); - } - - @Test - public void testCallbackDefaultResponseJSONExport() throws Exception { - CallbackStatusResponse response = CallbackStatusResponse.getDefaultSuccessResponse(); - - Assert.assertEquals("{\"status\":\"OK\",\"message\":\"Status recorded.\"}", response.toJson()); - - response = CallbackStatusResponse.getDefaultFailureResponse(); - - Assert.assertEquals("{\"status\":\"KO\",\"message\":\"Error when recording status.\"}", response.toJson()); - } - -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/PaymentStatusResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/PaymentStatusResponseTest.java deleted file mode 100644 index ceb8787..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/PaymentStatusResponseTest.java +++ /dev/null @@ -1,392 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.Calendar; -import java.util.List; - -import org.junit.Test; - -import com.payxpert.connect2pay.client.containers.ChargebackPaymentMeanInfo; -import com.payxpert.connect2pay.client.containers.ReversalPaymentMeanInfo; -import com.payxpert.connect2pay.client.containers.TransactionAttempt; -import com.payxpert.connect2pay.client.containers.TransactionAttemptTest; -import com.payxpert.connect2pay.constants.PaymentStatusValue; -import com.payxpert.connect2pay.constants.PaymentMethod; -import com.payxpert.connect2pay.constants.ResultCode; -import com.payxpert.connect2pay.constants.TransactionOperation; - -public class PaymentStatusResponseTest { - @Test - public void testPaymentStatusResponse() { - PaymentStatusResponse response = getDefaultResponse(); - - assertEquals(Integer.valueOf(1012), response.getAmount()); - assertEquals(ResultCode.SUCCESS, response.getCode()); - assertEquals("{mydata:\"test\"}", response.getCtrlCustomData()); - assertEquals("EUR", response.getCurrency()); - assertEquals("Success", response.getErrorMessage()); - assertEquals("a2xta2VyKm1sw6lrbWFza2ZtKmHDqW1MS8OpbWZ6YWxmZGs", response.getMerchantToken()); - assertEquals("Transaction Attempt", response.getMessage()); - assertEquals(TransactionOperation.SALE, response.getOperation()); - assertEquals("MyOrder1234", response.getOrderId()); - assertEquals("000", response.getErrorCode()); - assertEquals(PaymentStatusValue.AUTHORIZED, response.getStatus()); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(3, transactionAttempts.size()); - - TransactionAttempt lastTransactionAttempt = response.getLastInitialTransactionAttempt().orElse(null); - assertNotNull(lastTransactionAttempt); - assertEquals("Transaction Attempt 2", lastTransactionAttempt.getResultMessage()); - - // Add a null transaction - response.addTransactionAttempt(null); - transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(4, transactionAttempts.size()); - - lastTransactionAttempt = response.getLastInitialTransactionAttempt().orElse(null); - assertNotNull(lastTransactionAttempt); - assertEquals("Transaction Attempt 2", lastTransactionAttempt.getResultMessage()); - - // Add a transaction with date null - TransactionAttempt newTransactionAttempt = new TransactionAttemptTest().getDefaultTransactionAttempt(); - newTransactionAttempt.setDate(null); - newTransactionAttempt.setResultMessage("testTransactionStatusResponse"); - response.addTransactionAttempt(newTransactionAttempt); - transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(5, transactionAttempts.size()); - - lastTransactionAttempt = response.getLastInitialTransactionAttempt().orElse(null); - assertNotNull(lastTransactionAttempt); - assertEquals("Transaction Attempt 2", lastTransactionAttempt.getResultMessage()); - - // Test with only transaction with date null - response.setTransactions(null); - response.addTransactionAttempt(newTransactionAttempt); - transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(1, transactionAttempts.size()); - - lastTransactionAttempt = response.getLastInitialTransactionAttempt().orElse(null); - assertNotNull(lastTransactionAttempt); - assertEquals("testTransactionStatusResponse", lastTransactionAttempt.getResultMessage()); - } - - @Test - public void testPaymentStatusResponseWithReferral() { - PaymentStatusResponse response = getResponseWithReferral(); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(7, transactionAttempts.size()); - - TransactionAttempt lastTransactionAttempt = response.getLastInitialTransactionAttempt().orElse(null); - assertNotNull(lastTransactionAttempt); - assertNull(lastTransactionAttempt.getRefTransactionId()); - assertEquals("Transaction Attempt 4", lastTransactionAttempt.getResultMessage()); - - TransactionAttempt cancelTransactionAttempt = response.getTransactionAttempt(4); - assertNotNull(cancelTransactionAttempt); - assertNotNull(cancelTransactionAttempt.getRefTransactionId()); - assertEquals("Transaction Attempt 5", cancelTransactionAttempt.getResultMessage()); - assertEquals(lastTransactionAttempt.getTransactionId(), cancelTransactionAttempt.getRefTransactionId()); - } - - @Test - public void testPaymentStatusResponseWithChargeback() throws Exception { - PaymentStatusResponse response = getResponseFromJSONWithChargeback(); - - assertNotNull(response); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(3, transactionAttempts.size()); - - // The submission - TransactionAttempt lastTransactionAttempt = response.getLastInitialTransactionAttempt().orElse(null); - assertNotNull(lastTransactionAttempt); - assertNull(lastTransactionAttempt.getRefTransactionId()); - assertEquals("4reazyd5ln-4v8e", lastTransactionAttempt.getTransactionId()); - - // The related collection - TransactionAttempt collectTransactionAttempt = response - .getReferringTransactionAttempt(lastTransactionAttempt, TransactionOperation.COLLECTION).orElse(null); - assertNotNull(collectTransactionAttempt); - assertEquals("4reazyd5ln-4v8e", collectTransactionAttempt.getRefTransactionId()); - assertEquals("4reazyd5ln-g5ty", collectTransactionAttempt.getTransactionId()); - - // The chargeback - TransactionAttempt cbTransactionAttempt = response.getTransactionAttempt(2); - assertNotNull(cbTransactionAttempt); - assertEquals("4reazyd5ln-g5ty", cbTransactionAttempt.getRefTransactionId()); - assertEquals("4reazyd5ln-vgt7", cbTransactionAttempt.getTransactionId()); - - ChargebackPaymentMeanInfo cbPmInfo = cbTransactionAttempt.getChargebackPaymentMeanInfo(); - assertNotNull(cbPmInfo); - assertEquals(1517554885000L, cbPmInfo.getDate().getTime()); - assertEquals("AC01", cbPmInfo.getReasonCode()); - } - - @Test - public void testPaymentStatusResponseWithReversal() throws Exception { - PaymentStatusResponse response = getResponseFromJSONWithReversal(); - - assertNotNull(response); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(3, transactionAttempts.size()); - - // The submission - TransactionAttempt lastTransactionAttempt = response.getLastInitialTransactionAttempt().orElse(null); - assertNotNull(lastTransactionAttempt); - assertNull(lastTransactionAttempt.getRefTransactionId()); - assertEquals("4reazyd5ln-4v8e", lastTransactionAttempt.getTransactionId()); - - // The related collection - TransactionAttempt collectTransactionAttempt = response - .getReferringTransactionAttempt(lastTransactionAttempt, TransactionOperation.COLLECTION).orElse(null); - assertNotNull(collectTransactionAttempt); - assertEquals("4reazyd5ln-4v8e", collectTransactionAttempt.getRefTransactionId()); - assertEquals("4reazyd5ln-g5ty", collectTransactionAttempt.getTransactionId()); - - // The reversal - TransactionAttempt cbTransactionAttempt = response.getTransactionAttempt(2); - assertNotNull(cbTransactionAttempt); - assertEquals("4reazyd5ln-g5ty", cbTransactionAttempt.getRefTransactionId()); - assertEquals("4reazyd5ln-vgt7", cbTransactionAttempt.getTransactionId()); - - ReversalPaymentMeanInfo revPmInfo = cbTransactionAttempt.getReversalPaymentMeanInfo(); - assertNotNull(revPmInfo); - assertEquals(1517554885000L, revPmInfo.getDate().getTime()); - assertEquals("MD01", revPmInfo.getReasonCode()); - } - - @Test - public void testGetReferringTransactionAttempt() { - PaymentStatusResponse response = getResponseWithReferral(); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(7, transactionAttempts.size()); - - TransactionAttempt refTransactionAttempt = response.getTransactionAttempt("1234567-1234").orElse(null); - assertNotNull(refTransactionAttempt); - assertNull(refTransactionAttempt.getRefTransactionId()); - assertEquals("Transaction Attempt 4", refTransactionAttempt.getResultMessage()); - - TransactionAttempt cancelTransactionAttempt = response - .getReferringTransactionAttempt(refTransactionAttempt, TransactionOperation.CANCEL).orElse(null); - assertNotNull(cancelTransactionAttempt); - assertNotNull(cancelTransactionAttempt.getRefTransactionId()); - assertEquals("Transaction Attempt 5", cancelTransactionAttempt.getResultMessage()); - assertEquals(refTransactionAttempt.getTransactionId(), cancelTransactionAttempt.getRefTransactionId()); - } - - @Test - public void testGetReferringTransactionAttempts() { - PaymentStatusResponse response = getResponseWithReferral(); - - List transactionAttempts = response.getTransactions(); - assertNotNull(transactionAttempts); - assertEquals(7, transactionAttempts.size()); - - TransactionAttempt refTransactionAttempt = response.getTransactionAttempt("1234567-1234").orElse(null); - assertNotNull(refTransactionAttempt); - assertNull(refTransactionAttempt.getRefTransactionId()); - assertEquals("Transaction Attempt 4", refTransactionAttempt.getResultMessage()); - - List rebillTransactionAttempts = response.getReferringTransactionAttempts(refTransactionAttempt, - TransactionOperation.SUBMISSION); - assertNotNull(rebillTransactionAttempts); - assertFalse(rebillTransactionAttempts.isEmpty()); - assertEquals(2, rebillTransactionAttempts.size()); - - TransactionAttempt firstRebill = rebillTransactionAttempts.get(0); - assertEquals("Transaction Attempt 6", firstRebill.getResultMessage()); - - TransactionAttempt secondRebill = rebillTransactionAttempts.get(1); - assertEquals("Transaction Attempt 7", secondRebill.getResultMessage()); - } - - @Test - public void testGetTransactionAttemptByTransactionId() { - PaymentStatusResponse response = getResponseWithReferral(); - - TransactionAttempt cancelTransactionAttempt = response.getTransactionAttempt(4); - assertNotNull(cancelTransactionAttempt); - assertNotNull(cancelTransactionAttempt.getRefTransactionId()); - - TransactionAttempt refTransactionAttempt = response - .getTransactionAttempt(cancelTransactionAttempt.getRefTransactionId()).orElse(null); - assertNotNull(refTransactionAttempt); - assertNull(refTransactionAttempt.getRefTransactionId()); - assertEquals("Transaction Attempt 4", refTransactionAttempt.getResultMessage()); - assertEquals("1234567-1234", refTransactionAttempt.getTransactionId()); - } - - public static PaymentStatusResponse getDefaultResponse() { - PaymentStatusResponse response = new PaymentStatusResponse(); - response.setAmount(1012); - response.setCode(ResultCode.SUCCESS); - response.setCtrlCustomData("{mydata:\"test\"}"); - response.setCurrency("EUR"); - response.setErrorMessage("Success"); - response.setMerchantToken("a2xta2VyKm1sw6lrbWFza2ZtKmHDqW1MS8OpbWZ6YWxmZGs"); - response.setMessage("Transaction Attempt"); - response.setOperation(TransactionOperation.SALE); - response.setOrderId("MyOrder1234"); - response.setErrorCode("000"); - response.setStatus(PaymentStatusValue.AUTHORIZED); - - TransactionAttempt transactionAttempt = new TransactionAttemptTest().getDefaultTransactionAttempt(); - response.addTransactionAttempt(transactionAttempt); - - TransactionAttempt transactionAttempt2 = new TransactionAttemptTest().getDefaultTransactionAttempt(); - Calendar calendar = Calendar.getInstance(); - calendar.set(2017, 11, 11, 8, 12, 35); - calendar.set(Calendar.MILLISECOND, 12); - transactionAttempt2.setDate(calendar.getTime()); - transactionAttempt2.setResultMessage("Transaction Attempt 2"); - response.addTransactionAttempt(transactionAttempt2); - - TransactionAttempt transactionAttempt3 = new TransactionAttemptTest().getDefaultTransactionAttempt(); - calendar.set(2017, 10, 10, 8, 12, 35); - transactionAttempt3.setDate(calendar.getTime()); - transactionAttempt3.setResultMessage("Transaction Attempt 3"); - response.addTransactionAttempt(transactionAttempt3); - - return response; - } - - public static PaymentStatusResponse getResponseWithReferral() { - PaymentStatusResponse response = getDefaultResponse(); - - TransactionAttempt transactionAttempt4 = new TransactionAttemptTest().getDefaultTransactionAttempt(); - Calendar calendar = Calendar.getInstance(); - calendar.set(2017, 11, 15, 9, 16, 43); - transactionAttempt4.setDate(calendar.getTime()); - transactionAttempt4.setResultMessage("Transaction Attempt 4"); - transactionAttempt4.setPaymentType(PaymentMethod.DIRECT_DEBIT); - transactionAttempt4.setOperation(TransactionOperation.SUBMISSION); - transactionAttempt4.setTransactionId("1234567-1234"); - response.addTransactionAttempt(transactionAttempt4); - - TransactionAttempt transactionAttempt5 = new TransactionAttemptTest().getDefaultTransactionAttempt(); - calendar.set(2017, 11, 16, 7, 0, 6); - transactionAttempt5.setDate(calendar.getTime()); - transactionAttempt5.setResultMessage("Transaction Attempt 5"); - transactionAttempt5.setPaymentType(PaymentMethod.DIRECT_DEBIT); - transactionAttempt5.setOperation(TransactionOperation.CANCEL); - transactionAttempt5.setTransactionId("1234567-4321"); - transactionAttempt5.setRefTransactionId("1234567-1234"); - response.addTransactionAttempt(transactionAttempt5); - - // Adding them in reverse order will check the sort - TransactionAttempt transactionAttempt7 = new TransactionAttemptTest().getDefaultTransactionAttempt(); - calendar.set(2018, 01, 12, 22, 45, 45); - transactionAttempt7.setDate(calendar.getTime()); - transactionAttempt7.setResultMessage("Transaction Attempt 7"); - transactionAttempt7.setPaymentType(PaymentMethod.DIRECT_DEBIT); - transactionAttempt7.setOperation(TransactionOperation.SUBMISSION); - transactionAttempt7.setTransactionId("1234567-cv3t"); - transactionAttempt7.setRefTransactionId("1234567-1234"); - response.addTransactionAttempt(transactionAttempt7); - - TransactionAttempt transactionAttempt6 = new TransactionAttemptTest().getDefaultTransactionAttempt(); - calendar.set(2017, 12, 10, 10, 4, 8); - transactionAttempt6.setDate(calendar.getTime()); - transactionAttempt6.setResultMessage("Transaction Attempt 6"); - transactionAttempt6.setPaymentType(PaymentMethod.DIRECT_DEBIT); - transactionAttempt6.setOperation(TransactionOperation.SUBMISSION); - transactionAttempt6.setTransactionId("1234567-dfg6"); - transactionAttempt6.setRefTransactionId("1234567-1234"); - response.addTransactionAttempt(transactionAttempt6); - - return response; - } - - public static PaymentStatusResponse getResponseFromJSONWithChargeback() throws Exception { - String json = "{\"transactions\":[{\"date\":1516448832000,\"amount\":2548,\"paymentType\":" - + "\"DirectDebit\",\"paymentMeanInfo\":{\"bankAccount\":{\"holderName\":\"John Snow\"," - + "\"bankName\":\"BNP\",\"iban\":\"NL29ABNA050988XXXX\",\"bic\":\"ABNANL2AXXX\"," - + "\"countryCode\":\"NL\",\"sepaMandate\":{\"description\":\"Unit Test Mandate\"," - + "\"status\":\"SIGNED\",\"type\":\"RECURRENT\",\"scheme\":\"CORE\",\"signatureType\":\"SMS\"," - + "\"phoneNumber\":\"+34123456789\",\"signedAt\":1516448821000,\"createdAt\":1516448795000," - + "\"lastUsedAt\":1516448832000,\"downloadUrl\":\"https://fake.url/mandate/man654322/dl\"}}," - + "\"statementDescriptor\":\"Test statement descriptor\",\"collectedAt\":1516579200000}," - + "\"shopper\":{\"name\":\"John Snow\",\"address\":\"Calle Mallorca, 66\",\"zipcode\":\"08008\"," - + "\"city\":\"Barcelona\",\"state\":\"Barcelona\",\"countryCode\":\"ES\",\"email\":" - + "\"dev@payxpert.com\",\"ipAddress\":\"127.0.0.1\"},\"operation\":\"submission\"," - + "\"resultCode\":\"000\",\"resultMessage\":\"Transaction successfully completed\"," - + "\"status\":\"Authorized\",\"transactionID\":\"4reazyd5ln-4v8e\"},{\"refTransactionID\":" - + "\"4reazyd5ln-4v8e\",\"date\":1516596043000,\"amount\":2548,\"paymentType\":\"DirectDebit\"," - + "\"paymentMeanInfo\":{\"bankAccount\":{\"holderName\":\"John Snow\",\"bankName\":\"BNP\"," - + "\"iban\":\"NL29ABNA050988XXXX\",\"bic\":\"ABNANL2AXXX\",\"countryCode\":\"NL\",\"sepaMandate\":" - + "{\"description\":\"Unit Test Mandate\",\"status\":\"SIGNED\",\"type\":\"RECURRENT\",\"scheme\":" - + "\"CORE\",\"signatureType\":\"SMS\",\"phoneNumber\":\"+34123456789\",\"signedAt\":1516448821000," - + "\"createdAt\":1516448795000,\"lastUsedAt\":1516448832000,\"downloadUrl\":" - + "\"https://fake.url/mandate/man654322/dl\"}},\"statementDescriptor\":\"Test statement descriptor\"," - + "\"collectedAt\":1516579200000},\"shopper\":{\"name\":\"John Snow\",\"address\":\"Calle Mallorca, 66\"," - + "\"zipcode\":\"08008\",\"city\":\"Barcelona\",\"state\":\"Barcelona\",\"countryCode\":\"ES\"," - + "\"email\":\"dev@payxpert.com\",\"ipAddress\":\"127.0.0.1\"},\"operation\":\"collection\"," - + "\"resultCode\":\"000\",\"resultMessage\":\"Transaction successfully completed\",\"status\":" - + "\"Authorized\",\"transactionID\":\"4reazyd5ln-g5ty\"},{\"refTransactionID\":\"4reazyd5ln-g5ty\"," - + "\"date\":1517559172000,\"amount\":2548,\"paymentType\":\"Chargeback\",\"paymentMeanInfo\":" - + "{\"date\":1517554885000,\"reasonCode\":\"AC01\"},\"shopper\":{\"name\":" - + "\"John Snow\",\"address\":\"Calle Mallorca, 66\",\"zipcode\":\"08008\",\"city\":\"Barcelona\"," - + "\"state\":\"Barcelona\",\"countryCode\":\"ES\",\"email\":\"dev@payxpert.com\",\"ipAddress\":" - + "\"127.0.0.1\"},\"resultCode\":\"000\",\"resultMessage\":\"Transaction successfully completed\"," - + "\"status\":\"Authorized\",\"transactionID\":\"4reazyd5ln-vgt7\"}],\"status\":\"Authorized\"," - + "\"merchantToken\":\"4y4-GXqzNyOLJNX8BPzUbA\",\"operation\":\"submission\",\"errorCode\":\"000\"," - + "\"errorMessage\":\"Transaction successfully completed\",\"orderID\":\"1234567E1\",\"currency\":\"EUR\",\"amount\":2548}"; - - return new PaymentStatusResponse().fromJson(json); - } - - public static PaymentStatusResponse getResponseFromJSONWithReversal() throws Exception { - String json = "{\"transactions\":[{\"date\":1516448832000,\"amount\":2548,\"paymentType\":" - + "\"DirectDebit\",\"paymentMeanInfo\":{\"bankAccount\":{\"holderName\":\"John Snow\"," - + "\"bankName\":\"BNP\",\"iban\":\"NL29ABNA050988XXXX\",\"bic\":\"ABNANL2AXXX\"," - + "\"countryCode\":\"NL\",\"sepaMandate\":{\"description\":\"Unit Test Mandate\"," - + "\"status\":\"SIGNED\",\"type\":\"RECURRENT\",\"scheme\":\"CORE\",\"signatureType\":\"SMS\"," - + "\"phoneNumber\":\"+34123456789\",\"signedAt\":1516448821000,\"createdAt\":1516448795000," - + "\"lastUsedAt\":1516448832000,\"downloadUrl\":\"https://fake.url/mandate/man654322/dl\"}}," - + "\"statementDescriptor\":\"Test statement descriptor\",\"collectedAt\":1516579200000}," - + "\"shopper\":{\"name\":\"John Snow\",\"address\":\"Calle Mallorca, 66\",\"zipcode\":\"08008\"," - + "\"city\":\"Barcelona\",\"state\":\"Barcelona\",\"countryCode\":\"ES\",\"email\":" - + "\"dev@payxpert.com\",\"ipAddress\":\"127.0.0.1\"},\"operation\":\"submission\"," - + "\"resultCode\":\"000\",\"resultMessage\":\"Transaction successfully completed\"," - + "\"status\":\"Authorized\",\"transactionID\":\"4reazyd5ln-4v8e\"},{\"refTransactionID\":" - + "\"4reazyd5ln-4v8e\",\"date\":1516596043000,\"amount\":2548,\"paymentType\":\"DirectDebit\"," - + "\"paymentMeanInfo\":{\"bankAccount\":{\"holderName\":\"John Snow\",\"bankName\":\"BNP\"," - + "\"iban\":\"NL29ABNA050988XXXX\",\"bic\":\"ABNANL2AXXX\",\"countryCode\":\"NL\",\"sepaMandate\":" - + "{\"description\":\"Unit Test Mandate\",\"status\":\"SIGNED\",\"type\":\"RECURRENT\",\"scheme\":" - + "\"CORE\",\"signatureType\":\"SMS\",\"phoneNumber\":\"+34123456789\",\"signedAt\":1516448821000," - + "\"createdAt\":1516448795000,\"lastUsedAt\":1516448832000,\"downloadUrl\":" - + "\"https://fake.url/mandate/man654322/dl\"}},\"statementDescriptor\":\"Test statement descriptor\"," - + "\"collectedAt\":1516579200000},\"shopper\":{\"name\":\"John Snow\",\"address\":\"Calle Mallorca, 66\"," - + "\"zipcode\":\"08008\",\"city\":\"Barcelona\",\"state\":\"Barcelona\",\"countryCode\":\"ES\"," - + "\"email\":\"dev@payxpert.com\",\"ipAddress\":\"127.0.0.1\"},\"operation\":\"collection\"," - + "\"resultCode\":\"000\",\"resultMessage\":\"Transaction successfully completed\",\"status\":" - + "\"Authorized\",\"transactionID\":\"4reazyd5ln-g5ty\"},{\"refTransactionID\":\"4reazyd5ln-g5ty\"," - + "\"date\":1517559172000,\"amount\":2548,\"paymentType\":\"Reversal\",\"paymentMeanInfo\":" - + "{\"date\":1517554885000,\"reasonCode\":\"MD01\"},\"shopper\":{\"name\":" - + "\"John Snow\",\"address\":\"Calle Mallorca, 66\",\"zipcode\":\"08008\",\"city\":\"Barcelona\"," - + "\"state\":\"Barcelona\",\"countryCode\":\"ES\",\"email\":\"dev@payxpert.com\",\"ipAddress\":" - + "\"127.0.0.1\"},\"resultCode\":\"000\",\"resultMessage\":\"Transaction successfully completed\"," - + "\"status\":\"Authorized\",\"transactionID\":\"4reazyd5ln-vgt7\"}],\"status\":\"Authorized\"," - + "\"merchantToken\":\"4y4-GXqzNyOLJNX8BPzUbA\",\"operation\":\"submission\",\"errorCode\":\"000\"," - + "\"errorMessage\":\"Transaction successfully completed\",\"orderID\":\"1234567E1\",\"currency\":\"EUR\",\"amount\":2548}"; - - return new PaymentStatusResponse().fromJson(json); - } - -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/TransactionCancelResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/TransactionCancelResponseTest.java deleted file mode 100644 index 775f846..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/TransactionCancelResponseTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import org.junit.Assert; -import org.junit.Test; - -import com.payxpert.connect2pay.constants.TransactionOperation; - -public class TransactionCancelResponseTest { - @Test - public void testTransactionCancelResponseDeserialization() throws Exception { - String json = "{\"transactionID\":\"1kva092fgq-01-r05\",\"code\":\"012\",\"message\":\"Invalid Transaction\",\"operation\":\"cancel\"}"; - TransactionCancelResponse response = new TransactionCancelResponse().fromJson(json); - - Assert.assertNotNull(response); - Assert.assertEquals("012", response.getCode()); - Assert.assertEquals("1kva092fgq-01-r05", response.getTransactionId()); - Assert.assertEquals("Invalid Transaction", response.getMessage()); - Assert.assertEquals(TransactionOperation.CANCEL, response.getOperation()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/TransactionInfoResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/TransactionInfoResponseTest.java deleted file mode 100644 index a3f0205..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/TransactionInfoResponseTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; - -import com.payxpert.connect2pay.client.containers.TransactionAttempt; -import com.payxpert.connect2pay.client.containers.TransactionAttemptTest; -import com.payxpert.connect2pay.constants.ResultCode; - -public class TransactionInfoResponseTest { - @Test - public void testTransactionInfoResponse() { - TransactionInfoResponse response = getDefaultResponse(); - - assertEquals(ResultCode.SUCCESS, response.getCode()); - - TransactionAttempt transactionAttempt = response.getTransactionInfo(); - assertNotNull(transactionAttempt); - assertEquals("000", transactionAttempt.getResultCode()); - assertEquals("Success", transactionAttempt.getResultMessage()); - } - - public static TransactionInfoResponse getDefaultResponse() { - TransactionInfoResponse response = new TransactionInfoResponse(); - response.setCode(ResultCode.SUCCESS); - - TransactionAttempt transactionAttempt = new TransactionAttemptTest().getDefaultTransactionAttempt(); - response.setTransactionInfo(transactionAttempt); - - return response; - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/TransactionRebillResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/TransactionRebillResponseTest.java deleted file mode 100644 index 3fb3881..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/TransactionRebillResponseTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import org.junit.Assert; -import org.junit.Test; - -import com.payxpert.connect2pay.constants.TransactionOperation; - -public class TransactionRebillResponseTest { - @Test - public void testTransactionRebillResponseDeserialization() throws Exception { - String json = "{\"transactionID\":\"1kva092fgq-01-r05\",\"code\":\"012\",\"message\":\"Invalid Transaction\",\"operation\":\"submission\"}"; - TransactionRebillResponse response = new TransactionRebillResponse().fromJson(json); - - Assert.assertNotNull(response); - Assert.assertEquals("012", response.getCode()); - Assert.assertEquals("1kva092fgq-01-r05", response.getTransactionId()); - Assert.assertEquals("Invalid Transaction", response.getMessage()); - Assert.assertEquals(TransactionOperation.SUBMISSION, response.getOperation()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/TransactionRefundConfirmResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/TransactionRefundConfirmResponseTest.java deleted file mode 100644 index be7cf83..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/TransactionRefundConfirmResponseTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import org.junit.Assert; -import org.junit.Test; - -import com.payxpert.connect2pay.constants.TransactionOperation; - -public class TransactionRefundConfirmResponseTest { - @Test - public void testTransactionRefundResponseDeserialization() throws Exception { - String json = "{\"transactionID\":\"1kva092fgq-01-r05\",\"code\":\"012\",\"message\":\"Invalid Transaction\",\"operation\":\"refund\"}"; - TransactionRefundResponse response = new TransactionRefundResponse().fromJson(json); - - Assert.assertNotNull(response); - Assert.assertEquals("012", response.getCode()); - Assert.assertEquals("1kva092fgq-01-r05", response.getTransactionId()); - Assert.assertEquals("Invalid Transaction", response.getMessage()); - Assert.assertEquals(TransactionOperation.REFUND, response.getOperation()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/TransactionRefundResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/TransactionRefundResponseTest.java deleted file mode 100644 index 1192434..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/TransactionRefundResponseTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import org.junit.Assert; -import org.junit.Test; - -import com.payxpert.connect2pay.constants.TransactionOperation; - -public class TransactionRefundResponseTest { - @Test - public void testTransactionRefundResponseDeserialization() throws Exception { - String json = "{\"transactionID\":\"1kva092fgq-01-r05\",\"code\":\"012\",\"message\":\"Invalid Transaction\",\"operation\":\"refund_request\"}"; - TransactionRefundResponse response = new TransactionRefundResponse().fromJson(json); - - Assert.assertNotNull(response); - Assert.assertEquals("012", response.getCode()); - Assert.assertEquals("1kva092fgq-01-r05", response.getTransactionId()); - Assert.assertEquals("Invalid Transaction", response.getMessage()); - Assert.assertEquals(TransactionOperation.REFUND_REQUEST, response.getOperation()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/client/response/WeChatDirectProcessResponseTest.java b/src/test/java/com/payxpert/connect2pay/client/response/WeChatDirectProcessResponseTest.java deleted file mode 100644 index 5670d98..0000000 --- a/src/test/java/com/payxpert/connect2pay/client/response/WeChatDirectProcessResponseTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.payxpert.connect2pay.client.response; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; - -import com.payxpert.connect2pay.constants.ResultCode; - -public class WeChatDirectProcessResponseTest { - @Test - public void testWeChatDirectProcessResponse() throws Exception { - String json = "{\"apiVersion\":\"002.60\",\"code\":\"200\",\"message\":\"Request processed successfully\"," - + "\"webSocketUrl\":\"ws://connect2pay.dev.payxpert.com:9001/wsock/payment/gfrbFvsuAdDvPXYVyOFrhw/wait/restricted/x8la6mw44e-fwg9\"," - + "\"transactionID\":\"x8la6mw44e-1ouu\"}"; - - WeChatDirectProcessResponse response = new WeChatDirectProcessResponse().fromJson(json); - assertNotNull(response); - assertEquals("002.60", response.getApiVersion()); - assertEquals(ResultCode.SUCCESS, response.getCode()); - assertEquals("Request processed successfully", response.getMessage()); - assertEquals( - "ws://connect2pay.dev.payxpert.com:9001/wsock/payment/gfrbFvsuAdDvPXYVyOFrhw/wait/restricted/x8la6mw44e-fwg9", - response.getWebSocketUrl()); - assertEquals("x8la6mw44e-1ouu", response.getTransactionId()); - } -} diff --git a/src/test/java/com/payxpert/connect2pay/utils/PartPaymentTest.java b/src/test/java/com/payxpert/connect2pay/utils/PartPaymentTest.java deleted file mode 100644 index 1a13831..0000000 --- a/src/test/java/com/payxpert/connect2pay/utils/PartPaymentTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.payxpert.connect2pay.utils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.payxpert.connect2pay.constants.SubscriptionType; -import com.payxpert.connect2pay.utils.PartPayment; - -public class PartPaymentTest { - - @Test - public void testValidPartPayment() { - PartPayment payment = new PartPayment(5000, 3); - assertFalse(payment.isResultValid()); - assertTrue(payment.compute()); - assertTrue(payment.isResultValid()); - assertEquals(SubscriptionType.NORMAL, payment.getSubscriptionType()); - assertEquals(2, payment.getMaxIterations()); - assertEquals(1668, payment.getInitialAmount()); - assertEquals(1666, payment.getRebillAmount()); - - payment.setAmount(3533); - assertFalse(payment.isResultValid()); - assertTrue(payment.compute()); - assertTrue(payment.isResultValid()); - assertEquals(SubscriptionType.NORMAL, payment.getSubscriptionType()); - assertEquals(2, payment.getMaxIterations()); - assertEquals(1179, payment.getInitialAmount()); - assertEquals(1177, payment.getRebillAmount()); - - payment.setPartNumber(7); - assertFalse(payment.isResultValid()); - assertTrue(payment.compute()); - assertTrue(payment.isResultValid()); - assertEquals(SubscriptionType.NORMAL, payment.getSubscriptionType()); - assertEquals(6, payment.getMaxIterations()); - assertEquals(509, payment.getInitialAmount()); - assertEquals(504, payment.getRebillAmount()); - - payment.setAmount(3533); - payment.setPartNumber(3533); - assertFalse(payment.isResultValid()); - assertTrue(payment.compute()); - assertTrue(payment.isResultValid()); - assertEquals(SubscriptionType.NORMAL, payment.getSubscriptionType()); - assertEquals(3532, payment.getMaxIterations()); - assertEquals(1, payment.getInitialAmount()); - assertEquals(1, payment.getRebillAmount()); - } - - @Test - public void testInvalidPartPayment() { - PartPayment payment = new PartPayment(-1000, 3); - assertFalse(payment.compute()); - assertFalse(payment.isResultValid()); - - payment.setAmount(2); - assertFalse(payment.compute()); - assertFalse(payment.isResultValid()); - - payment.setAmount(-1000); - payment.setPartNumber(-1); - assertFalse(payment.compute()); - assertFalse(payment.isResultValid()); - - payment.setAmount(1000); - payment.setPartNumber(-1); - assertFalse(payment.compute()); - assertFalse(payment.isResultValid()); - - payment.setAmount(1000); - payment.setPartNumber(-13); - assertFalse(payment.compute()); - assertFalse(payment.isResultValid()); - - payment.setAmount(0); - payment.setPartNumber(-13); - assertFalse(payment.compute()); - assertFalse(payment.isResultValid()); - - payment.setAmount(0); - payment.setPartNumber(0); - assertFalse(payment.compute()); - assertFalse(payment.isResultValid()); - - payment.setAmount(3000); - payment.setPartNumber(0); - assertFalse(payment.compute()); - assertFalse(payment.isResultValid()); - - } -} diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml deleted file mode 100644 index 548a8e1..0000000 --- a/src/test/resources/logback-test.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - \ No newline at end of file