-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to run tests with different config profiles #9933
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
23 changes: 23 additions & 0 deletions
23
integration-tests/main/src/main/java/io/quarkus/it/rest/GreetingEndpoint.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.rest; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.jboss.resteasy.annotations.jaxrs.PathParam; | ||
|
||
@Path("/greeting") | ||
public class GreetingEndpoint { | ||
|
||
@Inject | ||
GreetingService greetingService; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Path("{name}") | ||
public String greet(@PathParam String name) { | ||
return greetingService.greet(name); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
integration-tests/main/src/main/java/io/quarkus/it/rest/GreetingService.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,10 @@ | ||
package io.quarkus.it.rest; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class GreetingService { | ||
public String greet(String greeting) { | ||
return "Hello " + greeting; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
integration-tests/main/src/test/java/io/quarkus/it/main/BonjourService.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,16 @@ | ||
package io.quarkus.it.main; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Alternative; | ||
|
||
import io.quarkus.it.rest.GreetingService; | ||
|
||
@ApplicationScoped | ||
@Alternative | ||
public class BonjourService extends GreetingService { | ||
|
||
@Override | ||
public String greet(String greeting) { | ||
return "Bonjour " + greeting; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
integration-tests/main/src/test/java/io/quarkus/it/main/GreetingNormalTestCase.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,21 @@ | ||
package io.quarkus.it.main; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
public class GreetingNormalTestCase { | ||
|
||
@Test | ||
public void included() { | ||
RestAssured.when() | ||
.get("/greeting/Stu") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Hello Stu")); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
integration-tests/main/src/test/java/io/quarkus/it/main/GreetingProfileTestCase.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,50 @@ | ||
package io.quarkus.it.main; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* Tests that QuarkusTestProfile works as expected | ||
*/ | ||
@QuarkusTest | ||
@TestProfile(GreetingProfileTestCase.MyProfile.class) | ||
public class GreetingProfileTestCase { | ||
|
||
@Test | ||
public void included() { | ||
RestAssured.when() | ||
.get("/greeting/Stu") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Bonjour Stu")); | ||
} | ||
|
||
@Test | ||
public void testPortTakesEffect() { | ||
Assertions.assertEquals(7777, RestAssured.port); | ||
} | ||
|
||
public static class MyProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Collections.singletonMap("quarkus.http.test-port", "7777"); | ||
} | ||
|
||
@Override | ||
public Set<Class<?>> getEnabledAlternatives() { | ||
return Collections.singleton(BonjourService.class); | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestProfile.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,42 @@ | ||
package io.quarkus.test.junit; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Defines a 'test profile'. Tests run under a test profile | ||
* will have different configuration options to other tests. | ||
* | ||
*/ | ||
public interface QuarkusTestProfile { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love the idea of having all per-test configuration under one class, really simplifies things both for users and for us :) |
||
|
||
/** | ||
* Returns additional config to be applied to the test. This | ||
* will override any existing config (including in application.properties), | ||
* however existing config will be merged with this (i.e. application.properties | ||
* config will still take effect, unless a specific config key has been overridden). | ||
*/ | ||
default Map<String, String> getConfigOverrides() { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
/** | ||
* Returns enabled alternatives. | ||
* | ||
* This has the same effect as setting the 'quarkus.arc.selected-alternatives' config key, | ||
* however it may be more convenient. | ||
*/ | ||
default Set<Class<?>> getEnabledAlternatives() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
/** | ||
* Allows the default config profile to be overridden. This basically just sets the quarkus.test.profile system | ||
* property before the test is run. | ||
* | ||
*/ | ||
default String getConfigProfile() { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI there is also
quarkus.arc.exclude-types
that allows you to exclude types from discovery, i.e. ignore the specified types. And it hase the same syntax as selected alternatives: https://github.com/quarkusio/quarkus/blob/master/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcConfig.java#L99-L113