-
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
4a5c76d
commit a2ff59a
Showing
10 changed files
with
320 additions
and
7 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
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 { | ||
|
||
/** | ||
* 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.