Skip to content

Commit fb94a14

Browse files
Merge pull request #490 from sgilrodriguez/master
2 parents 420c4b6 + 3007787 commit fb94a14

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed

src/main/java/com/ning/billing/recurly/model/Purchase.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public class Purchase extends RecurlyObject {
8888
@XmlElement(name = "transaction_type")
8989
private String transactionType;
9090

91+
@XmlElement(name = "vertex_transaction_type")
92+
private String vertexTransactionType;
93+
9194
@XmlList
9295
@XmlElementWrapper(name = "coupon_codes")
9396
@XmlElement(name = "coupon_code")
@@ -245,6 +248,14 @@ public void setTransactionType(final Object transactionType) {
245248
this.transactionType = stringOrNull(transactionType);
246249
}
247250

251+
public String getVertexTransactionType() {
252+
return vertexTransactionType;
253+
}
254+
255+
public void setVertexTransactionType(final Object vertexTransactionType) {
256+
this.vertexTransactionType = stringOrNull(vertexTransactionType);
257+
}
258+
248259
@Override
249260
public String toString() {
250261
final StringBuilder sb = new StringBuilder();
@@ -268,6 +279,7 @@ public String toString() {
268279
sb.append(", shippingAddressId='").append(shippingAddressId).append('\'');
269280
sb.append(", gatewayCode='").append(gatewayCode).append('\'');
270281
sb.append(", transactionType='").append(transactionType).append('\'');
282+
sb.append(", vertexTransactionType='").append(vertexTransactionType).append('\'');
271283
sb.append('}');
272284
return sb.toString();
273285
}
@@ -333,6 +345,9 @@ public boolean equals(final Object o) {
333345
if (transactionType != null ? !transactionType.equals(purchase.transactionType) : purchase.transactionType != null) {
334346
return false;
335347
}
348+
if (vertexTransactionType != null ? !vertexTransactionType.equals(purchase.vertexTransactionType) : purchase.vertexTransactionType != null) {
349+
return false;
350+
}
336351
if (vatReverseChargeNotes != null ? !vatReverseChargeNotes.equals(purchase.vatReverseChargeNotes) : purchase.vatReverseChargeNotes != null) {
337352
return false;
338353
}
@@ -361,7 +376,8 @@ public int hashCode() {
361376
billingInfoUuid,
362377
shippingAddressId,
363378
gatewayCode,
364-
transactionType
379+
transactionType,
380+
vertexTransactionType
365381
);
366382
}
367383

src/test/java/com/ning/billing/recurly/model/TestPurchase.java

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,94 @@ public void testSerializationWithBillingInfoUuid() throws Exception {
207207

208208
public void verifyPurchaseWithBillingInfoUuid(final Purchase purchase) {
209209
assertEquals(purchase.getBillingInfoUuid(), "iiznlrvdt8py");
210-
}
210+
}
211+
212+
@Test(groups = "fast")
213+
public void testSerializationWithVertexTransactionType() throws Exception {
214+
final String purchaseData = "<purchase xmlns=\"\">" +
215+
"<currency>USD</currency>" +
216+
" <collection_method>automatic</collection_method>" +
217+
" <vertex_transaction_type>rental</vertex_transaction_type>" +
218+
" <account>" +
219+
" <account_code>test</account_code>" +
220+
" <billing_info>" +
221+
" <first_name>Benjamin</first_name>" +
222+
" <last_name>Du Monde</last_name>" +
223+
" <address1>400 Alabama St</address1>" +
224+
" <city>San Francisco</city>" +
225+
" <state>CA</state>" +
226+
" <zip>94110</zip>" +
227+
" <country>US</country>" +
228+
" <year type=\"integer\">2019</year>" +
229+
" <month type=\"integer\">12</month>" +
230+
" <number>4000-0000-0000-0000</number>" +
231+
" </billing_info>" +
232+
" </account>" +
233+
" <adjustments>" +
234+
" <adjustment>" +
235+
" <unit_amount_in_cents type=\"integer\">1000</unit_amount_in_cents>" +
236+
" <quantity type=\"integer\">1</quantity>" +
237+
" <currency>USD</currency>" +
238+
" <product_code>product-code</product_code>" +
239+
" </adjustment>" +
240+
" </adjustments>" +
241+
"</purchase>";
242+
243+
// test serialization
244+
final Purchase purchase = xmlMapper.readValue(purchaseData, Purchase.class);
245+
verifyPurchaseWithVertexTransactionType(purchase);
246+
247+
// test deseralization
248+
final Purchase purchaseExpected = xmlMapper.readValue(purchaseData, Purchase.class);
249+
assertEquals(purchase, purchaseExpected);
250+
}
251+
252+
public void verifyPurchaseWithVertexTransactionType(final Purchase purchase) {
253+
assertEquals(purchase.getVertexTransactionType(), "rental");
254+
assertEquals(purchase.getCurrency(), "USD");
255+
assertEquals(purchase.getCollectionMethod(), "automatic");
256+
}
257+
258+
@Test(groups = "fast")
259+
public void testSerializationToXmlWithVertexTransactionType() throws Exception {
260+
// Create purchase object programmatically and verify it serializes correctly to XML
261+
final Purchase purchase = new Purchase();
262+
purchase.setCurrency("USD");
263+
purchase.setCollectionMethod("automatic");
264+
purchase.setVertexTransactionType("lease");
265+
266+
final Account account = new Account();
267+
account.setAccountCode("test-account");
268+
purchase.setAccount(account);
269+
270+
// Serialize to XML string
271+
final String xml = xmlMapper.writeValueAsString(purchase);
272+
273+
// Verify the XML contains the vertex_transaction_type element
274+
assert xml.contains("<vertex_transaction_type>lease</vertex_transaction_type>") :
275+
"Serialized XML should contain vertex_transaction_type element";
276+
assert xml.contains("<collection_method>automatic</collection_method>");
277+
assert xml.contains("<currency>USD</currency>");
278+
}
279+
280+
@Test(groups = "fast")
281+
public void testVertexTransactionTypeAllValidValues() throws Exception {
282+
// Test all valid values: sale, rental, lease
283+
final String[] validValues = {"sale", "rental", "lease"};
284+
285+
for (String value : validValues) {
286+
final Purchase purchase = new Purchase();
287+
purchase.setVertexTransactionType(value);
288+
assertEquals(purchase.getVertexTransactionType(), value,
289+
"Should correctly set and get value: " + value);
290+
291+
// Verify serialization/deserialization round-trip
292+
final String xml = xmlMapper.writeValueAsString(purchase);
293+
final Purchase deserializedPurchase = xmlMapper.readValue(xml, Purchase.class);
294+
assertEquals(deserializedPurchase.getVertexTransactionType(), value,
295+
"Should correctly deserialize value: " + value);
296+
}
297+
}
211298

212299
@Test(groups = "fast")
213300
public void testHashCodeAndEquality() throws Exception {

0 commit comments

Comments
 (0)