-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new version to simulate response time of 3rd party systems.
- Loading branch information
1 parent
f8067fa
commit 20c1cf2
Showing
2 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
147 changes: 147 additions & 0 deletions
147
src/main/java/it/pagopa/swclient/mil/PerfV2Resource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package it.pagopa.swclient.mil; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.netty.util.internal.ThreadLocalRandom; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.PATCH; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.core.UriInfo; | ||
import jakarta.ws.rs.core.Response.Status; | ||
|
||
@Path("/perf/v2") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.WILDCARD) | ||
public class PerfV2Resource { | ||
private static final String GET_ACCESS_TOKEN_RESP = "{\"access_token\":\"eyJraWQiOiJhdXRoNGFkZDY1OGI4YTEzNDVmZWIyZTAwZTc1YzEyYjYxY2YvNWIzODVlNGY0YjQ1NDgzYmE0MDJjZmY4MTIwOWE4MDUiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI4M2MwYjEwZi1iMzk4LTRjYzgtYjM1Ni1hM2UwZjAyOTE2NzkiLCJhdWQiOiJtaWwucGFnb3BhLml0IiwiY2xpZW50SWQiOiI4M2MwYjEwZi1iMzk4LTRjYzgtYjM1Ni1hM2UwZjAyOTE2NzkiLCJjaGFubmVsIjoiQVRNIiwiaXNzIjoiaHR0cHM6Ly9taWwtZC1hcGltLmF6dXJlLWFwaS5uZXQvbWlsLWF1dGgiLCJncm91cHMiOlsiTm90aWNlUGF5ZXIiLCJFbnJvbGxUb0lEUGF5Il0sInRlcm1pbmFsSWQiOiI2NDg3NDQxMiIsImV4cCI6MTcxNzc1ODI1MSwiYWNxdWlyZXJJZCI6IjA2Nzg5IiwiaWF0IjoxNzE3NzU3MzUxfQ.UeFXE0yieBzHCfv2Ju8cUucDUDNWU9zY3uht5nXDutsi46INRL8sd9o9jfPR1MdbXQsrFLW3NTrJaVNYiC9YVuuBuhKGc3MbiOsp3SfjmZEyeesoElwMnfmTCwLvny_W9-VgNCQ097GRA9xc2mD1Q7q6HerJnhPRJ30JllKOuxVXfVXssDbOP-k7_HrUs5Mh-8AXTx11BhA9EBniPn5PtzIv0zYkDVTo_cPBYoFrkubuQPTWTLWds0wPpswg0Vi3LCENdZBbtcQQCp8A65lQKfHQi7BPeV3rlLKfK9zjtSqOG0Poy-EZReU1AVqYQygUEijYEQ2CDmWQpXiI7CZ19QUXMJyeKrBanpH6ASG_MlveQ6RM9EuyMxIyguy6ebqkIMZipwCK4ZHNGrHDVqI0jUudpu1xKNwZ7JQ3E4sMRDN9Q8umviBGkP5cZdlU86dcnRUlSPqyu3xJzia7ywvia651VlywcvyuW7BafMJKcsUiUL9hl1ypobetywa-DPLXV02nECJQnIfQ7IiucyuxCjetSxHEyW2pRnFd2mDjk1J5gL9w7vli2zBQY7XKmAVHzVBz4uBrHhY62qbl47l7YPiugmg9UGG-seoLJzkNlik06OouQUer7wyHVKRI859rNaG92wk2sj_353dLH6eFUiVSkENBWgUJLYW46IhXPYQ\",\"token_type\":\"Bearer\",\"expires_in\":900}"; | ||
private static final String VERIFY_RESPONSE = "{\"outcome\":\"OK\",\"amount\":10000,\"dueDate\":\"2021-07-31\",\"note\":\"pagamentoTest\",\"description\":\"Pagamento di Test\",\"company\":\"companyName\",\"office\":\"officeName\",\"paTaxCode\":\"00000000201\",\"noticeNumber\":\"012345678901234567\"}"; | ||
private static final String ACTIVATE_RESPONSE = "{\"outcome\":\"OK\",\"amount\":10000,\"paTaxCode\":\"00000000201\",\"paymentToken\":\"37b0bb69ce774bc2bfeb485e107ae335\",\"transfers\":[{\"paTaxCode\":\"00000000201\",\"category\":\"\"}]}"; | ||
private static final String GET_FEES_RESPONSE = "{\"fee\":50}"; | ||
private static final String PRECLOSE_RESP = "{\"outcome\":\"OK\"}"; | ||
private static final String PRECLOSE_LOCATION = "3a4d848c6b3db5379b8067cc4a297290"; | ||
private static final String GET_STATUS_RESP = "{\"transactionId\":\"3a4d848c6b3db5379b8067cc4a297290\",\"acquirerId\":\"06789\",\"channel\":\"ATM\",\"merchantId\":null,\"terminalId\":\"64874412\",\"insertTimestamp\":\"2024-06-07T10:51:34\",\"notices\":[{\"paymentToken\":\"37b0bb69ce774bc2bfeb485e107ae335\",\"paTaxCode\":\"00000000201\",\"noticeNumber\":\"012345678901234567\",\"amount\":10000,\"description\":\"TARI 2021\",\"company\":\"companyName\",\"office\":\"officeName\",\"creditorReferenceId\":null,\"debtor\":null}],\"totalAmount\":10000,\"fee\":50,\"status\":\"CLOSED\",\"paymentMethod\":\"PAGOBANCOMAT\",\"paymentTimestamp\":\"2024-06-07T12:52:25\",\"closeTimestamp\":\"2024-06-07T10:52:07\",\"paymentDate\":null,\"callbackTimestamp\":null,\"preset\":null}"; | ||
|
||
@ConfigProperty(name = "getAccessToken.response-time.mean", defaultValue = "1250") | ||
int getAccessTokenMeanRespTime; | ||
|
||
@ConfigProperty(name = "getAccessToken.response-time.std-dev", defaultValue = "638") | ||
int getAccessTokenStdDevRespTime; | ||
|
||
@ConfigProperty(name = "getFees.response-time.mean", defaultValue = "250") | ||
int getFeesMeanRespTime; | ||
|
||
@ConfigProperty(name = "getFees.response-time.std-dev", defaultValue = "128") | ||
int getFeesRespTimeStdDev; | ||
|
||
@ConfigProperty(name = "nodo.response-time.mean", defaultValue = "2000") | ||
int nodoMeanRespTime; | ||
|
||
@ConfigProperty(name = "nodo.response-time.std-dev", defaultValue = "1020") | ||
int nodoRespTimeStdDev; | ||
|
||
@ConfigProperty(name = "preCloseOrGetStatus.response-time.mean", defaultValue = "250") | ||
int preCloseOrGetStatusMeanRespTime; | ||
|
||
@ConfigProperty(name = "preCloseOrGetStatus.response-time.std-dev", defaultValue = "128") | ||
int preCloseOrGetStatusRespTimeStdDev; | ||
|
||
private long getAccessTokenRespTime() { | ||
long respTime = (long) ThreadLocalRandom.current().nextGaussian(getAccessTokenMeanRespTime, getAccessTokenStdDevRespTime); | ||
if (respTime < 0) | ||
return 0; | ||
return respTime; | ||
} | ||
|
||
private long getFeesRespTime() { | ||
long respTime = (long) ThreadLocalRandom.current().nextGaussian(getFeesMeanRespTime, getFeesRespTimeStdDev); | ||
if (respTime < 0) | ||
return 0; | ||
return respTime; | ||
} | ||
|
||
private long nodoRespTime() { | ||
long respTime = (long) ThreadLocalRandom.current().nextGaussian(nodoMeanRespTime, nodoRespTimeStdDev); | ||
if (respTime < 0) | ||
return 0; | ||
return respTime; | ||
} | ||
|
||
private long preCloseOrGetStatusRespTime() { | ||
long respTime = (long) ThreadLocalRandom.current().nextGaussian(preCloseOrGetStatusMeanRespTime, preCloseOrGetStatusRespTimeStdDev); | ||
if (respTime < 0) | ||
return 0; | ||
return respTime; | ||
} | ||
|
||
@Path("/mil-auth/token") | ||
@POST | ||
public Response getAccessToken() throws InterruptedException { | ||
Thread.sleep(getAccessTokenRespTime()); | ||
return Response.ok(GET_ACCESS_TOKEN_RESP).build(); | ||
} | ||
|
||
@Path("/mil-payment-notice/paymentNotices/{pa_tax_code}/{notice_number}") | ||
@GET | ||
public Response verify() throws InterruptedException { | ||
Thread.sleep(nodoRespTime()); | ||
return Response.ok(VERIFY_RESPONSE).build(); | ||
} | ||
|
||
@Path("/mil-payment-notice/paymentNotices/{qr_code}") | ||
@GET | ||
public Response verifyQr() throws InterruptedException { | ||
Thread.sleep(nodoRespTime()); | ||
return Response.ok(VERIFY_RESPONSE).build(); | ||
} | ||
|
||
@Path("/mil-payment-notice/paymentNotices/{pa_tax_code}/{notice_number}") | ||
@PATCH | ||
public Response activate() throws InterruptedException { | ||
Thread.sleep(nodoRespTime()); | ||
return Response.ok(ACTIVATE_RESPONSE).build(); | ||
} | ||
|
||
@Path("/mil-payment-notice/paymentNotices/{qr_code}") | ||
@PATCH | ||
public Response activateQr() throws InterruptedException { | ||
Thread.sleep(nodoRespTime()); | ||
return Response.ok(ACTIVATE_RESPONSE).build(); | ||
} | ||
|
||
@Path("/mil-fee-calculator/fees") | ||
@POST | ||
public Response getFees() throws InterruptedException { | ||
Thread.sleep(getFeesRespTime()); | ||
return Response.ok(GET_FEES_RESPONSE).build(); | ||
} | ||
|
||
@Path("/mil-payment-notice/payments") | ||
@POST | ||
public Response preClose(@Context UriInfo uriInfo) throws InterruptedException { | ||
Thread.sleep(preCloseOrGetStatusRespTime()); | ||
return Response.status(Status.CREATED) | ||
.location(uriInfo.getAbsolutePathBuilder().path(PRECLOSE_LOCATION).build()) | ||
.entity(PRECLOSE_RESP) | ||
.build(); | ||
} | ||
|
||
@Path("/mil-payment-notice/payments/{transaction_id}/sendPaymentOutcome") | ||
@PATCH | ||
public Response sendPaymentOutcome() throws InterruptedException { | ||
Thread.sleep(nodoRespTime()); | ||
return Response.accepted().build(); | ||
} | ||
|
||
@Path("/mil-payment-notice/payments/{transaction_id}") | ||
@GET | ||
public Response getStatus() throws InterruptedException { | ||
Thread.sleep(preCloseOrGetStatusRespTime()); | ||
return Response.ok(GET_STATUS_RESP).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
getAccessToken.response-time.mean=${GET_ACCESS_TOKEN_MEAN_RESP_TIME:1250} | ||
getAccessToken.response-time.std-dev=${GET_ACCESS_TOKEN_RESP_TIME_STD_DEV:638} | ||
|
||
getFees.response-time.mean"=${GET_FEES_MEAN_RESP_TIME:250} | ||
getFees.response-time.std-dev=${GET_FEES_RESP_TIME_STD_DEV:128} | ||
nodo.response-time.mean=${NODO_MEAN_RESP_TIME:2000} | ||
nodo.response-time.std-dev=${NODO_RESP_TIME_STD_DEV:1020} | ||
preCloseOrGetStatus.response-time.mean=${PRECLOSE_OR_GET_STATUS_MEAN_RESP_TIME:250} | ||
preCloseOrGetStatus.response-time.std-dev=${PRECLOSE_OR_GET_STATUS_RESP_TIME_STD_DEV:128} |