diff --git a/src/main/java/com/ning/billing/recurly/model/Errors.java b/src/main/java/com/ning/billing/recurly/model/Errors.java
index a7f3b3f7..72375c4e 100644
--- a/src/main/java/com/ning/billing/recurly/model/Errors.java
+++ b/src/main/java/com/ning/billing/recurly/model/Errors.java
@@ -68,7 +68,7 @@ public void setRecurlyErrors(final Object recurlyError) {
}
this.recurlyErrors.add(error);
} else {
- this.recurlyErrors = (RecurlyErrors) recurlyErrors;
+ this.recurlyErrors = (RecurlyErrors) recurlyError;
}
}
@@ -114,4 +114,4 @@ public int hashCode() {
recurlyErrors
);
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/com/ning/billing/recurly/model/TestErrors.java b/src/test/java/com/ning/billing/recurly/model/TestErrors.java
index f67650a9..a2ebde41 100644
--- a/src/test/java/com/ning/billing/recurly/model/TestErrors.java
+++ b/src/test/java/com/ning/billing/recurly/model/TestErrors.java
@@ -20,14 +20,17 @@
import org.testng.Assert;
import org.testng.annotations.Test;
+import java.util.HashMap;
+import java.util.Map;
+
public class TestErrors extends TestModelBase {
@Test(groups = "fast")
public void testSerializationErrors() throws Exception {
final String errorsData = "\n" +
- " can't be empty\n" +
- " must be less than 2050\n" +
- "";
+ " can't be empty\n" +
+ " must be less than 2050\n" +
+ "";
final Errors errors = xmlMapper.readValue(errorsData, Errors.class);
Assert.assertEquals(errors.getRecurlyErrors().get(0).getField(), "billing_info.address1");
@@ -41,71 +44,75 @@ public void testSerializationErrors() throws Exception {
@Test(groups = "fast")
public void testSerializationTransactionErrors() throws Exception {
final String errorsData = "\n" +
- " \n" +
- " fraud_ip_address\n" +
- " fraud\n" +
- " The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.\n" +
- " The transaction was declined. Please contact support.\n" +
- " \n" +
- " The transaction was declined. Please contact support.\n" +
- " \n" +
- " \n" +
- " 12578bb566572144deb5364d4ebd32ce\n" +
- " verify\n" +
- " 0\n" +
- " 0\n" +
- " USD\n" +
- " declined\n" +
- " 8433694\n" +
- " billing_info\n" +
- " false\n" +
- " true\n" +
- " false\n" +
- " false\n" +
- " \n" +
- " fraud_ip_address\n" +
- " fraud\n" +
- " The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.\n" +
- " The transaction was declined. Please contact support.\n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " 2013-09-04T11:34:21Z\n" +
- " \n" +
- " \n" +
- " 4503f4df-acab-4097-9245-f4c130b5f9ac\n" +
- " 248e5\n" +
- " f1a42f\n" +
- " 2a08b4344e\n" +
- " 0a39@test.com\n" +
- " \n" +
- " 0dec5\n" +
- " 91faa8\n" +
- " 680a5d6012\n" +
- " cf66c41dea\n" +
- " b77f65bff7\n" +
- " c3274dd270\n" +
- " b12f7\n" +
- " f0ba2\n" +
- " 6\n" +
- " 7\n" +
- " Visa\n" +
- " 2015\n" +
- " 11\n" +
- " 400000\n" +
- " 0093\n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- "";
+ " \n" +
+ " fraud_ip_address\n" +
+ " fraud\n" +
+ " The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.\n" +
+ " The transaction was declined. Please contact support.\n" +
+ " \n" +
+ " The transaction was declined. Please contact support.\n" +
+ " \n" +
+ " \n" +
+ " 12578bb566572144deb5364d4ebd32ce\n" +
+ " verify\n" +
+ " 0\n" +
+ " 0\n" +
+ " USD\n" +
+ " declined\n" +
+ " 8433694\n" +
+ " billing_info\n" +
+ " false\n" +
+ " true\n" +
+ " false\n" +
+ " false\n" +
+ " \n" +
+ " fraud_ip_address\n" +
+ " fraud\n" +
+ " The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.\n" +
+ " The transaction was declined. Please contact support.\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " 2013-09-04T11:34:21Z\n" +
+ " \n" +
+ " \n" +
+ " 4503f4df-acab-4097-9245-f4c130b5f9ac\n" +
+ " 248e5\n" +
+ " f1a42f\n" +
+ " 2a08b4344e\n" +
+ " 0a39@test.com\n" +
+ " \n" +
+ " 0dec5\n" +
+ " 91faa8\n" +
+ " 680a5d6012\n" +
+ " cf66c41dea\n" +
+ " b77f65bff7\n" +
+ " c3274dd270\n" +
+ " b12f7\n" +
+ " f0ba2\n" +
+ " 6\n" +
+ " 7\n" +
+ " Visa\n" +
+ " 2015\n" +
+ " 11\n" +
+ " 400000\n" +
+ " 0093\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "";
final Errors errors = xmlMapper.readValue(errorsData, Errors.class);
Assert.assertEquals(errors.getTransactionError().getErrorCode(), "fraud_ip_address");
- Assert.assertEquals(errors.getTransactionError().getMerchantMessage(), "The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.");
- Assert.assertEquals(errors.getTransactionError().getCustomerMessage(), "The transaction was declined. Please contact support.");
+ Assert.assertEquals(
+ errors.getTransactionError().getMerchantMessage(),
+ "The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.");
+ Assert.assertEquals(
+ errors.getTransactionError().getCustomerMessage(),
+ "The transaction was declined. Please contact support.");
Assert.assertEquals(errors.getTransaction().getUuid(), "12578bb566572144deb5364d4ebd32ce");
Assert.assertEquals(errors.getTransaction().getAction(), "verify");
@@ -120,10 +127,16 @@ public void testSerializationTransactionErrors() throws Exception {
Assert.assertFalse(errors.getTransaction().getVoidable());
Assert.assertFalse(errors.getTransaction().getRefundable());
Assert.assertEquals(errors.getTransaction().getTransactionError().getErrorCode(), "fraud_ip_address");
- Assert.assertEquals(errors.getTransaction().getTransactionError().getMerchantMessage(), "The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.");
- Assert.assertEquals(errors.getTransaction().getTransactionError().getCustomerMessage(), "The transaction was declined. Please contact support.");
+ Assert.assertEquals(
+ errors.getTransaction().getTransactionError().getMerchantMessage(),
+ "The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.");
+ Assert.assertEquals(
+ errors.getTransaction().getTransactionError().getCustomerMessage(),
+ "The transaction was declined. Please contact support.");
- Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getAccountCode(), "4503f4df-acab-4097-9245-f4c130b5f9ac");
+ Assert.assertEquals(
+ errors.getTransaction().getDetails().getAccount().getAccountCode(),
+ "4503f4df-acab-4097-9245-f4c130b5f9ac");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getFirstName(), "248e5");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getLastName(), "f1a42f");
// TODO Element not consistent with Account API
@@ -131,18 +144,62 @@ public void testSerializationTransactionErrors() throws Exception {
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getEmail(), "0a39@test.com");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getFirstName(), "0dec5");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getLastName(), "91faa8");
- Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getAddress1(), "680a5d6012");
- Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getAddress2(), "cf66c41dea");
+ Assert.assertEquals(
+ errors.getTransaction().getDetails().getAccount().getBillingInfo().getAddress1(),
+ "680a5d6012");
+ Assert.assertEquals(
+ errors.getTransaction().getDetails().getAccount().getBillingInfo().getAddress2(),
+ "cf66c41dea");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getCity(), "b77f65bff7");
- Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getState(), "c3274dd270");
+ Assert.assertEquals(
+ errors.getTransaction().getDetails().getAccount().getBillingInfo().getState(),
+ "c3274dd270");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getZip(), "b12f7");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getCountry(), "f0ba2");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getPhone(), "6");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getVatNumber(), "7");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getCardType(), "Visa");
- Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getYear(), (Integer) 2015);
- Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getMonth(), (Integer) 11);
+ Assert.assertEquals(
+ errors.getTransaction().getDetails().getAccount().getBillingInfo().getYear(),
+ (Integer) 2015);
+ Assert.assertEquals(
+ errors.getTransaction().getDetails().getAccount().getBillingInfo().getMonth(),
+ (Integer) 11);
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getFirstSix(), "400000");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getLastFour(), "0093");
}
+
+ @Test(groups = "fast")
+ public void testShouldCreateRecurlyErrorsFromMap() {
+ Map recurlyErrorMap = new HashMap();
+ recurlyErrorMap.put(
+ "field",
+ "account base");
+ recurlyErrorMap.put(
+ "",
+ "transaction declined.");
+ recurlyErrorMap.put(
+ "symbol",
+ "fraud_velocity");
+
+ Errors errors = new Errors();
+ errors.setRecurlyErrors(recurlyErrorMap);
+
+ Assert.assertEquals(errors.getRecurlyErrors().size(), 1);
+ }
+
+ @Test(groups = "fast")
+ public void testShouldCreateRecurlyErrorsFromClass() {
+ RecurlyError recurlyError = new RecurlyError();
+ recurlyError.setField("account base");
+ recurlyError.setSymbol("fraud_velocity");
+ recurlyError.setMessage("transaction declined.");
+ RecurlyErrors recurlyErrors = new RecurlyErrors();
+ recurlyErrors.add(recurlyError);
+
+ Errors errors = new Errors();
+ errors.setRecurlyErrors(recurlyErrors);
+
+ Assert.assertEquals(errors.getRecurlyErrors().size(), 1);
+ }
}