@@ -72,57 +72,78 @@ public void subscriptionSamples() {
72
72
logger .info (String .format ("Created Subscription: %s" , createResponse .getSubscriptionId ()));
73
73
String subscriptionId = createResponse .getSubscriptionId ();
74
74
75
- //get
76
- ARBGetSubscriptionStatusRequest getRequest = new ARBGetSubscriptionStatusRequest ();
77
- getRequest .setRefId (refId );
78
- getRequest .setSubscriptionId (subscriptionId );
79
- ARBGetSubscriptionStatusController statusController = new ARBGetSubscriptionStatusController (getRequest );
80
- //execute and getResponse calls together
81
- ARBGetSubscriptionStatusResponse getResponse = statusController .executeWithApiResponse ();
82
- Assert .assertNotNull (getResponse .getStatus ());
83
- logger .info (String .format ("Subscription Status: %s" , getResponse .getStatus ()));
84
- ARBSubscriptionStatusEnum newStatus = getResponse .getStatus ();
85
- Assert .assertEquals (ARBSubscriptionStatusEnum .ACTIVE , newStatus );
86
- LogHelper .info (logger , "Getting Subscription List for SubscriptionId: %s" , subscriptionId );
75
+ try {
76
+ //get
77
+ ARBGetSubscriptionStatusRequest getRequest = new ARBGetSubscriptionStatusRequest ();
78
+ getRequest .setRefId (refId );
79
+ getRequest .setSubscriptionId (subscriptionId );
80
+ ARBGetSubscriptionStatusController statusController = new ARBGetSubscriptionStatusController (getRequest );
81
+ //execute and getResponse calls together
82
+ ARBGetSubscriptionStatusResponse getResponse = statusController .executeWithApiResponse ();
83
+ Assert .assertNotNull (getResponse .getStatus ());
84
+ logger .info (String .format ("Subscription Status: %s" , getResponse .getStatus ()));
85
+ ARBSubscriptionStatusEnum newStatus = getResponse .getStatus ();
86
+ Assert .assertEquals (ARBSubscriptionStatusEnum .ACTIVE , newStatus );
87
+ LogHelper .info (logger , "Getting Subscription List for SubscriptionId: %s" , subscriptionId );
87
88
88
- //get list
89
- ARBGetSubscriptionListSorting sorting = new ARBGetSubscriptionListSorting ();
90
- sorting .setOrderDescending (true );
91
- sorting .setOrderBy (ARBGetSubscriptionListOrderFieldEnum .CREATE_TIME_STAMP_UTC );
92
- Paging paging = new Paging ();
93
- paging .setLimit (100 );
94
- paging .setOffset (1 );
95
- ARBGetSubscriptionListRequest listRequest = new ARBGetSubscriptionListRequest ();
96
- listRequest .setRefId (refId );
97
- listRequest .setSearchType (ARBGetSubscriptionListSearchTypeEnum .SUBSCRIPTION_ACTIVE );
98
- listRequest .setSorting (sorting );
99
- listRequest .setPaging (paging );
100
- ARBGetSubscriptionListController listController = new ARBGetSubscriptionListController (listRequest );
101
- ARBGetSubscriptionListResponse listResponse = listController .executeWithApiResponse ();
102
- LogHelper .info ( logger , "Subscription Count: %d" , listResponse .getTotalNumInResultSet ());
103
- Assert .assertTrue ( 0 < listResponse .getTotalNumInResultSet ());
89
+ //get list
90
+ ARBGetSubscriptionListSorting sorting = new ARBGetSubscriptionListSorting ();
91
+ sorting .setOrderDescending (true );
92
+ sorting .setOrderBy (ARBGetSubscriptionListOrderFieldEnum .CREATE_TIME_STAMP_UTC );
93
+ Paging paging = new Paging ();
94
+ paging .setLimit (100 );
95
+ paging .setOffset (1 );
96
+ ARBGetSubscriptionListRequest listRequest = new ARBGetSubscriptionListRequest ();
97
+ listRequest .setRefId (refId );
98
+ listRequest .setSearchType (ARBGetSubscriptionListSearchTypeEnum .SUBSCRIPTION_ACTIVE );
99
+ listRequest .setSorting (sorting );
100
+ listRequest .setPaging (paging );
101
+
102
+ int retryCount = 3 ;
103
+ boolean found = false ;
104
+ do {
105
+ // Pause for about 15 seconds, so that the created subscription
106
+ // will be in the next service call.
107
+ try {
108
+ Thread .sleep (15000L );
109
+ } catch (InterruptedException e ) {
110
+ e .printStackTrace ();
111
+ }
112
+
113
+ ARBGetSubscriptionListController listController = new ARBGetSubscriptionListController (listRequest );
114
+ ARBGetSubscriptionListResponse listResponse = listController .executeWithApiResponse ();
115
+ LogHelper .info ( logger , "Subscription Count: %d" , listResponse .getTotalNumInResultSet ());
116
+ Assert .assertTrue ( 0 < listResponse .getTotalNumInResultSet ());
104
117
105
- //cancel
106
- ARBCancelSubscriptionRequest cancelRequest = new ARBCancelSubscriptionRequest ();
107
- cancelRequest .setMerchantAuthentication (merchantAuthenticationType );
108
- cancelRequest .setRefId (refId );
109
- cancelRequest .setSubscriptionId (subscriptionId );
110
- //explicitly setting up the merchant id and environment
111
- ARBCancelSubscriptionResponse cancelResponse = executeTestRequestWithSuccess (cancelRequest , ARBCancelSubscriptionController .class , environment );
112
- Assert .assertNotNull (cancelResponse .getMessages ());
113
- logger .info (String .format ("Subscription Cancelled %s" , subscriptionId ));
118
+ //validation of list
119
+ ArrayOfSubscription subscriptionsArray = listResponse .getSubscriptionDetails ();
120
+ Assert .assertNotNull ( subscriptionsArray );
114
121
115
- //validation of list
116
- ArrayOfSubscription subscriptionsArray = listResponse .getSubscriptionDetails ();
117
- Assert .assertNotNull ( subscriptionsArray );
118
- boolean found = false ;
119
- int subsId = Integer .parseInt (subscriptionId );
120
- for ( SubscriptionDetail aSubscription : subscriptionsArray .getSubscriptionDetail ()) {
121
- Assert .assertTrue ( 0 < aSubscription .getId ());
122
- LogHelper .info ( logger , "Subscription Id: %s, Status:%s, PaymentMethod: %s, Amount: %s, Account:%s" ,
122
+ int subsId = Integer .parseInt (subscriptionId );
123
+ for ( SubscriptionDetail aSubscription : subscriptionsArray .getSubscriptionDetail ()) {
124
+ Assert .assertTrue ( 0 < aSubscription .getId ());
125
+ LogHelper .info ( logger , "Subscription Id: %s, Status:%s, PaymentMethod: %s, Amount: %s, Account:%s" ,
123
126
aSubscription .getId (), aSubscription .getStatus (), aSubscription .getPaymentMethod (), aSubscription .getAmount (), aSubscription .getAccountNumber ());
124
- if ( subsId == aSubscription .getId ()) { found = true ;}
127
+ if ( subsId == aSubscription .getId ()) { found = true ;}
128
+ }
129
+ } while (!found && --retryCount > 0 );
130
+
131
+ Assert .assertTrue ("Retried " + retryCount
132
+ + " times, the subscription " + subscriptionId
133
+ + " not found in the subscription list." , found );
134
+ } finally {
135
+ // cancel
136
+ ARBCancelSubscriptionRequest cancelRequest = new ARBCancelSubscriptionRequest ();
137
+ cancelRequest .setMerchantAuthentication (merchantAuthenticationType );
138
+ cancelRequest .setRefId (refId );
139
+ cancelRequest .setSubscriptionId (subscriptionId );
140
+ // explicitly setting up the merchant id and environment
141
+ ARBCancelSubscriptionResponse cancelResponse = executeTestRequestWithSuccess (
142
+ cancelRequest , ARBCancelSubscriptionController .class ,
143
+ environment );
144
+ Assert .assertNotNull (cancelResponse .getMessages ());
145
+ logger .info (String .format ("Subscription Cancelled %s" ,
146
+ subscriptionId ));
125
147
}
126
- Assert .assertTrue (found );
127
148
}
128
149
}
0 commit comments