Skip to content

Commit

Permalink
[sc-13165] Testing the framework (#5)
Browse files Browse the repository at this point in the history
* Removed BasicWebTest: The suite is run using a shell script which invokes the JAR
* Cleanup unused experiments
* Add Helper Tests
* Removed shade-y warnings
* Fix org.junit.jupiter.junit-jupiter at 5.11.0
* Add Period tests
* Clean up
* Remove unused pom lines
* Remove lint test
  • Loading branch information
igbanam authored Sep 18, 2024
1 parent c19d484 commit 2a1cd8f
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 120 deletions.
34 changes: 22 additions & 12 deletions rtsl_util/CommonUtils/Dhis2CucumberTestTool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.MF</exclude>
<exclude>META-INF/license*</exclude>
<exclude>META-INF/LICENSE*</exclude>
<exclude>META-INF/notice*</exclude>
<exclude>META-INF/NOTICE*</exclude>
<exclude>META-INF/DEPENDENCIES*</exclude>
<exclude>META-INF/**/pom.properties</exclude>
<exclude>META-INF/**/pom.xml</exclude>
<exclude>META-INF/spring/*</exclude>
<exclude>META-INF/okio*</exclude>
<exclude>META-INF/spring.tooling</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -120,17 +141,6 @@
<type>pom</type>
<scope>test</scope>
</dependency>
<!-- SELENIUM STUFF -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.21.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>4.21.0</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
Expand All @@ -139,7 +149,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<version>5.11.0</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,4 @@ private String handleResponse(CloseableHttpResponse response) throws Exception {
}
return responseBody;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,4 @@ public Map<String, String> convertMetadata(Map<String, String> inputData, String

return returnMap;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ public static LocalDateTime current() throws Exception {
public static LocalDateTime toDateTime(String dateTimeString) throws Exception {
return LocalDateTime.parse(dateTimeString, ISO_DATE_TIME_FORMATTER);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

public class Period {

private static final LocalDateTime now = LocalDateTime.now();
private static final LocalDate today = LocalDate.now();
final static DateTimeFormatter YEAR_MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
final static DateTimeFormatter REPORTING_YEAR_MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyyMM");
Expand All @@ -27,10 +26,6 @@ public static String toReportingDateString(String relativeDate, String periodTyp
return parseRelativeDate(relativeDate).format(REPORTING_YEAR_QUARTER_FORMATTER);
}

public static LocalDate toDate(String relativeDate) {
return parseRelativeDate(relativeDate);
}

public static LocalDate parseRelativeDate(String relativeDate) {
// Split the relative date string by "_"
String[] parts = relativeDate.split("_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ public final class TestUniqueId {
public String get() {
return testUniqueId;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,49 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
">




<bean id="mobileDesiredCapabilities" class="org.openqa.selenium.remote.DesiredCapabilities">
<constructor-arg>
<util:map>
<entry key="platformName" value="Android" />
<entry key="platformVersion" value="8.0" />
<entry key="app" value="/Users/test/Downloads/FirstAutomationTest/src/test/resources/DemoApp.apk" />
<entry key="deviceName" value="c4e3f3cd" />
<entry key="automationName" value="UiAutomator2" />
</util:map>
</constructor-arg>
</bean>


<!--
<bean id="androidDriver" class="io.appium.java_client.android.AndroidDriver" >
<constructor-arg value="http://127.0.0.1:4723/" />
<constructor-arg ref="mobileDesiredCapabilities" />
</bean>
-->
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
">
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@

<import resource="classpath:org.rtsl.common.properties.standard.context.xml" />
<import resource="spring.api.xml" />

<!-- Maybe later :) /-->
<!-- import resource="spring.android.xml" /-->


<bean id="org.rtsl.common.properties.standard.rawProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true"/>
<property name="localOverride" value="true"/>
Expand Down Expand Up @@ -59,41 +56,26 @@
</bean>
<bean id="trackedEntityInstance" class="org.rtsl.dhis2.cucumber.factories.TrackedEntityInstance" scope="cucumber-glue"/>
<bean id="testAtomicInt" class="java.util.concurrent.atomic.AtomicInteger" scope="cucumber-glue"/>
<bean id="webDriver" class="org.openqa.selenium.firefox.FirefoxDriver" scope="cucumber-glue"/>

<bean id="dhis2Config" class="org.hisp.dhis.Dhis2Config">
<constructor-arg value="${dhis2.api.url}" />
<constructor-arg value="${dhis2.api.username}" />
<constructor-arg value="${dhis2.api.password}" />
</bean>

<bean id="dhisClient" class="org.hisp.dhis.Dhis2">
<constructor-arg ref="dhis2Config" />
</bean>


</bean>
<bean id="dhis2SdkClientBuilder" class="org.hisp.dhis.integration.sdk.Dhis2ClientBuilder" factory-method="newClient">
<constructor-arg value="${dhis2.api.url}/api" />
<constructor-arg value="${dhis2.api.username}" />
<constructor-arg value="${dhis2.api.password}" />
</bean>


<bean id="dhisSdkClient" factory-bean="dhis2SdkClientBuilder" factory-method="build" />


<bean id="testClient" class="org.rtsl.dhis2.cucumber.Dhis2HttpClient" scope="singleton">
<constructor-arg value="${dhis2.api.url}" />
<constructor-arg value="${dhis2.api.username}" />
<constructor-arg value="${dhis2.api.password}" />
</bean>


</bean>
<bean id="testIdConverter" class="org.rtsl.dhis2.cucumber.Dhis2IdConverter" init-method="getMetadata" scope="singleton">
<constructor-arg ref="testClient" />
</bean>




</bean>
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.rtsl.dhis2.cucumber;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class HelperTests {
@Test
public void testToISODateTimeString() throws Exception {
String actual = Helper.toISODateTimeString("2021-01-01");

Assertions.assertEquals("2021-01-01T00:00:00.000", actual);
}

@Test
public void testToDateTime() throws Exception {
var actual = Helper.toDateTime("2021-01-01T00:00:00.000");

Assertions.assertEquals(2021, actual.getYear());
Assertions.assertEquals(1, actual.getMonthValue());
Assertions.assertEquals(1, actual.getDayOfMonth());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.rtsl.dhis2.cucumber;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class PeriodTests {
@Test
public void testMonthsAgo() throws Exception {
assertMonthsBetween("3_MonthsAgo", -3);
}

@Test
public void testThisMonth() throws Exception {
assertMonthsBetween("thisMonth", 0);
}

@Test
public void testQuartersAgo() throws Exception {
LocalDate today = LocalDate.now();
LocalDate pointInTime = Period.parseRelativeDate("2_QuartersAgo");
long diff = ChronoUnit.MONTHS.between(pointInTime, today);
Assertions.assertTrue(diff >= 6); // Closer boundary
Assertions.assertTrue(diff <= 9); // Farther boundary
}

@Test
public void testThisQuarter() throws Exception {
LocalDate today = LocalDate.now();
LocalDate pointInTime = Period.parseRelativeDate("thisQuarter");
long diff = ChronoUnit.MONTHS.between(pointInTime, today);
Assertions.assertTrue(diff >= 0); // Closer boundary
Assertions.assertTrue(diff <= 3); // Farther boundary
}

@Test
public void testBeginningOfMonth() throws Exception {
LocalDate thisMonth = Period.parseRelativeDate("thisMonth");
LocalDate firstDayOfMonth = thisMonth.with(TemporalAdjusters.firstDayOfMonth());
LocalDate pointInTime = Period.parseRelativeDate("BeginningOfMonth");
Assertions.assertEquals(firstDayOfMonth, pointInTime);
}

@Test
public void testEndOfMonth() throws Exception {
LocalDate thisMonth = Period.parseRelativeDate("thisMonth");
LocalDate firstDayOfMonth = thisMonth.with(TemporalAdjusters.lastDayOfMonth());
LocalDate pointInTime = Period.parseRelativeDate("EndOfMonth");
Assertions.assertEquals(firstDayOfMonth, pointInTime);
}

@Test
public void testDaysAgo() throws Exception {
assertDaysBetween("4_DaysAgo", -4);
}

@Test
public void testPlusDays() throws Exception {
LocalDate thisMonth = Period.parseRelativeDate("thisMonth");
assertDaysBetweenFrom(thisMonth, "thisMonth_Plus_1_Day", 1);
}

@Test
public void testPlusMonths() throws Exception {
LocalDate thisMonth = Period.parseRelativeDate("thisMonth");
assertMonthsBetweenFrom(thisMonth, "thisMonth_Plus_1_Month", 1);
}

@Test
public void testMinusDays() throws Exception {
LocalDate thisMonth = Period.parseRelativeDate("thisMonth");
assertDaysBetweenFrom(thisMonth, "thisMonth_Minus_1_Day", -1);
}

@Test
public void testMinusMonths() throws Exception {
LocalDate thisMonth = Period.parseRelativeDate("thisMonth");
assertMonthsBetweenFrom(thisMonth, "thisMonth_Minus_1_Month", -1);
}

private void assertMonthsBetween(String relativeDate, long expectedMonths) {
assertTimeBetween(relativeDate, expectedMonths, ChronoUnit.MONTHS);
}

private void assertDaysBetween(String relativeDate, long expectedDays) {
assertTimeBetween(relativeDate, expectedDays, ChronoUnit.DAYS);
}

private void assertMonthsBetweenFrom(LocalDate fixedDate, String relativeDate, long expectedMonths) {
assertTimeBetweenFrom(fixedDate, relativeDate, expectedMonths, ChronoUnit.MONTHS);
}

private void assertDaysBetweenFrom(LocalDate fixedDate, String relativeDate, long expectedDays) {
assertTimeBetweenFrom(fixedDate, relativeDate, expectedDays, ChronoUnit.DAYS);
}

private void assertTimeBetween(String relativeDate, long expectedMonths, ChronoUnit timeUnit) {
LocalDate today = LocalDate.now();
assertTimeBetweenFrom(today, relativeDate, expectedMonths, timeUnit);
}

private void assertTimeBetweenFrom(LocalDate fixedDate, String relativeDate, long expectedMonths, ChronoUnit timeUnit) {
LocalDate pointInTime = Period.parseRelativeDate(relativeDate);
long diff = timeUnit.between(fixedDate, pointInTime);
Assertions.assertEquals(expectedMonths, diff);
}
}

0 comments on commit 2a1cd8f

Please sign in to comment.