-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestSchemeAdapter.java
More file actions
207 lines (156 loc) · 8.2 KB
/
Copy pathTestSchemeAdapter.java
File metadata and controls
207 lines (156 loc) · 8.2 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
package com.l1p.interop.scheme.adapter;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.mule.tck.junit4.FunctionalTestCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import io.restassured.response.Response;
public class TestSchemeAdapter extends FunctionalTestCase {
protected Logger logger = LoggerFactory.getLogger(getClass());
private static WireMockServer wireMockServer;
@Rule
public WireMockRule mockReceiverSchemeAdapter = new WireMockRule(8090);
@Rule
public WireMockRule dfspAPIService = new WireMockRule(8010);
@Rule
public WireMockRule dfspQuoteService = new WireMockRule(8020);
@Rule
public WireMockRule ilpService = new WireMockRule(3045);
@Rule
public WireMockRule notificationsService = new WireMockRule(8088);
@Override
protected String getConfigResources() {
return "test-resources.xml,scheme-adapter-api.xml,scheme-adapter.xml";
}
@BeforeClass
public static void initEnv() {
System.setProperty("MULE_ENV", "test");
}
@Test
public void testQuery() throws Exception {
String dfspReceiverResponseJson = loadResourceAsString("test_data/schemeAdapterReceiverMockResponse.json");
mockReceiverSchemeAdapter.stubFor(get(urlPathMatching("/scheme/adapter/v1/receivers/.*")).willReturn(aResponse().withBody(dfspReceiverResponseJson)));
given().
contentType("application/json").
queryParam("receiver", "localhost:8090/scheme/adapter/v1/receivers/123456").
when().
get("http://localhost:8088/scheme/adapter/v1/query").
then().
statusCode(200).
body("id", equalTo("http://ec2-35-166-180-190.us-west-2.compute.amazonaws.com:8088/ilp/ledger/v1/accounts/alice")).
body("name", equalTo("alice")).
body("balance", equalTo("1000.00")).
body("currencyCode", equalTo("USD")).
body("currencySymbol", equalTo("$")).
body("is_disabled", equalTo(false)).
body("ledger", equalTo("http://ec2-35-166-180-190.us-west-2.compute.amazonaws.com:8088/ilp/ledger/v1"));
}
@Test
public void testReceivers() throws Exception {
String dfspReceiverResponseJson = loadResourceAsString("test_data/dfspReceiverMockResponse.json");
dfspAPIService.stubFor(get(urlPathMatching("/receivers/.*")).willReturn(aResponse().withBody(dfspReceiverResponseJson)));
given().
contentType("application/json").
when().
get("http://localhost:8088/scheme/adapter/v1/receivers/123456").
then().
statusCode(200).
body("id", equalTo("http://ec2-35-166-189-14.us-west-2.compute.amazonaws.com:8088/ilp/ledger/v1/accounts/alice")).
body("name", equalTo("alice")).
body("balance", equalTo("1000.00")).
body("currencyCode", equalTo("USD")).
body("currencySymbol", equalTo("$")).
body("is_disabled", equalTo(false)).
body("ledger", equalTo("http://ec2-35-166-189-14.us-west-2.compute.amazonaws.com:8088/ilp/ledger/v1"));
}
@Test
@Ignore
public void testQuotes() throws Exception {
String dfspQuoteResponseJson = loadResourceAsString("test_data/dfspQuoteMockResponse.json");
dfspQuoteService.stubFor(post(urlMatching("/v1/quote")).willReturn(aResponse().withBody(dfspQuoteResponseJson)));
String ilpServiceMockCreateIPRMockJson = loadResourceAsString("test_data/ilpServiceCreateIPRMockResponse.json");
ilpService.stubFor(post(urlMatching("/createIPR")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(ilpServiceMockCreateIPRMockJson)));
String ilpServiceMockQuoteIPRMockJson = loadResourceAsString("test_data/ilpServiceQuoteIPRMockResponse.json");
ilpService.stubFor(get(urlPathMatching("/quoteIPR")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(ilpServiceMockQuoteIPRMockJson)));
String proxyQuoteRequestJson = loadResourceAsString("test_data/proxyQuoteRequest.json");
Response response =
given().
contentType("application/json").
body(proxyQuoteRequestJson).
when().
post("http://localhost:8088/scheme/adapter/v1/quotes");
logger.info("Response: "+response.asString());
assertEquals("receiveAmount","10",(String)response.jsonPath().get("receiveAmount.amount"));
assertEquals("payeeFee","1",(String)response.jsonPath().get("payeeFee.amount"));
assertEquals("payeeCommission","1",(String)response.jsonPath().get("payeeCommission.amount"));
assertEquals("ipr","Aojf9Pq9_RKgnS3mzvYnZAXvJuvjWnw6r-JXdwitLmHygdQBgdEAAAAAAAAEsDZsZXZlbG9uZS5kZnNwMS5hbGljZS5TdXVPNUdhaDUxSXM3VzVyUkdXdVBnTWVSdGtKOXZPelGBj1BTSy8xLjAKTm9uY2U6IHRsNF93NVRfaGhLM0FFcWJ3Ukg3VVEKRW5jcnlwdGlvbjogbm9uZQpQYXltZW50LUlkOiAxMTBlYzU4YS1hMGYyLTRhYzQtODM5My1jODY2ZDgxM2I4ZDEKCkV4cGlyZXMtQXQ6IDIwMTctMDYtMjBUMDA6MDA6MDEuMDAwWgoKAA==",(String)response.jsonPath().get("ipr"));
assertEquals("expiresAt","2017-06-14T00:00:01.000Z",(String)response.jsonPath().get("expiresAt"));
}
@Test
public void testPayments() throws Exception {
String proxyPaymentRequestJson = loadResourceAsString("test_data/proxyPaymentRequest.json");
String paymentMockResponseJson = loadResourceAsString("test_data/paymentMockResponse.json");
ilpService.stubFor(post(urlMatching("/payIPR")).willReturn(aResponse().withBody(paymentMockResponseJson).withStatus(201)).atPriority(2));
Response response =
given().
contentType("application/json").
body(proxyPaymentRequestJson).
when().
post("http://localhost:8088/scheme/adapter/v1/payments");
logger.info("Response: "+response.asString());
assertEquals("paymentId","123456",(String)response.jsonPath().get("paymentId"));
assertEquals("connectorAccount","123456",(String)response.jsonPath().get("connectorAccount"));
assertEquals("status","1",(String)response.jsonPath().get("status"));
assertEquals("rejectionMessage","rejection message",(String)response.jsonPath().get("rejectionMessage"));
assertEquals("fulfillment","fulfillment",(String)response.jsonPath().get("fulfillment"));
}
@Test
public void testIlpAddress() throws Exception {
String ilpAddressResponseJson = loadResourceAsString("test_data/ilpAddressMockResponse.json");
ilpService.stubFor(get(urlMatching("/ilpAddress.*")).willReturn(aResponse().withBody(ilpAddressResponseJson).withStatus(200)));
given().
contentType("application/json").
queryParam("account", "123459").
when().
get("http://localhost:8088/scheme/adapter/v1/ilpAddress").
then().
statusCode(200).
body("ilpAddress", equalTo("ok"));
}
@Test
public void testNotifications() throws Exception {
String notificationRequestBodyJson = loadResourceAsString("test_data/notificationMockRequestBody.json");
notificationsService.stubFor(post(urlPathMatching("/scheme/adapter/v1/notificationsXXX")).willReturn(aResponse().withStatus(500)));
given().
contentType("application/json").
body(notificationRequestBodyJson).
when().
post("http://localhost:8088/scheme/adapter/v1/notifications").
then().
statusCode(200);
}
@Test
public void testHealth() throws Exception {
String healthMockResponseJson = loadResourceAsString("test_data/healthMockResponse.json");
dfspAPIService.stubFor(get(urlPathMatching("/health")).willReturn(aResponse().withBody(healthMockResponseJson)));
given().
contentType("application/json").
when().
get("http://localhost:8088/scheme/adapter/v1/health").
then().
statusCode(200).
body("status", equalTo("ok"));
}
}