forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for simple @QuarkusMain case
I also slightly clarified the wording on the docs. Co-Authored-By: Ladislav Thon <ladicek@gmail.com>
- Loading branch information
1 parent
412e41a
commit f8757d6
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...sts/test-extension/tests/src/main/java/io/quarkus/it/testsupport/commandmode/CdiBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.quarkus.it.testsupport.commandmode; | ||
|
||
public interface CdiBean { | ||
String myMethod(); | ||
} |
11 changes: 11 additions & 0 deletions
11
...test-extension/tests/src/main/java/io/quarkus/it/testsupport/commandmode/DefaultBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.quarkus.it.testsupport.commandmode; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class DefaultBean implements CdiBean { | ||
@Override | ||
public String myMethod() { | ||
return "default bean"; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...sts/test-extension/tests/src/main/java/io/quarkus/it/testsupport/commandmode/MainApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.it.testsupport.commandmode; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import io.quarkus.runtime.QuarkusApplication; | ||
import io.quarkus.runtime.annotations.QuarkusMain; | ||
|
||
/* | ||
* Because this app co-exists in a module with a QuarkusIntegrationTest, it needs to not be on the default path. | ||
* Otherwise, this application is executed by the QuarkusIntegrationTest and exits early, causing test failures elsewhere. | ||
*/ | ||
@QuarkusMain(name = "test") | ||
public class MainApp implements QuarkusApplication { | ||
|
||
@Inject | ||
CdiBean myBean; | ||
|
||
@Override | ||
public int run(String... args) throws Exception { | ||
System.out.println("The bean is " + myBean.myMethod()); | ||
return 0; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...st/java/io/quarkus/it/testsupport/commandmode/QuarkusMainTestWithTestProfileTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.it.testsupport.commandmode; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import jakarta.enterprise.inject.Alternative; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import io.quarkus.test.junit.main.Launch; | ||
import io.quarkus.test.junit.main.LaunchResult; | ||
import io.quarkus.test.junit.main.QuarkusMainTest; | ||
|
||
@QuarkusMainTest | ||
@TestProfile(QuarkusMainTestWithTestProfileTestCase.MyTestProfile.class) | ||
public class QuarkusMainTestWithTestProfileTestCase { | ||
|
||
@Test | ||
@Launch(value = {}) | ||
public void testLaunchCommand(LaunchResult result) { | ||
assertThat(result.getOutput()) | ||
.contains("The bean is mocked value"); | ||
} | ||
|
||
public static class MyTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Map.of("quarkus.package.main-class", "test"); | ||
} | ||
|
||
@Override | ||
public Set<Class<?>> getEnabledAlternatives() { | ||
return Set.of(MockedCdiBean.class); | ||
} | ||
} | ||
|
||
@Alternative | ||
@Singleton | ||
public static class MockedCdiBean implements CdiBean { | ||
|
||
@Override | ||
public String myMethod() { | ||
return "mocked value"; | ||
} | ||
} | ||
} |