Skip to content

Commit 0b55bbe

Browse files
author
Auri Munoz
committed
Add all tests cases
1 parent 1ef016b commit 0b55bbe

File tree

10 files changed

+232
-28
lines changed

10 files changed

+232
-28
lines changed

extensions/smallrye-stork/deployment/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
<groupId>io.quarkus</groupId>
3030
<artifactId>quarkus-vertx-deployment</artifactId>
3131
</dependency>
32+
<dependency>
33+
<groupId>io.quarkus</groupId>
34+
<artifactId>quarkus-junit5-internal</artifactId>
35+
<scope>test</scope>
36+
</dependency>
3237
</dependencies>
3338

3439
<build>

extensions/smallrye-stork/deployment/src/main/java/io/quarkus/stork/deployment/SmallRyeStorkProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ void checkStorkConsulRegistrar(BuildProducer<StorkRegistrationBuildItem> registr
125125
private static String getDefaultHealthCheckPath(Capabilities capabilities, Config quarkusConfig) {
126126
String smallryeHealthCheckDefaultPath = "";
127127
if (capabilities.isPresent(Capability.SMALLRYE_HEALTH)) {
128+
LOGGER.info("Using Smallrye Health Check defaults");
128129
smallryeHealthCheckDefaultPath = quarkusConfig.getConfigValue("quarkus.management.root-path").getValue() + "/"
129130
+ quarkusConfig.getConfigValue("quarkus.smallrye-health.root-path").getValue() + "/"
130131
+ quarkusConfig.getConfigValue("quarkus.smallrye-health.liveness-path").getValue();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.quarkus.stork;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import java.util.logging.Level;
8+
import java.util.logging.LogRecord;
9+
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
import io.quarkus.builder.Version;
14+
import io.quarkus.maven.dependency.Dependency;
15+
import io.quarkus.test.QuarkusUnitTest;
16+
17+
public class HealthExtensionCheckTest {
18+
@RegisterExtension
19+
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
20+
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.INFO.intValue())
21+
.setForcedDependencies(
22+
Arrays.asList(
23+
Dependency.of("io.quarkus", "quarkus-smallrye-health", Version.getVersion())))
24+
.assertLogRecords(logRecords -> {
25+
List<LogRecord> deprecatedProperties = logRecords.stream()
26+
.filter(l -> l.getMessage().contains("Using Smallrye Health Check defaults"))
27+
.toList();
28+
29+
assertEquals(1, deprecatedProperties.size());
30+
});
31+
32+
@Test
33+
void shouldUseSmallryeHealthCheck() {
34+
35+
}
36+
}

extensions/smallrye-stork/runtime/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@
3939
<artifactId>junit-jupiter</artifactId>
4040
<scope>test</scope>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.assertj</groupId>
44+
<artifactId>assertj-core</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>io.quarkus</groupId>
49+
<artifactId>quarkus-junit5-internal</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.assertj</groupId>
54+
<artifactId>assertj-core</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.assertj</groupId>
58+
<artifactId>assertj-core</artifactId>
59+
</dependency>
4260
</dependencies>
4361

4462
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.quarkus.stork;
2+
3+
import static org.assertj.core.api.Fail.fail;
4+
5+
import java.util.Arrays;
6+
import java.util.logging.Level;
7+
8+
import org.assertj.core.api.Assertions;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.extension.RegisterExtension;
11+
12+
import io.quarkus.builder.Version;
13+
import io.quarkus.maven.dependency.Dependency;
14+
import io.quarkus.test.QuarkusUnitTest;
15+
16+
public class MultipleRegistrarsWithoutTypeConfigRegistrationTest {
17+
18+
@RegisterExtension
19+
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
20+
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.INFO.intValue())
21+
.setForcedDependencies(
22+
Arrays.asList(
23+
Dependency.of("io.quarkus", "quarkus-smallrye-stork", Version.getVersion()),
24+
Dependency.of("io.smallrye.stork", "stork-service-registration-consul", "2.7.3")))
25+
.overrideConfigKey("quarkus.stork.red-service.service-registrar.ip-address", "145.123.145.122")
26+
.overrideConfigKey("quarkus.stork.blue-service.service-registrar.type", "consul")
27+
.overrideConfigKey("quarkus.stork.blue-service.service-registrar.ip-address", "145.123.145.157")
28+
.assertException(throwable -> {
29+
Assertions.assertThat(throwable)
30+
.isInstanceOf(IllegalArgumentException.class)
31+
.hasMessage(
32+
"Impossible to register service. Missing required 'type' for the following services: red-service");
33+
});
34+
35+
@Test
36+
public void testBuildShouldFail() {
37+
fail("Should fail");
38+
}
39+
}

integration-tests/smallrye-stork-consul-registration/pom.xml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@
2424
<groupId>io.smallrye.stork</groupId>
2525
<artifactId>stork-service-registration-consul</artifactId>
2626
</dependency>
27+
<dependency>
28+
<groupId>io.quarkus</groupId>
29+
<artifactId>quarkus-smallrye-health</artifactId>
30+
</dependency>
2731
<dependency>
2832
<groupId>io.quarkus</groupId>
2933
<artifactId>quarkus-junit5</artifactId>
3034
<scope>test</scope>
3135
</dependency>
32-
<!-- <dependency>-->
33-
<!-- <groupId>io.quarkus</groupId>-->
34-
<!-- <artifactId>quarkus-junit5-internal</artifactId>-->
35-
<!-- <scope>test</scope>-->
36-
<!-- </dependency>-->
36+
<dependency>
37+
<groupId>io.quarkus</groupId>
38+
<artifactId>quarkus-junit5-internal</artifactId>
39+
<scope>test</scope>
40+
</dependency>
3741
<dependency>
3842
<groupId>org.assertj</groupId>
3943
<artifactId>assertj-core</artifactId>
@@ -79,6 +83,20 @@
7983
</exclusion>
8084
</exclusions>
8185
</dependency>
86+
<dependency>
87+
<groupId>io.quarkus</groupId>
88+
<artifactId>quarkus-smallrye-health-deployment</artifactId>
89+
<version>${project.version}</version>
90+
<type>pom</type>
91+
<scope>test</scope>
92+
<exclusions>
93+
<exclusion>
94+
<groupId>*</groupId>
95+
<artifactId>*</artifactId>
96+
</exclusion>
97+
</exclusions>
98+
</dependency>
99+
82100
</dependencies>
83101

84102
<build>

integration-tests/smallrye-stork-consul-registration/src/test/java/org/acme/MinimalExplicitConfigRegistrationTest.java renamed to integration-tests/smallrye-stork-consul-registration/src/test/java/org/acme/CustomExplicitConfigRegistrationTest.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,11 @@
1818
*/
1919

2020
@QuarkusTest
21-
@TestProfile(MinimalExplicitConfigRegistrationTest.MinimalExplicitConfigProfile.class)
21+
@TestProfile(CustomExplicitConfigRegistrationTest.CustomExplicitConfigProfile.class)
2222
@QuarkusTestResource(ConsulContainerWithFixedPortsTestResource.class)
23-
public class MinimalExplicitConfigRegistrationTest {
23+
public class CustomExplicitConfigRegistrationTest {
2424

25-
// @Inject
26-
// @ConfigProperty(name = "consul.host")
27-
// String consulHost;
28-
//
29-
// @Inject
30-
// @ConfigProperty(name = "consul.port")
31-
// String consulPort;
32-
33-
public static class MinimalExplicitConfigProfile implements QuarkusTestProfile {
25+
public static class CustomExplicitConfigProfile implements QuarkusTestProfile {
3426
@Override
3527
public String getConfigProfile() {
3628
return "minimal";
@@ -39,23 +31,20 @@ public String getConfigProfile() {
3931
@Override
4032
public Map<String, String> getConfigOverrides() {
4133
return Map.of(
42-
"quarkus.stork.my-service.service-registrar.ip-address", "145.123.145.145");
34+
"quarkus.stork.my-service.service-registrar.ip-address", "145.123.145.145",
35+
"quarkus.stork.my-service.service-registrar.port", "9090");
4336
}
4437

4538
}
4639

4740
@Test
4841
public void test() {
49-
// String consulUrl = "http://" + consulHost + ":" + consulPort;
50-
// RestAssured.get(consulUrl + "/v1/agent/service/my-service").then()
51-
// .statusCode(200)
52-
// .body(containsString("\"Service\": \"my-service\""));
53-
5442
RestAssured.get("http://localhost:8500/v1/agent/service/my-service")
5543
.then()
5644
.statusCode(200)
5745
.body(containsString("\"Service\": \"my-service\""),
58-
containsString("\"145.123.145.145\""));
46+
containsString("\"Port\": 9090"),
47+
containsString("\"Address\": \"145.123.145.145\""));
5948

6049
}
6150

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.acme;
2+
3+
import java.util.Map;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import io.quarkus.test.common.QuarkusTestResource;
8+
import io.quarkus.test.junit.QuarkusTest;
9+
import io.quarkus.test.junit.QuarkusTestProfile;
10+
import io.quarkus.test.junit.TestProfile;
11+
import io.restassured.RestAssured;
12+
13+
/**
14+
* A configuration block is defined for a single service (see Map returned by ConsulTestResource), but without the need to
15+
* indicate the registrar type.
16+
*/
17+
18+
@QuarkusTest
19+
@TestProfile(DisabledRegistrationTest.DisabledRegistrationConfigProfile.class)
20+
@QuarkusTestResource(ConsulContainerWithFixedPortsTestResource.class)
21+
public class DisabledRegistrationTest {
22+
23+
public static class DisabledRegistrationConfigProfile implements QuarkusTestProfile {
24+
@Override
25+
public String getConfigProfile() {
26+
return "minimal";
27+
}
28+
29+
@Override
30+
public Map<String, String> getConfigOverrides() {
31+
return Map.of(
32+
"quarkus.stork.my-service.service-registrar.enabled", "false");
33+
}
34+
35+
}
36+
37+
@Test
38+
public void test() {
39+
RestAssured.get("http://localhost:8500/v1/agent/service/my-service")
40+
.then()
41+
.statusCode(404);
42+
43+
}
44+
45+
}

integration-tests/smallrye-stork-consul-registration/src/test/java/org/acme/ImplicitConfigRegistrationTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.hamcrest.CoreMatchers.containsString;
44

5-
import org.junit.Before;
65
import org.junit.jupiter.api.Test;
76

87
import io.quarkus.test.common.QuarkusTestResource;
@@ -23,10 +22,6 @@ public String getConfigProfile() {
2322
}
2423
}
2524

26-
@Before
27-
public void before() {
28-
}
29-
3025
@Test
3126
public void test() {
3227
RestAssured.get("http://localhost:8500/v1/agent/service/quarkus-integration-test-smallrye-stork-consul-registration")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.acme;
2+
3+
import static org.hamcrest.CoreMatchers.containsString;
4+
5+
import java.util.Map;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
import io.quarkus.test.common.QuarkusTestResource;
10+
import io.quarkus.test.junit.QuarkusTest;
11+
import io.quarkus.test.junit.QuarkusTestProfile;
12+
import io.quarkus.test.junit.TestProfile;
13+
import io.restassured.RestAssured;
14+
15+
/**
16+
* A configuration block is defined for a single service (see Map returned by ConsulTestResource), but without the need to
17+
* indicate the registrar type.
18+
*/
19+
20+
@QuarkusTest
21+
@TestProfile(MultipleRegistrarsConfigRegistrationTest.MinimalExplicitConfigProfile.class)
22+
@QuarkusTestResource(ConsulContainerWithFixedPortsTestResource.class)
23+
public class MultipleRegistrarsConfigRegistrationTest {
24+
25+
public static class MinimalExplicitConfigProfile implements QuarkusTestProfile {
26+
@Override
27+
public String getConfigProfile() {
28+
return "minimal";
29+
}
30+
31+
@Override
32+
public Map<String, String> getConfigOverrides() {
33+
return Map.of(
34+
"quarkus.stork.red-service.service-registrar.type", "consul",
35+
"quarkus.stork.red-service.service-registrar.ip-address", "145.123.145.145",
36+
"quarkus.stork.blue-service.service-registrar.type", "consul",
37+
"quarkus.stork.blue-service.service-registrar.ip-address", "145.123.145.157");
38+
}
39+
40+
}
41+
42+
@Test
43+
public void test() {
44+
RestAssured.get("http://localhost:8500/v1/agent/service/red-service")
45+
.then()
46+
.statusCode(200)
47+
.body(containsString("\"Service\": \"red-service\""),
48+
containsString("\"145.123.145.145\""));
49+
50+
RestAssured.get("http://localhost:8500/v1/agent/service/blue-service")
51+
.then()
52+
.statusCode(200)
53+
.body(containsString("\"Service\": \"blue-service\""),
54+
containsString("\"145.123.145.157\""));
55+
56+
}
57+
58+
}

0 commit comments

Comments
 (0)