Skip to content

Commit

Permalink
Add tests which exercise more complex JUnit extensions (and all fail,…
Browse files Browse the repository at this point in the history
… so all disabled)

Co-Authored-By: Alexey Loubyansky <[email protected]>
  • Loading branch information
holly-cummins and aloubyansky committed Aug 8, 2023
1 parent 772d5e1 commit b850e90
Show file tree
Hide file tree
Showing 66 changed files with 2,117 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.awaitility.core.ConditionTimeoutException;
import org.junit.jupiter.api.Test;

import io.quarkus.test.devmode.util.DevModeTestUtils;
import io.quarkus.test.devmode.util.DevModeClient;

public class FastJarFormatWorksTest extends QuarkusGradleWrapperTestBase {

Expand All @@ -31,14 +31,16 @@ public void testFastJarFormatWorks() throws Exception {

File output = new File(projectDir, "build/output.log");
output.createNewFile();

DevModeClient devModeClient = new DevModeClient();
Process process = launch(jar, output);
try {
//Wait until server up
dumpFileContentOnFailure(() -> {
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.isCode("/hello", 200));
.until(() -> devModeClient.isCode("/hello", 200));
return null;
}, output, ConditionTimeoutException.class);

Expand All @@ -47,7 +49,7 @@ public void testFastJarFormatWorks() throws Exception {
assertThat(logs).contains("INFO").contains("cdi, resteasy");

// test that the application name and version are properly set
assertThat(DevModeTestUtils.getHttpResponse("/hello")).isEqualTo("hello");
assertThat(devModeClient.getHttpResponse("/hello")).isEqualTo("hello");
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.awaitility.core.ConditionTimeoutException;
import org.junit.jupiter.api.Test;

import io.quarkus.test.devmode.util.DevModeTestUtils;
import io.quarkus.test.devmode.util.DevModeClient;

public class LegacyJarFormatWorksTest extends QuarkusGradleWrapperTestBase {

Expand All @@ -31,13 +31,15 @@ public void testLegacyJarFormatWorks() throws Exception {
File output = new File(projectDir, "build/output.log");
output.createNewFile();
Process process = launch(runnerJar, output);
DevModeClient devModeClient = new DevModeClient();

try {
//Wait until server up
dumpFileContentOnFailure(() -> {
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.isCode("/hello", 200));
.until(() -> devModeClient.isCode("/hello", 200));
return null;
}, output, ConditionTimeoutException.class);

Expand All @@ -46,7 +48,7 @@ public void testLegacyJarFormatWorks() throws Exception {
assertThat(logs).contains("INFO").contains("cdi, resteasy");

// test that the application name and version are properly set
assertThat(DevModeTestUtils.getHttpResponse("/hello")).isEqualTo("hello");
assertThat(devModeClient.getHttpResponse("/hello")).isEqualTo("hello");
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.awaitility.core.ConditionTimeoutException;
import org.junit.jupiter.api.Test;

import io.quarkus.test.devmode.util.DevModeTestUtils;
import io.quarkus.test.devmode.util.DevModeClient;

public class MultiModuleUberJarTest extends QuarkusGradleWrapperTestBase {

Expand All @@ -30,14 +30,16 @@ public void testUberJarForMultiModule() throws Exception {

File output = new File(projectDir, "application/build/output.log");
output.createNewFile();
DevModeClient devModeClient = new DevModeClient();

Process process = launch(jar, output);
try {
// Wait until server up
dumpFileContentOnFailure(() -> {
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.isCode("/hello", 200));
.until(() -> devModeClient.isCode("/hello", 200));
return null;
}, output, ConditionTimeoutException.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.awaitility.core.ConditionTimeoutException;
import org.junit.jupiter.api.Test;

import io.quarkus.test.devmode.util.DevModeTestUtils;
import io.quarkus.test.devmode.util.DevModeClient;

public class MutableJarFormatBootsInDevModeTest extends QuarkusGradleWrapperTestBase {

Expand All @@ -32,14 +32,16 @@ public void testFastJarFormatWorks() throws Exception {

File output = new File(projectDir, "build/output.log");
output.createNewFile();
DevModeClient devModeClient = new DevModeClient();

Process process = launch(jar, output, Collections.singletonMap("QUARKUS_LAUNCH_DEVMODE", "true"));
try {
//Wait until server up
dumpFileContentOnFailure(() -> {
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.isCode("/hello", 200));
.until(() -> devModeClient.isCode("/hello", 200));
return null;
}, output, ConditionTimeoutException.class);

Expand All @@ -48,7 +50,7 @@ public void testFastJarFormatWorks() throws Exception {
assertThat(logs).contains("INFO").contains("cdi, resteasy");

// test that the application name and version are properly set
assertThat(DevModeTestUtils.getHttpResponse("/hello")).isEqualTo("hello");
assertThat(devModeClient.getHttpResponse("/hello")).isEqualTo("hello");
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.project.SourceType;
import io.quarkus.test.devmode.util.DevModeTestUtils;
import io.quarkus.test.devmode.util.DevModeClient;

public class QuarkusPluginFunctionalTest extends QuarkusGradleDevToolsTestBase {

Expand Down Expand Up @@ -84,7 +84,7 @@ public void canDetectClassChangeWhenBuilding() throws Exception {

final File greetingResourceFile = projectRoot.toPath().resolve("src/main/java/org/acme/foo/GreetingResource.java")
.toFile();
DevModeTestUtils.filter(greetingResourceFile, ImmutableMap.of("\"/greeting\"", "\"/test/hello\""));
DevModeClient.filter(greetingResourceFile, ImmutableMap.of("\"/greeting\"", "\"/test/hello\""));

BuildResult secondBuild = runGradleWrapper(projectRoot, "quarkusBuild");
assertThat(BuildResult.isSuccessful(secondBuild.getTasks().get(":quarkusBuild"))).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.awaitility.core.ConditionTimeoutException;
import org.junit.jupiter.api.Test;

import io.quarkus.test.devmode.util.DevModeTestUtils;
import io.quarkus.test.devmode.util.DevModeClient;

public class UberJarFormatWorksTest extends QuarkusGradleWrapperTestBase {

Expand All @@ -29,14 +29,16 @@ public void testUberJarFormatWorks() throws Exception {

File output = new File(projectDir, "build/output.log");
output.createNewFile();
DevModeClient devModeClient = new DevModeClient();

Process process = launch(jar, output);
try {
// Wait until server up
dumpFileContentOnFailure(() -> {
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.isCode("/hello", 200));
.until(() -> devModeClient.isCode("/hello", 200));
return null;
}, output, ConditionTimeoutException.class);

Expand All @@ -45,7 +47,7 @@ public void testUberJarFormatWorks() throws Exception {
assertThat(logs).contains("INFO").contains("cdi, resteasy");

// test that the application name and version are properly set
assertThat(DevModeTestUtils.getHttpResponse("/hello")).isEqualTo("hello");
assertThat(devModeClient.getHttpResponse("/hello")).isEqualTo("hello");
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

import io.quarkus.gradle.BuildResult;
import io.quarkus.gradle.QuarkusGradleWrapperTestBase;
import io.quarkus.test.devmode.util.DevModeTestUtils;
import io.quarkus.test.devmode.util.DevModeClient;

public abstract class QuarkusDevGradleTestBase extends QuarkusGradleWrapperTestBase {

private Future<?> quarkusDev;
protected File projectDir;

protected DevModeClient devModeClient = new DevModeClient();

@Override
protected void setupTestCommand() {
gradleNoWatchFs(false);
Expand Down Expand Up @@ -67,9 +69,9 @@ public void main() throws Exception {
}

// Kill all processes that were (indirectly) spawned by the current process.
List<ProcessHandle> childProcesses = DevModeTestUtils.killDescendingProcesses();
List<ProcessHandle> childProcesses = DevModeClient.killDescendingProcesses();

DevModeTestUtils.awaitUntilServerDown();
devModeClient.awaitUntilServerDown();

// sanity: forcefully terminate left-over processes
childProcesses.forEach(ProcessHandle::destroyForcibly);
Expand Down Expand Up @@ -151,15 +153,15 @@ protected void beforeQuarkusDev() throws Exception {
protected abstract void testDevMode() throws Exception;

protected String getHttpResponse() {
return DevModeTestUtils.getHttpResponse(getQuarkusDevBrokenReason());
return devModeClient.getHttpResponse(getQuarkusDevBrokenReason());
}

protected String getHttpResponse(String path) {
return getHttpResponse(path, devModeTimeoutSeconds(), TimeUnit.SECONDS);
}

protected String getHttpResponse(String path, long timeout, TimeUnit tu) {
return DevModeTestUtils.getHttpResponse(path, false, getQuarkusDevBrokenReason(), timeout, tu);
return devModeClient.getHttpResponse(path, false, getQuarkusDevBrokenReason(), timeout, tu);
}

private Supplier<String> getQuarkusDevBrokenReason() {
Expand All @@ -172,7 +174,7 @@ protected void replace(String srcFile, Map<String, String> tokens) {
final File source = new File(getProjectDir(), srcFile);
assertThat(source).exists();
try {
DevModeTestUtils.filter(source, tokens);
DevModeClient.filter(source, tokens);
} catch (IOException e) {
throw new IllegalStateException("Failed to replace tokens in " + source, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import org.junit.jupiter.api.Test;

import io.quarkus.gradle.BuildResult;
import io.quarkus.test.devmode.util.DevModeTestUtils;
import io.quarkus.test.devmode.util.DevModeClient;

public class BasicJavaNativeBuildIT extends QuarkusNativeGradleITBase {

public static final String NATIVE_IMAGE_NAME = "foo-1.0.0-SNAPSHOT-runner";
private DevModeClient devModeClient = new DevModeClient();

@Test
public void shouldBuildNativeImage() throws Exception {
Expand All @@ -33,7 +34,7 @@ public void shouldBuildNativeImage() throws Exception {
assertThat(nativeImagePath).exists();
Process nativeImageProcess = runNativeImage(nativeImagePath.toAbsolutePath().toString());
try {
final String response = DevModeTestUtils.getHttpResponse("/hello");
final String response = devModeClient.getHttpResponse("/hello");
assertThat(response)
.withFailMessage("Response %s for /hello was expected to contain the hello, but didn't", response)
.contains("hello");
Expand Down Expand Up @@ -63,7 +64,7 @@ public void shouldBuildNativeImageWithCustomName() throws Exception {
assertThat(nativeImagePath).exists();
Process nativeImageProcess = runNativeImage(nativeImagePath.toAbsolutePath().toString());
try {
final String response = DevModeTestUtils.getHttpResponse("/hello");
final String response = devModeClient.getHttpResponse("/hello");
assertThat(response)
.withFailMessage("Response %s for /hello was expected to contain the hello, but didn't", response)
.contains("hello");
Expand Down Expand Up @@ -93,7 +94,7 @@ public void shouldBuildNativeImageWithCustomNameWithoutSuffix() throws Exception
assertThat(nativeImagePath).exists();
Process nativeImageProcess = runNativeImage(nativeImagePath.toAbsolutePath().toString());
try {
final String response = DevModeTestUtils.getHttpResponse("/hello");
final String response = devModeClient.getHttpResponse("/hello");
assertThat(response)
.withFailMessage("Response %s for /hello was expected to contain the hello, but didn't", response)
.contains("hello");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.jupiter.api.Test;

import io.quarkus.maven.it.RunAndCheckMojoTestBase;
import io.quarkus.test.devmode.util.DevModeTestUtils;

public class KotlinDevModeIT extends RunAndCheckMojoTestBase {

Expand All @@ -30,7 +29,7 @@ public void testThatTheApplicationIsReloadedOnKotlinChange() throws MavenInvocat
// Wait until we get "uuid"
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains(uuid));
.atMost(1, TimeUnit.MINUTES).until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));

await()
.pollDelay(1, TimeUnit.SECONDS)
Expand All @@ -42,7 +41,7 @@ public void testThatTheApplicationIsReloadedOnKotlinChange() throws MavenInvocat
// Wait until we get "carambar"
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("carambar"));
.atMost(1, TimeUnit.MINUTES).until(() -> devModeClient.getHttpResponse("/app/hello").contains("carambar"));

File greetingService = new File(testDir, "src/main/kotlin/org/acme/GreetingService.kt");
String newUuid = UUID.randomUUID().toString();
Expand All @@ -51,7 +50,7 @@ public void testThatTheApplicationIsReloadedOnKotlinChange() throws MavenInvocat
// Wait until we get "newUuid"
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello/bean").contains(newUuid));
.atMost(1, TimeUnit.MINUTES).until(() -> devModeClient.getHttpResponse("/app/hello/bean").contains(newUuid));
}

@Test
Expand All @@ -68,11 +67,11 @@ public void testThatTheApplicationIsReloadedOnKotlinChangeWithCustomCompilerArgs
// Wait until we get "uuid"
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains(uuid));
.atMost(1, TimeUnit.MINUTES).until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.getHttpResponse("/graphql/schema.graphql").contains("[Banana!]!"));
.until(() -> devModeClient.getHttpResponse("/graphql/schema.graphql").contains("[Banana!]!"));
}

@Test
Expand All @@ -94,7 +93,7 @@ public void testExternalKotlinReloadableArtifacts() throws Exception {
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.getHttpResponse("/hello").contains("Hello"));
.until(() -> devModeClient.getHttpResponse("/hello").contains("Hello"));

final File greetingKotlin = externalJarDir.toPath().resolve("src").resolve("main")
.resolve("kotlin").resolve("org").resolve("acme").resolve("lib")
Expand All @@ -117,7 +116,7 @@ public void testExternalKotlinReloadableArtifacts() throws Exception {
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.getHttpResponse("/hello").contains("Bonjour"));
.until(() -> devModeClient.getHttpResponse("/hello").contains("Bonjour"));

// Change bonjour() method content in Greeting.kt
filter(greetingKotlin, Map.of("Bonjour", "Bonjour!"));
Expand All @@ -129,6 +128,6 @@ public void testExternalKotlinReloadableArtifacts() throws Exception {
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.getHttpResponse("/hello").contains("BONJOUR!"));
.until(() -> devModeClient.getHttpResponse("/hello").contains("BONJOUR!"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.jupiter.api.Test;

import io.quarkus.maven.it.RunAndCheckWithAgentMojoTestBase;
import io.quarkus.test.devmode.util.DevModeTestUtils;

public class KotlinRemoteDevModeIT extends RunAndCheckWithAgentMojoTestBase {

Expand All @@ -31,7 +30,7 @@ public void testThatTheApplicationIsReloadedOnKotlinChange()
// Wait until we get "uuid"
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(3, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains(uuid));
.atMost(3, TimeUnit.MINUTES).until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));

await()
.pollDelay(1, TimeUnit.SECONDS)
Expand All @@ -43,6 +42,6 @@ public void testThatTheApplicationIsReloadedOnKotlinChange()
// Wait until we get "carambar"
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(3, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("carambar"));
.atMost(3, TimeUnit.MINUTES).until(() -> devModeClient.getHttpResponse("/app/hello").contains("carambar"));
}
}
Loading

0 comments on commit b850e90

Please sign in to comment.