-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathInstamojoIntegrationTest.java
More file actions
192 lines (157 loc) · 6.88 KB
/
InstamojoIntegrationTest.java
File metadata and controls
192 lines (157 loc) · 6.88 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
package com.instamojo.wrapper.api;
import com.instamojo.wrapper.builder.PaymentOrderBuilder;
import com.instamojo.wrapper.exception.HTTPException;
import com.instamojo.wrapper.filter.PaymentRequestFilter;
import com.instamojo.wrapper.model.PaymentOrder;
import com.instamojo.wrapper.model.PaymentOrderResponse;
import com.instamojo.wrapper.model.PaymentRequest;
import com.instamojo.wrapper.response.ApiListResponse;
import com.instamojo.wrapper.util.TestConstants;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static com.instamojo.wrapper.api.ApiContext.Mode;
import static org.junit.Assert.*;
public class InstamojoIntegrationTest {
private Instamojo api;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
ApiContext.ClearInstance();
ApiContext context = ApiContext.create(TestConstants.CLIENT_ID, TestConstants.CLIENT_SECRET, Mode.TEST);
api = new InstamojoImpl(context);
}
@Test
public void createValidPaymentOrder() throws Exception {
PaymentOrder order = new PaymentOrderBuilder().build();
PaymentOrderResponse paymentOrderResponse = api.createPaymentOrder(order);
assertNotNull(paymentOrderResponse);
assertNotNull(paymentOrderResponse.getPaymentOrder().getId());
assertEquals(paymentOrderResponse.getPaymentOrder().getTransactionId(), order.getTransactionId());
}
@Test
public void createPaymentOrder_InvalidWebhookUrl() throws Exception {
expectedException.expect(HTTPException.class);
expectedException.expectMessage("Bad Request");
PaymentOrder paymentOrder = new PaymentOrderBuilder()
.withWebhookUrl("invalid_url")
.build();
api.createPaymentOrder(paymentOrder);
}
@Test
public void createPaymentOrder_NullWebhookUrl() throws Exception {
PaymentOrder order = new PaymentOrderBuilder()
.withWebhookUrl(null)
.build();
api.createPaymentOrder(order);
assertNull(order.getWebhookUrl());
}
@Test
public void createPaymentOrder_ExistingTransactionId() throws Exception {
PaymentOrder order = new PaymentOrderBuilder().build();
api.createPaymentOrder(order);
expectedException.expect(HTTPException.class);
expectedException.expectMessage("Bad Request");
api.createPaymentOrder(order);
}
@Test
public void getPaymentOrderById() throws Exception {
PaymentOrder newPaymentOrder = new PaymentOrderBuilder().build();
PaymentOrderResponse paymentOrderResponse = api.createPaymentOrder(newPaymentOrder);
String paymentOrderId = paymentOrderResponse.getPaymentOrder().getId();
PaymentOrder paymentOrder = api.getPaymentOrder(paymentOrderId);
assertNotNull(paymentOrder);
assertEquals(paymentOrder.getId(), paymentOrderId);
assertEquals(paymentOrder.getTransactionId(), newPaymentOrder.getTransactionId());
}
@Test
public void getPaymentOrderByTransactionId() throws Exception {
String transactionId = UUID.randomUUID().toString();
PaymentOrder newPaymentOrder = new PaymentOrderBuilder().withTransactionId(transactionId).build();
PaymentOrderResponse paymentOrderResponse = api.createPaymentOrder(newPaymentOrder);
PaymentOrder paymentOrder = api.getPaymentOrderByTransactionId(transactionId);
assertNotNull(paymentOrder);
assertEquals(paymentOrder.getTransactionId(), transactionId);
assertEquals(paymentOrder.getId(), paymentOrderResponse.getPaymentOrder().getId());
}
@Test
public void getPaymentOrdersByFilter() throws Exception {
PaymentOrder order = new PaymentOrderBuilder().build();
PaymentOrderResponse paymentOrderResponse = api.createPaymentOrder(order);
ApiListResponse<PaymentOrder> paymentOrders = api.getPaymentOrders(1, 1);
assertEquals(1, paymentOrders.getResults().size());
}
@Test
public void createWebhookSignature() {
Map<String, String> map = new HashMap<>();
map.put("foo", "1");
map.put("bar", "2");
map.put("baz", "3");
String signature = api.generateWebhookSignature(map, TestConstants.CLIENT_SALT);
assertEquals(signature, "32b1d38a4a70bdce36a52dad3f3ac6eb3662096b");
}
@Test
public void getPayoutById_InvalidId() throws Exception {
expectedException.expect(HTTPException.class);
expectedException.expectMessage("Not Found");
api.getPayout("invalid_id");
}
@Test
public void createValidPaymentRequest() throws Exception {
PaymentRequest rap = new PaymentRequest();
rap.setAmount(10.0);
rap.setEmail("vijith@instamojo.com");
rap.setPurpose("testing rap");
PaymentRequest createdRap = api.createPaymentRequest(rap);
assertNotNull(createdRap);
}
@Test
public void getPaymentRequestsByFilter() throws Exception {
PaymentRequest rap = new PaymentRequest();
rap.setAmount(10.0);
rap.setEmail("vijith@instamojo.com");
rap.setPurpose("testing rap");
rap.setPhone("+919999999999");
api.createPaymentRequest(rap);
Map<PaymentRequestFilter, String> filter = new HashMap<>();
filter.put(PaymentRequestFilter.PHONE, "+919999999999");
ApiListResponse<PaymentRequest> raps = api.getPaymentRequests(filter, 1, 1);
assertEquals(1, raps.getResults().size());
assertEquals(rap.getPhone(), raps.getResults().get(0).getPhone());
}
@Test
public void getPaymentRequestById() throws Exception {
PaymentRequest rap = new PaymentRequest();
rap.setAmount(10.0);
rap.setEmail("vijith@instamojo.com");
rap.setPurpose("testing rap");
PaymentRequest createdRap = api.createPaymentRequest(rap);
PaymentRequest retrievedRap = api.getPaymentRequest(createdRap.getId());
assertNotNull(retrievedRap);
}
@Test
public void enablePaymentRequest() throws Exception {
PaymentRequest rap = new PaymentRequest();
rap.setAmount(10.0);
rap.setEmail("vijith@instamojo.com");
rap.setPurpose("testing rap");
PaymentRequest createdRap = api.createPaymentRequest(rap);
Boolean success = api.enablePaymentRequest(createdRap.getId());
assertTrue(success);
}
@Test
public void disablePaymentRequest() throws Exception {
PaymentRequest rap = new PaymentRequest();
rap.setAmount(10.0);
rap.setEmail("vijith@instamojo.com");
rap.setPurpose("testing rap");
PaymentRequest createdRap = api.createPaymentRequest(rap);
Boolean success = api.disablePaymentRequest(createdRap.getId());
assertTrue(success);
}
}