Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions src/e2e/java/teammates/e2e/cases/TimezoneSyncerTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package teammates.e2e.cases;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.testng.annotations.Test;

Expand All @@ -24,8 +16,7 @@
*/
public class TimezoneSyncerTest extends BaseE2ETestCase {

private static final String IANA_TIMEZONE_DATABASE_URL = "https://www.iana.org/time-zones";
private static final int DAYS_TO_UPDATE_TZ = 120;
private static final String IANA_TIMEZONE_DATABASE_VERSION_URL = "https://data.iana.org/time-zones/tzdb/version";

@Override
protected void prepareTestData() {
Expand Down Expand Up @@ -56,25 +47,12 @@ public void testAll() {
______TS("ensure the timezone databases are up-to-date");
String currentTzVersion = timezonePage.getMomentTimezoneVersion();
IanaTimezonePage ianaPage = getNewPageInstance(
new AppUrl(IANA_TIMEZONE_DATABASE_URL), IanaTimezonePage.class);
new AppUrl(IANA_TIMEZONE_DATABASE_VERSION_URL), IanaTimezonePage.class);
String latestTzVersion = ianaPage.getVersion();

if (!currentTzVersion.equals(latestTzVersion)) {
// find the release day
String releaseDateString = ianaPage.getReleaseDate();
Pattern datePattern = Pattern.compile("\\(Released (.+)\\)");
Matcher matcher = datePattern.matcher(releaseDateString);
assertTrue(matcher.find());

LocalDate releaseDate = LocalDate.parse(matcher.group(1), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
LocalDate nowDate = Instant.now().atZone(ZoneId.of(Const.DEFAULT_TIME_ZONE)).toLocalDate();

assertTrue(
releaseDate.plusDays(DAYS_TO_UPDATE_TZ).isAfter(nowDate),
"The timezone database version is not up-to-date for more than " + DAYS_TO_UPDATE_TZ + " days,"
+ " please update them according to the maintenance guide.");

}
assertEquals(latestTzVersion, currentTzVersion,
"The timezone database version is not up-to-date, "
+ "please update them according to the maintenance guide.");
}

}
19 changes: 4 additions & 15 deletions src/e2e/java/teammates/e2e/pageobjects/IanaTimezonePage.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
package teammates.e2e.pageobjects;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.By;

/**
* Page Object Model for the official IANA page for timezone database.
* Page Object Model for the official IANA timezone database version page.
*/
public class IanaTimezonePage extends AppPage {

@FindBy(id = "version")
private WebElement timezoneVersion;

@FindBy(id = "date")
private WebElement timezoneReleaseDate;

public IanaTimezonePage(Browser browser) {
super(browser);
}

@Override
protected boolean containsExpectedPageContents() {
return true;
return getVersion().matches("\\d{4}[a-z]");
}

public String getVersion() {
return timezoneVersion.getText();
}

public String getReleaseDate() {
return timezoneReleaseDate.getText();
return browser.driver.findElement(By.tagName("body")).getText().trim();
}

}
Binary file modified src/main/resources/tzdb.dat
Binary file not shown.
Loading
Loading