Skip to content

Commit 74b22ac

Browse files
author
srathod
committed
- Added sampletest for ARBGetSubscription and GetCustomerPaymentProfileList methods.
1 parent f2a1611 commit 74b22ac

2 files changed

Lines changed: 228 additions & 7 deletions

File tree

src/test/java/net/authorize/api/controller/sampletest/ArbSubscriptionSampleTest.java

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package net.authorize.api.controller.sampletest;
22

3+
import org.junit.After;
4+
import org.junit.AfterClass;
5+
import org.junit.Before;
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
39
import junit.framework.Assert;
410
import net.authorize.api.contract.v1.ARBCancelSubscriptionRequest;
511
import net.authorize.api.contract.v1.ARBCancelSubscriptionResponse;
@@ -10,26 +16,24 @@
1016
import net.authorize.api.contract.v1.ARBGetSubscriptionListResponse;
1117
import net.authorize.api.contract.v1.ARBGetSubscriptionListSearchTypeEnum;
1218
import net.authorize.api.contract.v1.ARBGetSubscriptionListSorting;
19+
import net.authorize.api.contract.v1.ARBGetSubscriptionRequest;
20+
import net.authorize.api.contract.v1.ARBGetSubscriptionResponse;
1321
import net.authorize.api.contract.v1.ARBGetSubscriptionStatusRequest;
1422
import net.authorize.api.contract.v1.ARBGetSubscriptionStatusResponse;
23+
import net.authorize.api.contract.v1.ARBSubscriptionMaskedType;
1524
import net.authorize.api.contract.v1.ARBSubscriptionStatusEnum;
1625
import net.authorize.api.contract.v1.ArrayOfSubscription;
1726
import net.authorize.api.contract.v1.Paging;
1827
import net.authorize.api.contract.v1.SubscriptionDetail;
1928
import net.authorize.api.controller.ARBCancelSubscriptionController;
2029
import net.authorize.api.controller.ARBCreateSubscriptionController;
30+
import net.authorize.api.controller.ARBGetSubscriptionController;
2131
import net.authorize.api.controller.ARBGetSubscriptionListController;
2232
import net.authorize.api.controller.ARBGetSubscriptionStatusController;
2333
import net.authorize.api.controller.base.ApiOperationBase;
2434
import net.authorize.api.controller.test.ApiCoreTestBase;
2535
import net.authorize.util.LogHelper;
2636

27-
import org.junit.After;
28-
import org.junit.AfterClass;
29-
import org.junit.Before;
30-
import org.junit.BeforeClass;
31-
import org.junit.Test;
32-
3337
public class ArbSubscriptionSampleTest extends ApiCoreTestBase {
3438

3539
@BeforeClass
@@ -51,6 +55,59 @@ public void setUp() throws Exception {
5155
public void tearDown() throws Exception {
5256
super.tearDown();
5357
}
58+
59+
@Test
60+
public void ARBGetSubscriptionSample() {
61+
62+
//Common code to set for all requests
63+
ApiOperationBase.setEnvironment(environment);
64+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
65+
66+
//create
67+
ARBCreateSubscriptionRequest createRequest = new ARBCreateSubscriptionRequest();
68+
createRequest.setRefId(refId);
69+
createRequest.setSubscription(arbSubscriptionOne);
70+
ARBCreateSubscriptionController createController = new ARBCreateSubscriptionController(createRequest);
71+
//separate execute and getResponse calls
72+
createController.execute();
73+
ARBCreateSubscriptionResponse createResponse = createController.getApiResponse();
74+
75+
Assert.assertNotNull(createResponse.getSubscriptionId());
76+
logger.info(String.format("Created Subscription: %s", createResponse.getSubscriptionId()));
77+
String subscriptionId = createResponse.getSubscriptionId();
78+
79+
try {
80+
//getsubscription
81+
LogHelper.info(logger, "Getting Subscription Information for SubscriptionId: %s", subscriptionId);
82+
83+
ARBGetSubscriptionRequest getSubscriptionRequest = new ARBGetSubscriptionRequest();
84+
getSubscriptionRequest.setRefId(refId);
85+
getSubscriptionRequest.setSubscriptionId(subscriptionId);
86+
87+
ARBGetSubscriptionController subscriptionController = new ARBGetSubscriptionController(getSubscriptionRequest);
88+
//execute and getResponse calls together
89+
ARBGetSubscriptionResponse getSubscriptionResponse = subscriptionController.executeWithApiResponse();
90+
Assert.assertNotNull(getSubscriptionResponse.getSubscription());
91+
92+
ARBSubscriptionMaskedType subscriptionInfo = getSubscriptionResponse.getSubscription();
93+
94+
logger.info(String.format("Subscription Name: %s", subscriptionInfo.getName()));
95+
Assert.assertEquals(arbSubscriptionOne.getName(), subscriptionInfo.getName());
96+
} finally {
97+
// cancel
98+
ARBCancelSubscriptionRequest cancelRequest = new ARBCancelSubscriptionRequest();
99+
cancelRequest.setMerchantAuthentication(merchantAuthenticationType);
100+
cancelRequest.setRefId(refId);
101+
cancelRequest.setSubscriptionId(subscriptionId);
102+
// explicitly setting up the merchant id and environment
103+
ARBCancelSubscriptionResponse cancelResponse = executeTestRequestWithSuccess(
104+
cancelRequest, ARBCancelSubscriptionController.class,
105+
environment);
106+
Assert.assertNotNull(cancelResponse.getMessages());
107+
logger.info(String.format("Subscription Cancelled %s",
108+
subscriptionId));
109+
}
110+
}
54111

55112
@Test
56113
public void subscriptionSamples() {
@@ -85,7 +142,7 @@ public void subscriptionSamples() {
85142
ARBSubscriptionStatusEnum newStatus = getResponse.getStatus();
86143
Assert.assertEquals(ARBSubscriptionStatusEnum.ACTIVE, newStatus);
87144
LogHelper.info(logger, "Getting Subscription List for SubscriptionId: %s", subscriptionId);
88-
145+
89146
//get list
90147
ARBGetSubscriptionListSorting sorting = new ARBGetSubscriptionListSorting();
91148
sorting.setOrderDescending(true);
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package net.authorize.api.controller.sampletest;
2+
3+
import java.math.BigDecimal;
4+
import java.util.List;
5+
6+
import org.junit.After;
7+
import org.junit.AfterClass;
8+
import org.junit.Before;
9+
import org.junit.BeforeClass;
10+
import org.junit.Test;
11+
12+
import junit.framework.Assert;
13+
import net.authorize.api.contract.v1.CreateCustomerPaymentProfileRequest;
14+
import net.authorize.api.contract.v1.CreateCustomerPaymentProfileResponse;
15+
import net.authorize.api.contract.v1.CreateCustomerProfileRequest;
16+
import net.authorize.api.contract.v1.CreateCustomerProfileResponse;
17+
import net.authorize.api.contract.v1.CreditCardType;
18+
import net.authorize.api.contract.v1.CustomerPaymentProfileListItemType;
19+
import net.authorize.api.contract.v1.CustomerPaymentProfileSearchTypeEnum;
20+
import net.authorize.api.contract.v1.CustomerPaymentProfileType;
21+
import net.authorize.api.contract.v1.CustomerProfileType;
22+
import net.authorize.api.contract.v1.CustomerTypeEnum;
23+
import net.authorize.api.contract.v1.DeleteCustomerProfileRequest;
24+
import net.authorize.api.contract.v1.DeleteCustomerProfileResponse;
25+
import net.authorize.api.contract.v1.GetCustomerPaymentProfileListRequest;
26+
import net.authorize.api.contract.v1.GetCustomerPaymentProfileListResponse;
27+
import net.authorize.api.contract.v1.MessageTypeEnum;
28+
import net.authorize.api.contract.v1.PaymentType;
29+
import net.authorize.api.contract.v1.ValidationModeEnum;
30+
import net.authorize.api.controller.CreateCustomerPaymentProfileController;
31+
import net.authorize.api.controller.CreateCustomerProfileController;
32+
import net.authorize.api.controller.DeleteCustomerProfileController;
33+
import net.authorize.api.controller.GetCustomerPaymentProfileListController;
34+
import net.authorize.api.controller.base.ApiOperationBase;
35+
import net.authorize.api.controller.test.ApiCoreTestBase;
36+
import net.authorize.util.LogHelper;
37+
38+
public class CustomerProfileSampleTest extends ApiCoreTestBase {
39+
40+
@BeforeClass
41+
public static void setUpBeforeClass() throws Exception {
42+
ApiCoreTestBase.setUpBeforeClass();
43+
}
44+
45+
@AfterClass
46+
public static void tearDownAfterClass() throws Exception {
47+
ApiCoreTestBase.tearDownAfterClass();
48+
}
49+
50+
@Before
51+
public void setUp() throws Exception {
52+
super.setUp();
53+
}
54+
55+
@After
56+
public void tearDown() throws Exception {
57+
super.tearDown();
58+
}
59+
60+
@Test
61+
public void getCustomerPaymentProfileListSample()
62+
{
63+
//Common code to set for all requests
64+
ApiOperationBase.setEnvironment(environment);
65+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
66+
67+
CreateCustomerProfileResponse createdCustomerProfile = createCustomerProfile();
68+
69+
try {
70+
GetCustomerPaymentProfileListRequest request = new GetCustomerPaymentProfileListRequest();
71+
request.setRefId(refId);
72+
request.setSearchType(CustomerPaymentProfileSearchTypeEnum.CARDS_EXPIRING_IN_MONTH);
73+
request.setMonth("2040-12");
74+
75+
int retryCount = 3;
76+
boolean found = false;
77+
do {
78+
// Pause for about 15 seconds, so that the created subscription
79+
// will be in the next service call.
80+
try {
81+
Thread.sleep(15000L);
82+
} catch (InterruptedException e) {
83+
e.printStackTrace();
84+
}
85+
86+
GetCustomerPaymentProfileListController customerPaymentProfileController = new GetCustomerPaymentProfileListController(request);
87+
customerPaymentProfileController.execute();
88+
GetCustomerPaymentProfileListResponse response = customerPaymentProfileController.getApiResponse();
89+
90+
Assert.assertNotNull(response);
91+
Assert.assertEquals(MessageTypeEnum.OK, response.getMessages().getResultCode());
92+
93+
List<CustomerPaymentProfileListItemType> paymentProfiles = response.getPaymentProfiles().getPaymentProfile();
94+
95+
Assert.assertTrue( 0 < response.getTotalNumInResultSet());
96+
Assert.assertNotNull(paymentProfiles);
97+
LogHelper.info( logger, "Customer Payment Profile List Count: %d", response.getTotalNumInResultSet());
98+
99+
for( CustomerPaymentProfileListItemType customerPaymentProfile : paymentProfiles) {
100+
String customerPaymentProfileId = Integer.toString(customerPaymentProfile.getCustomerProfileId());
101+
LogHelper.info( logger, "Customer Profile Id: %s", customerPaymentProfileId);
102+
if (customerPaymentProfileId.equals(createdCustomerProfile.getCustomerProfileId())) { found = true;}
103+
}
104+
} while (!found && --retryCount > 0);
105+
106+
Assert.assertTrue("The customer payment profile " + createdCustomerProfile.getCustomerProfileId()
107+
+ " not found in the list.", found);
108+
} finally {
109+
// delete
110+
DeleteCustomerProfileRequest deleteCustomerProfileRequest = new DeleteCustomerProfileRequest();
111+
deleteCustomerProfileRequest.setRefId(refId);
112+
deleteCustomerProfileRequest.setCustomerProfileId(createdCustomerProfile.getCustomerProfileId());
113+
114+
DeleteCustomerProfileController deleteCustomerProfileController = new DeleteCustomerProfileController(deleteCustomerProfileRequest);
115+
deleteCustomerProfileController.execute();
116+
DeleteCustomerProfileResponse deleteCustomerProfileResponse = deleteCustomerProfileController.getApiResponse();
117+
118+
Assert.assertNotNull(deleteCustomerProfileResponse);
119+
Assert.assertEquals(MessageTypeEnum.OK, deleteCustomerProfileResponse.getMessages().getResultCode());
120+
logger.info(String.format("Customer Profile Deleted %s",
121+
createdCustomerProfile.getCustomerProfileId()));
122+
}
123+
}
124+
125+
private CreateCustomerProfileResponse createCustomerProfile()
126+
{
127+
//Common code to set for all requests
128+
ApiOperationBase.setEnvironment(environment);
129+
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
130+
131+
CreateCustomerProfileRequest request = new CreateCustomerProfileRequest();
132+
request.setRefId(refId);
133+
134+
CreditCardType creditCard = new CreditCardType();
135+
creditCard.setCardNumber("4111111111111111");
136+
creditCard.setExpirationDate("2040-12");
137+
138+
PaymentType payment = new PaymentType();
139+
payment.setCreditCard(creditCard);
140+
141+
CustomerPaymentProfileType customerPaymentProfile = new CustomerPaymentProfileType();
142+
customerPaymentProfile.setCustomerType(CustomerTypeEnum.INDIVIDUAL);
143+
customerPaymentProfile.setPayment(payment);
144+
145+
CustomerProfileType customerProfile = new CustomerProfileType() ;
146+
customerProfile.setMerchantCustomerId(getRandomString("Cust"));
147+
customerProfile.setDescription(getRandomString("CustDescription"));
148+
customerProfile.setEmail(counterStr+".customerProfileTest@test.anet.net");
149+
150+
customerProfile.getPaymentProfiles().add(customerPaymentProfile);
151+
request.setProfile(customerProfile);
152+
request.setValidationMode(ValidationModeEnum.TEST_MODE);
153+
154+
CreateCustomerProfileController createProfileController = new CreateCustomerProfileController(request);
155+
createProfileController.execute();
156+
CreateCustomerProfileResponse response = createProfileController.getApiResponse();
157+
158+
Assert.assertNotNull(response);
159+
Assert.assertEquals(MessageTypeEnum.OK, response.getMessages().getResultCode());
160+
Assert.assertFalse(response.getCustomerProfileId().isEmpty());
161+
162+
return response;
163+
}
164+
}

0 commit comments

Comments
 (0)