-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to run tests with different config profiles
- Loading branch information
1 parent
885008e
commit 0501a5d
Showing
11 changed files
with
246 additions
and
3 deletions.
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
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")); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
package io.quarkus.it.main; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.WithProfile; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* Tests that QuarkusTestProfile works as expected | ||
*/ | ||
@QuarkusTest | ||
@WithProfile(GreetingProfileTestCase.MyProfile.class) | ||
public class GreetingProfileTestCase { | ||
|
||
@Test | ||
public void included() { | ||
RestAssured.when() | ||
.get("/greeting/Stu") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Bonjour Stu")); | ||
} | ||
|
||
public static class MyProfile implements QuarkusTestProfile { | ||
|
||
@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
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
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 { | ||
|
||
/** | ||
* 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(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
test-framework/junit5/src/main/java/io/quarkus/test/junit/WithProfile.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,31 @@ | ||
package io.quarkus.test.junit; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Defines a 'test profile'. Tests run under a test profile | ||
* will have different configuration options to other tests. | ||
* | ||
* Due to the global nature of Quarkus if a previous test was | ||
* run under a different profile then Quarkus will need to be | ||
* restarted when the profile changes. Unfortunately there | ||
* is currently no way to order tests based on profile, however | ||
* this can be done manually by running tests in alphabetical | ||
* order and putting all tests with the same profile in the same | ||
* package. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface WithProfile { | ||
|
||
/** | ||
* The test profile to use. If subsequent tests use the same | ||
* profile then Quarkus will not be restarted between tests, | ||
* giving a faster execution. | ||
*/ | ||
Class<? extends QuarkusTestProfile> value(); | ||
|
||
} |