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)
  • Loading branch information
holly-cummins committed Aug 1, 2023
1 parent 681c22b commit cfec5e8
Show file tree
Hide file tree
Showing 63 changed files with 2,094 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public void testFastJarFormatWorks() throws Exception {

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

DevModeTestUtils devModeTestUtils = new DevModeTestUtils();
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(() -> devModeTestUtils.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(devModeTestUtils.getHttpResponse("/hello")).isEqualTo("hello");
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public void testLegacyJarFormatWorks() throws Exception {
File output = new File(projectDir, "build/output.log");
output.createNewFile();
Process process = launch(runnerJar, output);
DevModeTestUtils devModeTestUtils = new DevModeTestUtils();

try {
//Wait until server up
dumpFileContentOnFailure(() -> {
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.isCode("/hello", 200));
.until(() -> devModeTestUtils.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(devModeTestUtils.getHttpResponse("/hello")).isEqualTo("hello");
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ public void testUberJarForMultiModule() throws Exception {

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

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(() -> devModeTestUtils.isCode("/hello", 200));
return null;
}, output, ConditionTimeoutException.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public void testFastJarFormatWorks() throws Exception {

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

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(() -> devModeTestUtils.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(devModeTestUtils.getHttpResponse("/hello")).isEqualTo("hello");
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ public void testUberJarFormatWorks() throws Exception {

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

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(() -> devModeTestUtils.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(devModeTestUtils.getHttpResponse("/hello")).isEqualTo("hello");
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public abstract class QuarkusDevGradleTestBase extends QuarkusGradleWrapperTestB
private Future<?> quarkusDev;
protected File projectDir;

protected DevModeTestUtils devModeTestUtils = new DevModeTestUtils();

@Override
protected void setupTestCommand() {
gradleNoWatchFs(false);
Expand Down Expand Up @@ -69,7 +71,7 @@ public void main() throws Exception {
// Kill all processes that were (indirectly) spawned by the current process.
List<ProcessHandle> childProcesses = DevModeTestUtils.killDescendingProcesses();

DevModeTestUtils.awaitUntilServerDown();
devModeTestUtils.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 devModeTestUtils.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 devModeTestUtils.getHttpResponse(path, false, getQuarkusDevBrokenReason(), timeout, tu);
}

private Supplier<String> getQuarkusDevBrokenReason() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class BasicJavaNativeBuildIT extends QuarkusNativeGradleITBase {

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

@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 = devModeTestUtils.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 = devModeTestUtils.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 = devModeTestUtils.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(() -> devModeTestUtils.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(() -> devModeTestUtils.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(() -> devModeTestUtils.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(() -> devModeTestUtils.getHttpResponse("/app/hello").contains(uuid));
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(1, TimeUnit.MINUTES)
.until(() -> DevModeTestUtils.getHttpResponse("/graphql/schema.graphql").contains("[Banana!]!"));
.until(() -> devModeTestUtils.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(() -> devModeTestUtils.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(() -> devModeTestUtils.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(() -> devModeTestUtils.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(() -> devModeTestUtils.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(() -> devModeTestUtils.getHttpResponse("/app/hello").contains("carambar"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
@DisableForNative
class BuildIT extends MojoTestBase {

private DevModeTestUtils devModeTestUtils = new DevModeTestUtils();

private RunningInvoker running;
private File testDir;

Expand Down Expand Up @@ -206,7 +208,7 @@ private void launch(TestContext context, String path, File testDir, String outpu
List.of())
.start();
try {
Assertions.assertEquals(expectedMessage, DevModeTestUtils.getHttpResponse(path));
Assertions.assertEquals(expectedMessage, devModeTestUtils.getHttpResponse(path));
} finally {
process.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import io.quarkus.maven.it.verifier.MavenProcessInvocationResult;
import io.quarkus.maven.it.verifier.RunningInvoker;
import io.quarkus.test.devmode.util.DevModeTestUtils;

/**
* <p>
Expand All @@ -28,7 +27,7 @@ public class CodeGenIT extends RunAndCheckMojoTestBase {
public void shouldCompileAndRunWithCodegenEnabled() throws MavenInvocationException, FileNotFoundException {
testDir = initProject("projects/proto-gen");
run(true);
assertThat(DevModeTestUtils.getHttpResponse("/hello")).isEqualTo("Hello, World!");
assertThat(devModeTestUtils.getHttpResponse("/hello")).isEqualTo("Hello, World!");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
@DisableForNative
public class CreateProjectMojoIT extends QuarkusPlatformAwareMojoTestBase {

private DevModeTestUtils devModeTestUtils = new DevModeTestUtils();

private Invoker invoker;
private RunningInvoker running;
private File testDir;
Expand Down Expand Up @@ -588,13 +590,13 @@ public void generateNewProjectAndRun() throws Exception {
mvnRunProps.setProperty("debug", "false");
running.execute(Arrays.asList("compile", "quarkus:dev"), Collections.emptyMap(), mvnRunProps);

String resp = DevModeTestUtils.getHttpResponse();
String resp = devModeTestUtils.getHttpResponse();

assertThat(resp).containsIgnoringCase("Congratulations!").containsIgnoringCase("application")
.containsIgnoringCase("org.acme")
.containsIgnoringCase("1.0.0-SNAPSHOT");

String greeting = DevModeTestUtils.getHttpResponse("/hello");
String greeting = devModeTestUtils.getHttpResponse("/hello");
assertThat(greeting).containsIgnoringCase("hello");
}

Expand Down
Loading

0 comments on commit cfec5e8

Please sign in to comment.