This is an automated email from the ASF dual-hosted git repository.

vorburger pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 55af726  improve SchedulerJobsTest.testDateFormat() by introducing 
Awaitility
55af726 is described below

commit 55af726cf9b9807758f4310a7e0b3bfa2dff2c4f
Author: Michael Vorburger <[email protected]>
AuthorDate: Sat May 9 00:07:12 2020 +0200

    improve SchedulerJobsTest.testDateFormat() by introducing Awaitility
    
    This recently introduced new test (FINERACT-926) would locally pass, but
    then fail on the next run, because another test in the same class would
    modify job state to be inactive.  It now sets the first jobs state as it
    requires it to be, and properly awaits the expected outcome.
---
 fineract-provider/build.gradle                            |  2 +-
 fineract-provider/dependencies.gradle                     |  5 +++--
 .../fineract/integrationtests/SchedulerJobsTest.java      | 15 ++++++++-------
 .../integrationtests/common/SchedulerJobHelper.java       |  4 +++-
 4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle
index abb8672..92aa7d5 100644
--- a/fineract-provider/build.gradle
+++ b/fineract-provider/build.gradle
@@ -114,7 +114,7 @@ dependencyManagement {
         dependency 'io.github.classgraph:classgraph:4.8.43'
         dependency 'org.dom4j:dom4j:2.1.0'
         dependency 'nekohtml:nekohtml:1.9.6.2'
-
+               dependency 'org.awaitility:awaitility:4.0.2'
 
         dependencySet(group: 'com.sun.jersey', version: jerseyVersion) {
             entry 'jersey-core'
diff --git a/fineract-provider/dependencies.gradle 
b/fineract-provider/dependencies.gradle
index fa31e93..7213b91 100644
--- a/fineract-provider/dependencies.gradle
+++ b/fineract-provider/dependencies.gradle
@@ -78,7 +78,7 @@ dependencies {
                exclude group: 'javax.validation'
     }
     implementation ('org.apache.activemq:activemq-broker') {
-       exclude group: 'org.apache.geronimo.specs'
+        exclude group: 'org.apache.geronimo.specs'
     }
     implementation ('org.springframework.boot:spring-boot-starter-data-jpa') {
                exclude group: 'org.hibernate'
@@ -111,9 +111,10 @@ dependencies {
        // Do NOT repeat dependencies which are ALREADY in implementation or 
runtimeOnly!
        //
     testImplementation( 'junit:junit',
-               'org.junit.platform:junit-platform-runner', // FINERACT-943
+            'org.junit.platform:junit-platform-runner', // FINERACT-943
             'org.mockito:mockito-core',
             'io.github.classgraph:classgraph',
+            'org.awaitility:awaitility'
        )
     testImplementation ('io.rest-assured:rest-assured') {
         exclude group: 'commons-logging'
diff --git 
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/SchedulerJobsTest.java
 
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/SchedulerJobsTest.java
index 3ce443c..623cfd8 100644
--- 
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/SchedulerJobsTest.java
+++ 
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/SchedulerJobsTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.fineract.integrationtests;
 
+import static org.awaitility.Awaitility.await;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -34,7 +35,6 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
 public class SchedulerJobsTest {
 
     private RequestSpecification requestSpec;
@@ -51,9 +51,10 @@ public class SchedulerJobsTest {
 
     @Test // FINERACT-926
     public void testDateFormat() {
-        Map<String, Object> schedulerJob1 = 
schedulerJobHelper.getSchedulerJobById(1);
-        String nextRunTimeText = (String)schedulerJob1.get("nextRunTime");
-        assertNotNull("nextRunTime == null: " + schedulerJob1, 
nextRunTimeText);
+        // must start scheduler and make job active to have nextRunTime (which 
is a java.util.Date)
+        schedulerJobHelper.updateSchedulerStatus(true);
+        schedulerJobHelper.updateSchedulerJob(1, "true");
+        String nextRunTimeText = await().until(() -> 
(String)schedulerJobHelper.getSchedulerJobById(1).get("nextRunTime"), 
nextRunTime -> nextRunTime != null);
         DateTimeFormatter.ISO_INSTANT.parse(nextRunTimeText);
     }
 
@@ -62,12 +63,12 @@ public class SchedulerJobsTest {
         // Retrieving Status of Scheduler
         Boolean schedulerStatus = schedulerJobHelper.getSchedulerStatus();
         if (schedulerStatus == true) {
-            schedulerJobHelper.updateSchedulerStatus("stop");
+            schedulerJobHelper.updateSchedulerStatus(false);
             schedulerStatus = schedulerJobHelper.getSchedulerStatus();
             // Verifying Status of the Scheduler after stopping
             assertEquals("Verifying Scheduler Job Status", false, 
schedulerStatus);
         } else {
-            schedulerJobHelper.updateSchedulerStatus("start");
+            schedulerJobHelper.updateSchedulerStatus(true);
             schedulerStatus = schedulerJobHelper.getSchedulerStatus();
             // Verifying Status of the Scheduler after starting
             assertEquals("Verifying Scheduler Job Status", true, 
schedulerStatus);
@@ -77,7 +78,7 @@ public class SchedulerJobsTest {
     @Test
     public void testFlippingJobsActiveStatus() throws InterruptedException {
         // Stop the Scheduler while we test flapping jobs' active on/off, to 
avoid side effects
-        schedulerJobHelper.updateSchedulerStatus("stop");
+        schedulerJobHelper.updateSchedulerStatus(false);
 
         // For each retrieved scheduled job (by ID)...
         for (Integer jobId : schedulerJobHelper.getAllSchedulerJobIds()) {
diff --git 
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java
 
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java
index 55b00d9..560f932 100644
--- 
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java
+++ 
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/SchedulerJobHelper.java
@@ -67,6 +67,7 @@ public class SchedulerJobHelper {
         final String GET_SCHEDULER_JOB_BY_ID_URL = 
"/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
         System.out.println("------------------------ RETRIEVING SCHEDULER JOB 
BY ID -------------------------");
         final Map<String, Object> response = 
Utils.performServerGet(requestSpec, response200Spec, 
GET_SCHEDULER_JOB_BY_ID_URL, "");
+        System.out.println(response);
         assertNotNull(response);
         return response;
     }
@@ -78,7 +79,8 @@ public class SchedulerJobHelper {
         return (Boolean) response.get("active");
     }
 
-    public void updateSchedulerStatus(final String command) {
+    public void updateSchedulerStatus(final boolean on) {
+        String command = on ? "start" : "stop";
         final String UPDATE_SCHEDULER_STATUS_URL = 
"/fineract-provider/api/v1/scheduler?command=" + command + "&" + 
Utils.TENANT_IDENTIFIER;
         System.out.println("------------------------ UPDATING SCHEDULER STATUS 
-------------------------");
         Utils.performServerPost(requestSpec, response202Spec, 
UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);

Reply via email to