|
23 | 23 |
|
24 | 24 | import static org.testng.Assert.assertEquals; |
25 | 25 | import static org.testng.Assert.assertNotEquals; |
| 26 | +import static org.testng.Assert.assertNull; |
26 | 27 |
|
27 | 28 | public class TestPurchase extends TestModelBase { |
28 | 29 |
|
@@ -296,6 +297,129 @@ public void testVertexTransactionTypeAllValidValues() throws Exception { |
296 | 297 | } |
297 | 298 | } |
298 | 299 |
|
| 300 | + @Test(groups = "fast") |
| 301 | + public void testPurchaseWithAdjustmentLevelVertexTransactionType() throws Exception { |
| 302 | + // Test purchase with adjustment-level vertex_transaction_type |
| 303 | + final String purchaseData = "<purchase xmlns=\"\">" + |
| 304 | + "<currency>USD</currency>" + |
| 305 | + " <collection_method>automatic</collection_method>" + |
| 306 | + " <vertex_transaction_type>sale</vertex_transaction_type>" + |
| 307 | + " <account>" + |
| 308 | + " <account_code>test-account</account_code>" + |
| 309 | + " </account>" + |
| 310 | + " <adjustments>" + |
| 311 | + " <adjustment>" + |
| 312 | + " <unit_amount_in_cents type=\"integer\">1000</unit_amount_in_cents>" + |
| 313 | + " <quantity type=\"integer\">1</quantity>" + |
| 314 | + " <currency>USD</currency>" + |
| 315 | + " <product_code>product-1</product_code>" + |
| 316 | + " <vertex_transaction_type>lease</vertex_transaction_type>" + |
| 317 | + " </adjustment>" + |
| 318 | + " </adjustments>" + |
| 319 | + "</purchase>"; |
| 320 | + |
| 321 | + // Deserialize and verify |
| 322 | + final Purchase purchase = xmlMapper.readValue(purchaseData, Purchase.class); |
| 323 | + assertEquals(purchase.getVertexTransactionType(), "sale"); |
| 324 | + assertEquals(purchase.getAdjustments().size(), 1); |
| 325 | + assertEquals(purchase.getAdjustments().get(0).getVertexTransactionType(), "lease"); |
| 326 | + } |
| 327 | + |
| 328 | + @Test(groups = "fast") |
| 329 | + public void testPurchaseWithMultipleAdjustmentsWithDifferentVertexTransactionTypes() throws Exception { |
| 330 | + // Test purchase with multiple adjustments having different vertex_transaction_type values |
| 331 | + final String purchaseData = "<purchase xmlns=\"\">" + |
| 332 | + "<currency>USD</currency>" + |
| 333 | + " <vertex_transaction_type>sale</vertex_transaction_type>" + |
| 334 | + " <account>" + |
| 335 | + " <account_code>test-account</account_code>" + |
| 336 | + " </account>" + |
| 337 | + " <adjustments>" + |
| 338 | + " <adjustment>" + |
| 339 | + " <unit_amount_in_cents type=\"integer\">5000</unit_amount_in_cents>" + |
| 340 | + " <quantity type=\"integer\">1</quantity>" + |
| 341 | + " <currency>USD</currency>" + |
| 342 | + " <product_code>product-lease</product_code>" + |
| 343 | + " <vertex_transaction_type>lease</vertex_transaction_type>" + |
| 344 | + " </adjustment>" + |
| 345 | + " <adjustment>" + |
| 346 | + " <unit_amount_in_cents type=\"integer\">3000</unit_amount_in_cents>" + |
| 347 | + " <quantity type=\"integer\">1</quantity>" + |
| 348 | + " <currency>USD</currency>" + |
| 349 | + " <product_code>product-rental</product_code>" + |
| 350 | + " <vertex_transaction_type>rental</vertex_transaction_type>" + |
| 351 | + " </adjustment>" + |
| 352 | + " <adjustment>" + |
| 353 | + " <unit_amount_in_cents type=\"integer\">2000</unit_amount_in_cents>" + |
| 354 | + " <quantity type=\"integer\">1</quantity>" + |
| 355 | + " <currency>USD</currency>" + |
| 356 | + " <product_code>product-no-vtt</product_code>" + |
| 357 | + " </adjustment>" + |
| 358 | + " </adjustments>" + |
| 359 | + "</purchase>"; |
| 360 | + |
| 361 | + // Deserialize and verify |
| 362 | + final Purchase purchase = xmlMapper.readValue(purchaseData, Purchase.class); |
| 363 | + assertEquals(purchase.getVertexTransactionType(), "sale"); |
| 364 | + assertEquals(purchase.getAdjustments().size(), 3); |
| 365 | + assertEquals(purchase.getAdjustments().get(0).getVertexTransactionType(), "lease"); |
| 366 | + assertEquals(purchase.getAdjustments().get(1).getVertexTransactionType(), "rental"); |
| 367 | + assertNull(purchase.getAdjustments().get(2).getVertexTransactionType()); |
| 368 | + } |
| 369 | + |
| 370 | + @Test(groups = "fast") |
| 371 | + public void testSerializePurchaseWithAdjustmentLevelVertexTransactionType() throws Exception { |
| 372 | + // Create purchase programmatically with adjustment-level vertex_transaction_type |
| 373 | + final Purchase purchase = new Purchase(); |
| 374 | + purchase.setCurrency("USD"); |
| 375 | + purchase.setCollectionMethod("automatic"); |
| 376 | + purchase.setVertexTransactionType("sale"); |
| 377 | + |
| 378 | + final Account account = new Account(); |
| 379 | + account.setAccountCode("test-account"); |
| 380 | + purchase.setAccount(account); |
| 381 | + |
| 382 | + // Create adjustments with different vertex_transaction_type values |
| 383 | + final Adjustments adjustments = new Adjustments(); |
| 384 | + |
| 385 | + final Adjustment adjustment1 = new Adjustment(); |
| 386 | + adjustment1.setUnitAmountInCents(5000); |
| 387 | + adjustment1.setQuantity(1); |
| 388 | + adjustment1.setCurrency("USD"); |
| 389 | + adjustment1.setProductCode("product-lease"); |
| 390 | + adjustment1.setVertexTransactionType("lease"); |
| 391 | + adjustments.add(adjustment1); |
| 392 | + |
| 393 | + final Adjustment adjustment2 = new Adjustment(); |
| 394 | + adjustment2.setUnitAmountInCents(3000); |
| 395 | + adjustment2.setQuantity(1); |
| 396 | + adjustment2.setCurrency("USD"); |
| 397 | + adjustment2.setProductCode("product-rental"); |
| 398 | + adjustment2.setVertexTransactionType("rental"); |
| 399 | + adjustments.add(adjustment2); |
| 400 | + |
| 401 | + purchase.setAdjustments(adjustments); |
| 402 | + |
| 403 | + // Serialize to XML |
| 404 | + final String xml = xmlMapper.writeValueAsString(purchase); |
| 405 | + |
| 406 | + // Verify XML contains both purchase-level and adjustment-level vertex_transaction_type |
| 407 | + assert xml.contains("<purchase") : "Should contain purchase root element"; |
| 408 | + assert xml.contains("<vertex_transaction_type>sale</vertex_transaction_type>") : |
| 409 | + "Should contain purchase-level vertex_transaction_type"; |
| 410 | + assert xml.contains("<vertex_transaction_type>lease</vertex_transaction_type>") : |
| 411 | + "Should contain adjustment-level vertex_transaction_type 'lease'"; |
| 412 | + assert xml.contains("<vertex_transaction_type>rental</vertex_transaction_type>") : |
| 413 | + "Should contain adjustment-level vertex_transaction_type 'rental'"; |
| 414 | + |
| 415 | + // Verify round-trip serialization/deserialization |
| 416 | + final Purchase deserializedPurchase = xmlMapper.readValue(xml, Purchase.class); |
| 417 | + assertEquals(deserializedPurchase.getVertexTransactionType(), "sale"); |
| 418 | + assertEquals(deserializedPurchase.getAdjustments().size(), 2); |
| 419 | + assertEquals(deserializedPurchase.getAdjustments().get(0).getVertexTransactionType(), "lease"); |
| 420 | + assertEquals(deserializedPurchase.getAdjustments().get(1).getVertexTransactionType(), "rental"); |
| 421 | + } |
| 422 | + |
299 | 423 | @Test(groups = "fast") |
300 | 424 | public void testHashCodeAndEquality() throws Exception { |
301 | 425 | // create purchase of the same value but difference references |
|
0 commit comments