-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProfilesAPITest.java
More file actions
341 lines (288 loc) · 11.3 KB
/
ProfilesAPITest.java
File metadata and controls
341 lines (288 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package com.beanstream.api.test;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import com.beanstream.connection.HttpsConnector;
import com.beanstream.domain.Address;
import com.beanstream.domain.Card;
import com.beanstream.domain.PaymentProfile;
import com.beanstream.domain.Token;
import com.beanstream.exceptions.BeanstreamApiException;
import com.beanstream.responses.LegatoTokenResponse;
import com.beanstream.responses.ProfileResponse;
public class ProfilesAPITest extends BasePaymentsTest {
@Test
public void invalidCardCreateProfile() {
Address billing = getTestBillingAddress();
Card card = getTestCard();
ProfileResponse createdProfile = null;
try {
Card nillCard = null;
createdProfile = gateway.profiles().createProfile(nillCard, billing);
Assert.fail("Fail test because the card was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
card.setName(null);
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the card name was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
card.setName("Jhon Garcia");
card.setNumber("");
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the card number was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
card.setNumber("5100000010001004");
card.setExpiryYear("");
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the card expiry year was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
card.setExpiryYear("2018");
card.setExpiryMonth(null);
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the card expiry month was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
}
@Test
public void invalidBillingAddrCreateProfile() {
Address billing = getTestBillingAddress();
Card card = getTestCard();
ProfileResponse createdProfile = null;
try {
createdProfile = gateway.profiles().createProfile(card, null);
Assert.fail("Fail test because the billing address was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
billing.setAddressLine1(null);
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the billing address line 1 was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
billing.setAddressLine1("12635 NW 98TH ST");
billing.setCity(null);
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the billing address city was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
billing.setCity("Miami");
billing.setCountry(null);
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the billing address country was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
billing.setCountry("US");
billing.setEmailAddress(null);
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the billing address email was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
billing.setEmailAddress("pagarciaortega@gmail.com");
billing.setPhoneNumber(null);
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the billing address phone number was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
try {
billing.setPhoneNumber("786-241-8879");
billing.setProvince(null);
createdProfile = gateway.profiles().createProfile(card, billing);
Assert.fail("Fail test because the billing address province/state was empty");
} catch (BeanstreamApiException ex) {
Assert.assertTrue("", ex.getHttpStatusCode() == 400);
}
}
@Test
public void testProfileCreationWhenDisabledAddressValidation() throws BeanstreamApiException {
System.setProperty("bamboraSDK.profiles.validateBillingAddress", "false");
Address nullBillingAddress = null;
Card card = getTestCard();
try {
ProfileResponse createdProfile = gateway.profiles().createProfile(card, nullBillingAddress);
Assert.assertNotNull(createdProfile.getId());
Assert.assertNotNull(createdProfile.getCode());
}finally {
System.clearProperty("bamboraSDK.profiles.validateBillingAddress");
}
}
@Test
public void testProfileCrudUsingCard() throws BeanstreamApiException {
String profileId = null;
try {
Address billing = getTestCardValidAddress();
Card card = getTestCard();
// test create profile
ProfileResponse createdProfile = gateway.profiles()
.createProfile(card, billing);
profileId = createdProfile.getId();
Assert.assertNotNull(
"Test failed because it should create the profile and return a valid id",
profileId);
// test get profile by id
PaymentProfile paymentProfile = gateway.profiles()
.getProfileById(profileId);
Assert.assertEquals(
"billing address assinged does not matches with the one sent at creation time",
paymentProfile.getBilling(), billing);
Assert.assertNotNull("Credit card was not in the response",
paymentProfile.getCard());
Assert.assertTrue("The default lenguage should be english","en".equals(paymentProfile.getLanguage()));
// update the profile to francais
paymentProfile.setLanguage("fr");
paymentProfile.setComments("test updating profile sending billing info only");
// update profile
gateway.profiles().updateProfile(paymentProfile);
// refresh the updated profile
paymentProfile = gateway.profiles().getProfileById(profileId);
Assert.assertEquals("Language was updated to Francais",
paymentProfile.getLanguage(), "fr");
// delete the payment profile
gateway.profiles().deleteProfileById(profileId);
try {
gateway.profiles().getProfileById(profileId);
Assert.fail("This profile was deleted, therefore should throw an exception");
} catch (BeanstreamApiException e) {
profileId = null;
}
} catch (BeanstreamApiException ex) {
Assert.fail("Test can not continue, "+ex.getMessage());
} catch (Exception ex) {
Assert.fail("unexpected exception occur, test can not continue");
} finally {
if (profileId != null) {
ProfileResponse response = gateway.profiles()
.deleteProfileById(profileId);
}
}
}
@Test
public void testProfileCrudUsingToken() throws BeanstreamApiException {
String profileId = null;
try {
HttpsConnector connector = new HttpsConnector(300200578,
"4BaD82D9197b4cc4b70a221911eE9f70");
Address billing = getTestCardValidAddress();
LegatoTokenResponse tokenResponse = tokenizeCard(connector, "5100000010001004", "123",12, 19);
// test create profile
Token token = new Token("John Doe",tokenResponse.getToken());
ProfileResponse createdProfile = gateway.profiles()
.createProfile(token, billing);
profileId = createdProfile.getId();
Assert.assertNotNull(
"Test failed because it should create the profile and return a valid id",
profileId);
// test get profile by id
PaymentProfile paymentProfile = gateway.profiles()
.getProfileById(profileId);
Assert.assertEquals(
"billing address assinged does not matches with the one sent at creation time",
paymentProfile.getBilling(), billing);
Assert.assertNotNull("Credit card was not in the response",
paymentProfile.getCard());
Assert.assertTrue("The default lenguage should be english","en".equals(paymentProfile.getLanguage()));
// update the profile to francais
paymentProfile.setLanguage("fr");
paymentProfile.setComments("test updating profile sending billing info only");
// update profile
gateway.profiles().updateProfile(paymentProfile);
// refresh the updated profile
paymentProfile = gateway.profiles().getProfileById(profileId);
Assert.assertEquals("Language was updated to Francais",
paymentProfile.getLanguage(), "fr");
// delete the payment profile
gateway.profiles().deleteProfileById(profileId);
try {
gateway.profiles().getProfileById(profileId);
Assert.fail("This profile was deleted, therefore should throw an exception");
} catch (BeanstreamApiException e) {
profileId = null;
}
} catch (BeanstreamApiException ex) {
Assert.fail("Test can not continue, "+ex.getMessage());
} catch (Exception ex) {
Assert.fail("unexpected exception occur, test can not continue");
} finally {
if (profileId != null) {
ProfileResponse response = gateway.profiles()
.deleteProfileById(profileId);
}
}
}
@Test
public void testProfileCardsCrud() throws BeanstreamApiException {
String profileId = null;
try {
Address billing = getTestBillingAddress();
Card card = getTestCard();
// test create profile
ProfileResponse createdProfile = gateway.profiles()
.createProfile(card, billing);
profileId = createdProfile.getId();
Assert.assertNotNull(
"Test failed because it should create the profile and return a valid id",
profileId);
// test getCards
List<Card> profileCards = gateway.profiles().getCards(profileId);
Assert.assertFalse("this profile should have one credit card",
profileCards.isEmpty());
Card card1 = profileCards.get(0);
// test getCard
Card freshCard = gateway.profiles().getCard(profileId,
card1.getId());
Assert.assertNotNull(
"Test failed because it should return a valid card",
freshCard);
// add a new card
Card newCard = getTestCard();
newCard.setCvd("123");
newCard.setName("John Doe");
newCard.setNumber("4030000010001234");
newCard.setExpiryMonth("01");
newCard.setExpiryYear("19");
ProfileResponse newCardResp = gateway.profiles().addCard(profileId, newCard);
// update the card expires date
freshCard.setExpiryMonth("01");
freshCard.setExpiryYear("19");
freshCard.setName("Bob Two");
ProfileResponse profileResponse = gateway.profiles().updateCard(profileId, freshCard);
//2659 Douglas Street V8T 4M3
// Address newCardAddr = getAddress("Pedro Garcia", "VICTORIA", "BC", "CA", "2659 Douglas Street", "V8T4M3", "TEST@BEANSTREAM.COM", "12501234567");
freshCard = gateway.profiles().getCard(profileId,
freshCard.getId());
Assert.assertEquals("the Expiry Month was updated but the change is not reflected", "01",freshCard.getExpiryMonth());
Assert.assertEquals("the Expiry Year was updated but the change is not reflected", "19",freshCard.getExpiryYear());
} catch (BeanstreamApiException ex) {
Assert.fail(ex.getMessage());
} catch (Exception ex) {
Assert.fail("unexpected exception occur, test can not continue : "
+ ex.getMessage());
} finally {
if (profileId != null) {
ProfileResponse response = gateway.profiles()
.deleteProfileById(profileId);
}
}
}
}