Skip to content

Commit b19a43d

Browse files
committed
Add tests
1 parent 9f457fa commit b19a43d

File tree

2 files changed

+230
-133
lines changed

2 files changed

+230
-133
lines changed

src/test/java/com/adyen/CheckoutTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,51 @@ public void TestSessionsCheckDefaultValues() throws Exception {
665665
final JsonNode actual = mapper.readTree(captor.getValue());
666666
assertEquals(expected, actual);
667667
}
668+
669+
@Test
670+
public void TestBccm() throws Exception {
671+
Client client = createMockClientFromFile("mocks/checkout/paymentResponseBcmc.json");
672+
Amount amount = new Amount().currency("EUR").value(1000L);
673+
PaymentRequest paymentRequest = new PaymentRequest();
674+
paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT");
675+
paymentRequest.setReference("YOUR_ORDER_NUMBER");
676+
paymentRequest.setAmount(new Amount()
677+
.currency("EUR")
678+
.value(1000L));
679+
paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(
680+
new CardDetails()
681+
.type(CardDetails.TypeEnum.BCMC)
682+
.holderName("Ms Smith")
683+
.encryptedCardNumber("...")
684+
.encryptedExpiryMonth("...")
685+
.encryptedExpiryYear("...")
686+
.brand("bcmc")
687+
.checkoutAttemptId("...")
688+
));
689+
PaymentsApi checkout = new PaymentsApi(client);
690+
PaymentResponse paymentResponse = checkout.payments(paymentRequest);
691+
assertEquals(PaymentResponse.ResultCodeEnum.REDIRECTSHOPPER, paymentResponse.getResultCode());
692+
assertNotNull(paymentResponse.getAction());
693+
}
694+
695+
@Test
696+
public void TestBccmMobile() throws Exception {
697+
Client client = createMockClientFromFile("mocks/checkout/paymentResponseBcmcMobile.json");
698+
Amount amount = new Amount().currency("EUR").value(1000L);
699+
PaymentRequest paymentRequest = new PaymentRequest();
700+
paymentRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT");
701+
paymentRequest.setReference("YOUR_ORDER_NUMBER");
702+
paymentRequest.setAmount(new Amount()
703+
.currency("EUR")
704+
.value(1000L));
705+
paymentRequest.setPaymentMethod(new CheckoutPaymentMethod(
706+
new StoredPaymentMethodDetails()
707+
.type(StoredPaymentMethodDetails.TypeEnum.BCMC_MOBILE)
708+
));
709+
PaymentsApi checkout = new PaymentsApi(client);
710+
PaymentResponse paymentResponse = checkout.payments(paymentRequest);
711+
assertEquals(PaymentResponse.ResultCodeEnum.PENDING, paymentResponse.getResultCode());
712+
assertNotNull(paymentResponse.getAction());
713+
}
714+
668715
}

src/test/java/com/adyen/serializer/ModelTest.java

Lines changed: 183 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -5,146 +5,196 @@
55
import static org.junit.Assert.assertNull;
66
import static org.junit.Assert.assertTrue;
77

8+
import com.adyen.model.checkout.CardDetails;
9+
import com.adyen.model.checkout.CheckoutPaymentMethod;
810
import com.adyen.model.checkout.CreateCheckoutSessionResponse;
11+
import com.adyen.model.checkout.StoredPaymentMethodDetails;
912
import com.adyen.model.legalentitymanagement.*;
1013
import com.fasterxml.jackson.core.JsonProcessingException;
14+
1115
import java.time.Month;
1216
import java.time.ZoneId;
17+
1318
import org.junit.Test;
1419

15-
/** Test model serialization (toJson) and deserialization (fromJson) */
20+
/**
21+
* Test model serialization (toJson) and deserialization (fromJson)
22+
*/
1623
public class ModelTest {
1724

18-
@Test
19-
public void testFromJsonLegalEntity() throws JsonProcessingException {
20-
String json =
21-
"{\n"
22-
+ " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n"
23-
+ " \"reference\": \"YOUR_REFERENCE_12345\",\n"
24-
+ " \"type\": \"individual\",\n"
25-
+ " \"individual\": {\n"
26-
+ " \"name\": {\n"
27-
+ " \"firstName\": \"Jane\",\n"
28-
+ " \"lastName\": \"Doe\"\n"
29-
+ " },\n"
30-
+ " \"residentialAddress\": {\n"
31-
+ " \"country\": \"NL\",\n"
32-
+ " \"city\": \"Amsterdam\"\n"
33-
+ " }\n"
34-
+ " },\n"
35-
+ " \"capabilities\": {\n"
36-
+ " \"issueCard\": {\n"
37-
+ " \"allowed\": true,\n"
38-
+ " \"requested\": true\n"
39-
+ " }\n"
40-
+ " }\n"
41-
+ "}";
42-
43-
LegalEntity legalEntity = LegalEntity.fromJson(json);
44-
45-
assertNotNull(legalEntity);
46-
assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId());
47-
assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference());
48-
49-
assertEquals(LegalEntity.TypeEnum.INDIVIDUAL, legalEntity.getType());
50-
assertNotNull(legalEntity.getIndividual());
51-
52-
assertNotNull(legalEntity.getCapabilities());
53-
assertTrue(legalEntity.getCapabilities().containsKey("issueCard"));
54-
assertNotNull(legalEntity.getCapabilities().get("issueCard"));
55-
}
56-
57-
@Test
58-
public void testFromJsonLegalEntityWithInvalidEnum() throws JsonProcessingException {
59-
String json =
60-
"{\n"
61-
+ " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n"
62-
+ " \"reference\": \"YOUR_REFERENCE_12345\",\n"
63-
+ " \"type\": \"UNKNOWN\",\n"
64-
+ " \"individual\": {\n"
65-
+ " \"name\": {\n"
66-
+ " \"firstName\": \"Jane\",\n"
67-
+ " \"lastName\": \"Doe\"\n"
68-
+ " },\n"
69-
+ " \"residentialAddress\": {\n"
70-
+ " \"country\": \"NL\",\n"
71-
+ " \"city\": \"Amsterdam\"\n"
72-
+ " }\n"
73-
+ " },\n"
74-
+ " \"capabilities\": {\n"
75-
+ " \"issueCard\": {\n"
76-
+ " \"allowed\": true,\n"
77-
+ " \"requested\": true\n"
78-
+ " }\n"
79-
+ " }\n"
80-
+ "}";
81-
82-
LegalEntity legalEntity = LegalEntity.fromJson(json);
83-
84-
assertNotNull(legalEntity);
85-
assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId());
86-
assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference());
87-
// type is null since enum value is invalid
88-
assertNull(legalEntity.getType());
89-
}
90-
91-
@Test
92-
public void testToJsonLegalEntity() throws JsonProcessingException {
93-
LegalEntity legalEntity =
94-
new LegalEntity()
95-
.reference("YOUR_REFERENCE_12345")
96-
.type(LegalEntity.TypeEnum.INDIVIDUAL)
97-
.individual(
98-
new Individual()
99-
.name(new Name().firstName("Jane").lastName("Doe"))
100-
.residentialAddress(new Address().country("NL").city("Amsterdam")))
101-
.putCapabilitiesItem(
102-
"issueCard",
103-
new LegalEntityCapability()
104-
.allowedSettings(
105-
new CapabilitySettings()
106-
.addFundingSourceItem(CapabilitySettings.FundingSourceEnum.CREDIT)));
107-
108-
String deserialized = legalEntity.toJson();
109-
110-
String expected =
111-
"{\"capabilities\":{\"issueCard\":{\"allowedSettings\":{\"fundingSource\":[\"credit\"]}}},\"individual\":{\"name\":{\"firstName\":\"Jane\",\"lastName\":\"Doe\"},\"residentialAddress\":{\"city\":\"Amsterdam\",\"country\":\"NL\"}},\"reference\":\"YOUR_REFERENCE_12345\",\"type\":\"individual\"}";
112-
113-
assertEquals(expected, deserialized);
114-
}
115-
116-
@Test
117-
public void testFromJsonCreateCheckoutSessionResponse() throws JsonProcessingException {
118-
String json =
119-
"{\n"
120-
+ " \"amount\": {\n"
121-
+ " \"currency\": \"EUR\",\n"
122-
+ " \"value\": 1000\n"
123-
+ " },\n"
124-
+ " \"countryCode\": \"NL\",\n"
125-
+ " \"expiresAt\": \"2022-01-11T13:53:18+01:00\",\n"
126-
+ " \"id\": \"CS451F2AB1ED897A94\",\n"
127-
+ " \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\",\n"
128-
+ " \"reference\": \"YOUR_PAYMENT_REFERENCE\",\n"
129-
+ " \"url\": \"https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF\",\n"
130-
+ " \"sessionData\": \"Ab02b4c0!BQABAgBfYI29...\"\n"
131-
+ "}";
132-
133-
CreateCheckoutSessionResponse response = CreateCheckoutSessionResponse.fromJson(json);
134-
135-
assertNotNull(response);
136-
assertEquals("CS451F2AB1ED897A94", response.getId());
137-
assertEquals("YOUR_PAYMENT_REFERENCE", response.getReference());
138-
assertEquals(
139-
"https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF", response.getUrl());
140-
141-
assertNotNull(response.getAmount());
142-
assertEquals("EUR", response.getAmount().getCurrency());
143-
assertEquals(1000L, response.getAmount().getValue().longValue());
144-
145-
assertEquals("2022-01-11T13:53:18+01:00", response.getExpiresAt().toString());
146-
assertEquals(2022, response.getExpiresAt().getYear());
147-
assertEquals(Month.JANUARY, response.getExpiresAt().getMonth());
148-
assertEquals(ZoneId.of("+01:00"), response.getExpiresAt().toZonedDateTime().getZone());
149-
}
25+
@Test
26+
public void testFromJsonLegalEntity() throws JsonProcessingException {
27+
String json =
28+
"{\n"
29+
+ " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n"
30+
+ " \"reference\": \"YOUR_REFERENCE_12345\",\n"
31+
+ " \"type\": \"individual\",\n"
32+
+ " \"individual\": {\n"
33+
+ " \"name\": {\n"
34+
+ " \"firstName\": \"Jane\",\n"
35+
+ " \"lastName\": \"Doe\"\n"
36+
+ " },\n"
37+
+ " \"residentialAddress\": {\n"
38+
+ " \"country\": \"NL\",\n"
39+
+ " \"city\": \"Amsterdam\"\n"
40+
+ " }\n"
41+
+ " },\n"
42+
+ " \"capabilities\": {\n"
43+
+ " \"issueCard\": {\n"
44+
+ " \"allowed\": true,\n"
45+
+ " \"requested\": true\n"
46+
+ " }\n"
47+
+ " }\n"
48+
+ "}";
49+
50+
LegalEntity legalEntity = LegalEntity.fromJson(json);
51+
52+
assertNotNull(legalEntity);
53+
assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId());
54+
assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference());
55+
56+
assertEquals(LegalEntity.TypeEnum.INDIVIDUAL, legalEntity.getType());
57+
assertNotNull(legalEntity.getIndividual());
58+
59+
assertNotNull(legalEntity.getCapabilities());
60+
assertTrue(legalEntity.getCapabilities().containsKey("issueCard"));
61+
assertNotNull(legalEntity.getCapabilities().get("issueCard"));
62+
}
63+
64+
@Test
65+
public void testFromJsonLegalEntityWithInvalidEnum() throws JsonProcessingException {
66+
String json =
67+
"{\n"
68+
+ " \"id\": \"LE3227C223222B5BPCMFXD2XG\",\n"
69+
+ " \"reference\": \"YOUR_REFERENCE_12345\",\n"
70+
+ " \"type\": \"UNKNOWN\",\n"
71+
+ " \"individual\": {\n"
72+
+ " \"name\": {\n"
73+
+ " \"firstName\": \"Jane\",\n"
74+
+ " \"lastName\": \"Doe\"\n"
75+
+ " },\n"
76+
+ " \"residentialAddress\": {\n"
77+
+ " \"country\": \"NL\",\n"
78+
+ " \"city\": \"Amsterdam\"\n"
79+
+ " }\n"
80+
+ " },\n"
81+
+ " \"capabilities\": {\n"
82+
+ " \"issueCard\": {\n"
83+
+ " \"allowed\": true,\n"
84+
+ " \"requested\": true\n"
85+
+ " }\n"
86+
+ " }\n"
87+
+ "}";
88+
89+
LegalEntity legalEntity = LegalEntity.fromJson(json);
90+
91+
assertNotNull(legalEntity);
92+
assertEquals("LE3227C223222B5BPCMFXD2XG", legalEntity.getId());
93+
assertEquals("YOUR_REFERENCE_12345", legalEntity.getReference());
94+
// type is null since enum value is invalid
95+
assertNull(legalEntity.getType());
96+
}
97+
98+
@Test
99+
public void testToJsonLegalEntity() throws JsonProcessingException {
100+
LegalEntity legalEntity =
101+
new LegalEntity()
102+
.reference("YOUR_REFERENCE_12345")
103+
.type(LegalEntity.TypeEnum.INDIVIDUAL)
104+
.individual(
105+
new Individual()
106+
.name(new Name().firstName("Jane").lastName("Doe"))
107+
.residentialAddress(new Address().country("NL").city("Amsterdam")))
108+
.putCapabilitiesItem(
109+
"issueCard",
110+
new LegalEntityCapability()
111+
.allowedSettings(
112+
new CapabilitySettings()
113+
.addFundingSourceItem(CapabilitySettings.FundingSourceEnum.CREDIT)));
114+
115+
String deserialized = legalEntity.toJson();
116+
117+
String expected =
118+
"{\"capabilities\":{\"issueCard\":{\"allowedSettings\":{\"fundingSource\":[\"credit\"]}}},\"individual\":{\"name\":{\"firstName\":\"Jane\",\"lastName\":\"Doe\"},\"residentialAddress\":{\"city\":\"Amsterdam\",\"country\":\"NL\"}},\"reference\":\"YOUR_REFERENCE_12345\",\"type\":\"individual\"}";
119+
120+
assertEquals(expected, deserialized);
121+
}
122+
123+
@Test
124+
public void testFromJsonCreateCheckoutSessionResponse() throws JsonProcessingException {
125+
String json =
126+
"{\n"
127+
+ " \"amount\": {\n"
128+
+ " \"currency\": \"EUR\",\n"
129+
+ " \"value\": 1000\n"
130+
+ " },\n"
131+
+ " \"countryCode\": \"NL\",\n"
132+
+ " \"expiresAt\": \"2022-01-11T13:53:18+01:00\",\n"
133+
+ " \"id\": \"CS451F2AB1ED897A94\",\n"
134+
+ " \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\",\n"
135+
+ " \"reference\": \"YOUR_PAYMENT_REFERENCE\",\n"
136+
+ " \"url\": \"https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF\",\n"
137+
+ " \"sessionData\": \"Ab02b4c0!BQABAgBfYI29...\"\n"
138+
+ "}";
139+
140+
CreateCheckoutSessionResponse response = CreateCheckoutSessionResponse.fromJson(json);
141+
142+
assertNotNull(response);
143+
assertEquals("CS451F2AB1ED897A94", response.getId());
144+
assertEquals("YOUR_PAYMENT_REFERENCE", response.getReference());
145+
assertEquals(
146+
"https://checkout-test.adyen.com/checkout/sessions/CS_1234567890ABCDEF", response.getUrl());
147+
148+
assertNotNull(response.getAmount());
149+
assertEquals("EUR", response.getAmount().getCurrency());
150+
assertEquals(1000L, response.getAmount().getValue().longValue());
151+
152+
assertEquals("2022-01-11T13:53:18+01:00", response.getExpiresAt().toString());
153+
assertEquals(2022, response.getExpiresAt().getYear());
154+
assertEquals(Month.JANUARY, response.getExpiresAt().getMonth());
155+
assertEquals(ZoneId.of("+01:00"), response.getExpiresAt().toZonedDateTime().getZone());
156+
}
157+
158+
@Test
159+
public void testFromJsonCheckoutPaymentMethodBcmc() throws Exception {
160+
String json =
161+
"{\n"
162+
+ " \"type\": \"bcmc\",\n"
163+
+ " \"holderName\": \"Ms Smith\",\n"
164+
+ " \"encryptedCardNumber\": \"...\",\n"
165+
+ " \"encryptedExpiryMonth\": \"...\",\n"
166+
+ " \"encryptedExpiryYear\": \"...\",\n"
167+
+ " \"brand\": \"bcmc\",\n"
168+
+ " \"checkoutAttemptId\": \"...\"\n"
169+
+ "}";
170+
171+
CheckoutPaymentMethod paymentMethod = CheckoutPaymentMethod.fromJson(json);
172+
173+
assertNotNull(paymentMethod);
174+
175+
CardDetails cardDetails = paymentMethod.getCardDetails();
176+
assertNotNull(cardDetails);
177+
178+
assertEquals(CardDetails.TypeEnum.BCMC, cardDetails.getType());
179+
assertEquals("bcmc", cardDetails.getBrand());
180+
assertEquals("Ms Smith", cardDetails.getHolderName());
181+
}
182+
183+
@Test
184+
public void testFromJsonCheckoutPaymentMethodBcmcMobile() throws Exception {
185+
String json =
186+
"{\n" +
187+
" \"type\":\"bcmc_mobile\",\n" +
188+
" \"storedPaymentMethodId\":\"7219687191761347\"\n" +
189+
"}";
190+
191+
CheckoutPaymentMethod paymentMethod = CheckoutPaymentMethod.fromJson(json);
192+
assertNotNull(paymentMethod);
193+
194+
StoredPaymentMethodDetails storedPaymentMethodDetails = paymentMethod.getStoredPaymentMethodDetails();
195+
assertNotNull(storedPaymentMethodDetails);
196+
197+
assertEquals(StoredPaymentMethodDetails.TypeEnum.BCMC_MOBILE, storedPaymentMethodDetails.getType());
198+
assertEquals("7219687191761347", storedPaymentMethodDetails.getStoredPaymentMethodId());
199+
}
150200
}

0 commit comments

Comments
 (0)