|
1 | 1 | package io.javaoperatorsdk.quarkus.extension.deployment; |
2 | 2 |
|
3 | | -import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 3 | +import static io.restassured.RestAssured.given; |
| 4 | +import static org.hamcrest.Matchers.equalTo; |
| 5 | +import static org.hamcrest.Matchers.is; |
4 | 6 |
|
5 | | -import io.javaoperatorsdk.operator.api.config.ConfigurationService; |
| 7 | +import io.javaoperatorsdk.quarkus.it.TestController; |
| 8 | +import io.javaoperatorsdk.quarkus.it.TestOperatorApp; |
| 9 | +import io.javaoperatorsdk.quarkus.it.TestResource; |
6 | 10 | import io.quarkus.test.QuarkusProdModeTest; |
7 | | -import javax.inject.Inject; |
8 | 11 | import org.jboss.shrinkwrap.api.ShrinkWrap; |
9 | 12 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
10 | 13 | import org.junit.jupiter.api.Test; |
11 | 14 | import org.junit.jupiter.api.extension.RegisterExtension; |
12 | 15 |
|
| 16 | +/** |
| 17 | + * This tests creates an application based on the application code found in the {@code |
| 18 | + * operator-framework-quarkus-tests-support} module. The app is started and accessed over REST to |
| 19 | + * assess that injected values are present and what we expect. |
| 20 | + */ |
13 | 21 | public class QuarkusExtensionProcessorTest { |
14 | 22 |
|
15 | 23 | @RegisterExtension |
16 | 24 | static final QuarkusProdModeTest config = |
17 | 25 | new QuarkusProdModeTest() |
18 | 26 | .setArchiveProducer( |
19 | | - () -> ShrinkWrap.create(JavaArchive.class).addClasses(TestController.class)) |
| 27 | + () -> |
| 28 | + ShrinkWrap.create(JavaArchive.class) |
| 29 | + .addClasses(TestOperatorApp.class, TestController.class)) |
20 | 30 | .setApplicationName("basic-app") |
21 | | - .setApplicationVersion("0.1-SNAPSHOT"); |
| 31 | + .setApplicationVersion("0.1-SNAPSHOT") |
| 32 | + .setRun(true); |
22 | 33 |
|
23 | | - @Inject TestController controller; |
24 | | - @Inject ConfigurationService configurationService; |
| 34 | + @Test |
| 35 | + void controllerShouldExist() { |
| 36 | + // first check that we're not always returning true for any controller name :) |
| 37 | + given().when().get("/operator/does_not_exist").then().statusCode(200).body(is("false")); |
| 38 | + |
| 39 | + // given the name of the TestController, the app should reply true meaning that it is indeed |
| 40 | + // injected |
| 41 | + given().when().get("/operator/" + TestController.NAME).then().statusCode(200).body(is("true")); |
| 42 | + } |
25 | 43 |
|
26 | 44 | @Test |
27 | | - void test() { |
28 | | - assertNotNull(controller); |
29 | | - assertNotNull(configurationService); |
30 | | - assertNotNull(configurationService.getConfigurationFor(controller)); |
| 45 | + void configurationForControllerShouldExist() { |
| 46 | + // check that the config for the test controller can be retrieved and is conform to our |
| 47 | + // expectations |
| 48 | + final var resourceName = TestResource.class.getCanonicalName(); |
| 49 | + given() |
| 50 | + .when() |
| 51 | + .get("/operator/" + TestController.NAME + "/config") |
| 52 | + .then() |
| 53 | + .statusCode(200) |
| 54 | + .body( |
| 55 | + "customResourceClass", equalTo(resourceName), |
| 56 | + "doneableClass", equalTo(resourceName + "Doneable"), |
| 57 | + "name", equalTo(TestController.NAME), |
| 58 | + "crdName", equalTo(TestController.CRD_NAME)); |
31 | 59 | } |
32 | 60 | } |
0 commit comments