adamsaghy commented on code in PR #6115:
URL: https://github.com/apache/fineract/pull/6115#discussion_r3614879277
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java:
##########
@@ -18,175 +18,132 @@
*/
package org.apache.fineract.integrationtests.common;
-import static
org.apache.fineract.infrastructure.jobs.api.SchedulerJobApiConstants.SHORT_NAME_PARAM;
+import static org.apache.fineract.client.feign.util.FeignCalls.executeVoid;
+import static org.apache.fineract.client.feign.util.FeignCalls.ok;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import com.google.gson.Gson;
-import io.restassured.builder.ResponseSpecBuilder;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializer;
import io.restassured.specification.RequestSpecification;
-import io.restassured.specification.ResponseSpecification;
import java.time.Duration;
-import java.util.HashMap;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
+import org.apache.fineract.client.models.CommandProcessingResult;
+import org.apache.fineract.client.models.ExecuteJobRequest;
import org.apache.fineract.client.models.GetJobsResponse;
+import org.apache.fineract.client.models.GetSchedulerResponse;
import org.apache.fineract.client.models.PutJobsJobIDRequest;
-import org.apache.fineract.client.util.Calls;
import org.hamcrest.MatcherAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Feign-based. Still instance-shaped (see constructor) purely for source
compatibility with existing call sites; a
+ * follow-up PR will static-ify this class and update all callers in one
mechanical pass.
+ */
public class SchedulerJobHelper {
private static final Logger LOG =
LoggerFactory.getLogger(SchedulerJobHelper.class);
- private final RequestSpecification requestSpec;
- private final ResponseSpecification response200Spec;
+ private static final Gson GSON = new GsonBuilder()
+ .registerTypeAdapter(OffsetDateTime.class,
+ (JsonSerializer<OffsetDateTime>) (src, type, ctx) -> src
== null ? null
+ : new
JsonPrimitive(DateTimeFormatter.ISO_INSTANT.format(src.toInstant())))
+ .registerTypeAdapter(LocalDateTime.class,
+ (JsonSerializer<LocalDateTime>) (src, type, ctx) -> src ==
null ? null
+ : new
JsonPrimitive(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss").format(src)))
+ .registerTypeAdapter(LocalDate.class,
+ (JsonSerializer<LocalDate>) (src, type, ctx) -> src ==
null ? null : new JsonPrimitive(src.toString()))
+ .create();
- // TODO: Rewrite to use fineract-client instead!
- // Example:
org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
- @Deprecated(forRemoval = true)
+ /**
+ * @deprecated the {@code requestSpec} parameter is unused now that this
Helper is Feign-based. Retained only so
+ * existing {@code new SchedulerJobHelper(requestSpec)} call
sites keep compiling; prefer relying on
+ * static usage once callers are migrated in a follow-up PR.
+ */
+ @Deprecated
public SchedulerJobHelper(final RequestSpecification requestSpec) {
- this.requestSpec = requestSpec;
- this.response200Spec = new
ResponseSpecBuilder().expectStatusCode(200).build();
+ // no-op: retained for source compatibility with existing callers
}
- // TODO: Rewrite to use fineract-client instead!
- // Example:
org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
- @Deprecated(forRemoval = true)
- private List<Map<String, Object>> getAllSchedulerJobs() {
- final String GET_ALL_SCHEDULER_JOBS_URL =
"/fineract-provider/api/v1/jobs?" + Utils.TENANT_IDENTIFIER;
+ private List<GetJobsResponse> getAllSchedulerJobs() {
LOG.info("------------------------ RETRIEVING ALL SCHEDULER JOBS
-------------------------");
- List<Map<String, Object>> response =
Utils.performServerGet(requestSpec, response200Spec,
GET_ALL_SCHEDULER_JOBS_URL, "");
+ List<GetJobsResponse> response = ok(
+ () ->
FineractFeignClientHelper.getFineractFeignClient().schedulerJob().retrieveAllSchedulerJobs());
assertNotNull(response);
return response;
}
- private <T> List<T> getAllSchedulerJobDetails(Function<Map<String,
Object>, T> mapper) {
+ private <T> List<T> getAllSchedulerJobDetails(Function<GetJobsResponse, T>
mapper) {
return
getAllSchedulerJobs().stream().map(mapper).collect(Collectors.toList());
}
public List<Integer> getAllSchedulerJobIds() {
- return getAllSchedulerJobDetails(map -> (Integer) map.get("jobId"));
+ return getAllSchedulerJobDetails(job -> job.getJobId().intValue());
}
public List<String> getAllSchedulerJobNames() {
- return getAllSchedulerJobDetails(map -> (String)
map.get("displayName"));
+ return getAllSchedulerJobDetails(GetJobsResponse::getDisplayName);
}
- // TODO: Rewrite to use fineract-client instead!
- // Example:
org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
- // org.apache.fineract.client.models.PostLoansLoanIdRequest)
- @Deprecated(forRemoval = true)
public Map<String, Object> getSchedulerJobById(int jobId) {
- final String GET_SCHEDULER_JOB_BY_ID_URL =
"/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
LOG.info("------------------------ RETRIEVING SCHEDULER JOB BY ID
-------------------------");
- final Map<String, Object> response =
Utils.performServerGet(requestSpec, response200Spec,
GET_SCHEDULER_JOB_BY_ID_URL, "");
- LOG.info("{}", response.toString());
+ GetJobsResponse response = ok(
+ () ->
FineractFeignClientHelper.getFineractFeignClient().schedulerJob().retrieveOneSchedulerJob((long)
jobId));
assertNotNull(response);
- return response;
+ LOG.info("{}", response);
+ return toMap(response);
Review Comment:
Return the real object, do not map with gson
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]