Skip to content

Commit

Permalink
Add integration test for Calendar building.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerboaa committed Nov 14, 2023
1 parent f0fd875 commit dc8a50d
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
39 changes: 39 additions & 0 deletions apps/calendars/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>calendars</groupId>
<artifactId>calendars</artifactId>
<version>1</version>

<name>calendars</name>

<parent>
<groupId>org.graalvm.tests.integration</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<properties>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
</properties>

<build>
<finalName>calendars</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<manifest>
<mainClass>calendar.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
48 changes: 48 additions & 0 deletions apps/calendars/src/main/java/calendar/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2023, Red Hat Inc. All rights reserved.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package calendar;

import java.util.Calendar;
import java.util.Locale;

/**
* @author Severin Gehwolf <[email protected]>
*/
public class Main {

private static void doCalTest(String type) {
Calendar cal = new Calendar.Builder()
.setCalendarType(type)
.setFields(Calendar.YEAR, 1, Calendar.DAY_OF_YEAR, 1)
.build();
int year = cal.get(Calendar.YEAR);
String t = cal.getCalendarType();
int dayOfYear = cal.get(Calendar.DAY_OF_YEAR);
System.out.printf("Year: %d, dayOfYear: %d, type: %s%n", year, dayOfYear, t);
}

public static void main(String[] args) {
Locale.setDefault(Locale.US); // Don't rely on the default locale of the system.
String[] types = new String[] { "japanese", "buddhist", "gregory" };
for (String t : types) {
doCalTest(t);
}
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<module>apps/debug-symbols-smoke</module>
<module>apps/quarkus-spöklik-encoding</module>
<module>apps/quarkus-vertx</module>
<module>apps/calendars</module>
</modules>
</profile>
</profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,46 @@ public void timezonesBakedIn(TestInfo testInfo) throws IOException, InterruptedE
cleanup(process, cn, mn, report, app, processLog);
}
}

@Test
@Tag("calendars")
@IfMandrelVersion(min = "22.3.5") // The fix for this test is in 22.3.5 and better
public void calendarsBakedIn(TestInfo testInfo) throws IOException, InterruptedException {
final Apps app = Apps.CALENDARS;
LOGGER.info("Testing app: " + app);
Process process = null;
File processLog = null;
final StringBuilder report = new StringBuilder();
final File appDir = Path.of(BASE_DIR, app.dir).toFile();
final String cn = testInfo.getTestClass().get().getCanonicalName();
final String mn = testInfo.getTestMethod().get().getName();
try {
// Cleanup
cleanTarget(app);
Files.createDirectories(Paths.get(appDir.getAbsolutePath() + File.separator + "logs"));

// Build
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();

builderRoutine(app, report, cn, mn, appDir, processLog);

LOGGER.info("Running...");
List<String> cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]);
process = runCommand(cmd, appDir, processLog, app);
assertNotNull(process, "The test application failed to run. Check " + getLogsDir(cn, mn) + File.separator + processLog.getName());
process.waitFor(5, TimeUnit.SECONDS);
Logs.appendln(report, appDir.getAbsolutePath());
Logs.appendlnSection(report, String.join(" ", cmd));

final Pattern p = Pattern.compile(".*Year: (?:1|1086), dayOfYear: 1, type: (?:japanese|buddhist|gregory).*");
assertTrue(searchLogLines(p, processLog, Charset.defaultCharset()), "Expected pattern " + p.toString() + " was not found in the log.");

processStopper(process, false);
Logs.checkLog(cn, mn, app, processLog);
} finally {
cleanup(process, cn, mn, report, app, processLog);
}
}

@Test
@Tag("jdk-17")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public enum Apps {
WhitelistLogLines.NONE,
BuildAndRunCmds.TIMEZONES,
ContainerNames.NONE),
CALENDARS("apps" + File.separator + "calendars",
URLContent.NONE,
WhitelistLogLines.NONE,
BuildAndRunCmds.CALENDARS,
ContainerNames.NONE),
RECORDANNOTATIONS("apps" + File.separator + "recordannotations",
URLContent.NONE,
WhitelistLogLines.NONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public enum BuildAndRunCmds {
new String[]{"native-image", "-J-Duser.country=CA", "-J-Duser.language=fr", "-jar", "target/timezones.jar", "target/timezones"},
new String[]{IS_THIS_WINDOWS ? "target\\timezones.exe" : "./target/timezones"}
}),
CALENDARS(new String[][]{
new String[]{"mvn", "package"},
new String[]{"native-image", "--link-at-build-time=calendar.Main", "-jar", "target/calendars.jar", "target/calendars"},
new String[]{IS_THIS_WINDOWS ? "target\\calendars.exe" : "./target/calendars"}
}),
RECORDANNOTATIONS(new String[][]{
new String[]{"mvn", "package"},
new String[]{"native-image", "--no-fallback", "-jar", "target/recordannotations.jar", "target/recordannotations"},
Expand Down

0 comments on commit dc8a50d

Please sign in to comment.