Skip to content

Commit 07cba0d

Browse files
committed
Adjust our tests due to changes in JUnit 5 regarding inheritance
JUnit 5 changed how they handle inheritance to be more in line with what standard Java does. This change causes some issues with some of our tests as we can't leverage overriding for static fields as we did before. https://junit.org/junit5/docs/5.11.1/release-notes/#release-notes-5.11.0-junit-platform-bug-fixes
1 parent 3b5be06 commit 07cba0d

File tree

13 files changed

+972
-952
lines changed

13 files changed

+972
-952
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package io.quarkus.restclient.configuration;
2+
3+
import java.util.Set;
4+
5+
import jakarta.enterprise.inject.spi.Bean;
6+
import jakarta.enterprise.inject.spi.BeanManager;
7+
import jakarta.inject.Singleton;
8+
9+
import org.eclipse.microprofile.rest.client.inject.RestClient;
10+
import org.junit.jupiter.api.Assertions;
11+
import org.junit.jupiter.api.Test;
12+
13+
import io.quarkus.arc.Arc;
14+
15+
/**
16+
* Tests clients configured with MicroProfile-style configuration.
17+
*/
18+
abstract class AbstractRestClientsTest {
19+
20+
@RestClient
21+
EchoClientWithConfigKey clientWithConfigKey;
22+
23+
@RestClient
24+
EchoClient fullClassNameClient;
25+
26+
@Test
27+
public void clientWithConfigKeyShouldConnect() {
28+
Assertions.assertEquals("Hello", clientWithConfigKey.echo("Hello"));
29+
}
30+
31+
@Test
32+
void clientWithConfigShouldHaveSingletonScope() {
33+
verifyClientScope(EchoClientWithConfigKey.class, Singleton.class);
34+
}
35+
36+
@Test
37+
public void fullClassNameClientShouldConnect() {
38+
Assertions.assertEquals("Hello", fullClassNameClient.echo("Hello"));
39+
}
40+
41+
@Test
42+
void fullClassNameClientShouldHaveSingletonScope() {
43+
verifyClientScope(EchoClient.class, Singleton.class);
44+
}
45+
46+
static void verifyClientScope(Class clientInterface, Class expectedScope) {
47+
BeanManager beanManager = Arc.container().beanManager();
48+
Set<Bean<?>> beans = beanManager.getBeans(clientInterface, RestClient.LITERAL);
49+
Bean<?> resolvedBean = beanManager.resolve(beans);
50+
Assertions.assertEquals(expectedScope, resolvedBean.getScope());
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,18 @@
11
package io.quarkus.restclient.configuration;
22

3-
import java.util.Set;
4-
5-
import jakarta.enterprise.inject.spi.Bean;
6-
import jakarta.enterprise.inject.spi.BeanManager;
7-
import jakarta.inject.Singleton;
8-
9-
import org.eclipse.microprofile.rest.client.inject.RestClient;
10-
import org.junit.jupiter.api.Assertions;
11-
import org.junit.jupiter.api.Test;
123
import org.junit.jupiter.api.extension.RegisterExtension;
134

14-
import io.quarkus.arc.Arc;
155
import io.quarkus.test.QuarkusUnitTest;
166

177
/**
188
* Tests clients configured with MicroProfile-style configuration.
199
*/
20-
public class MPRestClientsTest {
10+
public class MPRestClientsTest extends AbstractRestClientsTest {
2111

2212
@RegisterExtension
2313
static final QuarkusUnitTest config = new QuarkusUnitTest()
2414
.withApplicationRoot((jar) -> jar
2515
.addClasses(EchoResource.class,
2616
EchoClient.class, EchoClientWithConfigKey.class, ShortNameEchoClient.class))
2717
.withConfigurationResource("mp-restclients-test-application.properties");
28-
29-
@RestClient
30-
EchoClientWithConfigKey clientWithConfigKey;
31-
32-
@RestClient
33-
EchoClient fullClassNameClient;
34-
35-
@Test
36-
public void clientWithConfigKeyShouldConnect() {
37-
Assertions.assertEquals("Hello", clientWithConfigKey.echo("Hello"));
38-
}
39-
40-
@Test
41-
void clientWithConfigShouldHaveSingletonScope() {
42-
verifyClientScope(EchoClientWithConfigKey.class, Singleton.class);
43-
}
44-
45-
@Test
46-
public void fullClassNameClientShouldConnect() {
47-
Assertions.assertEquals("Hello", fullClassNameClient.echo("Hello"));
48-
}
49-
50-
@Test
51-
void fullClassNameClientShouldHaveSingletonScope() {
52-
verifyClientScope(EchoClient.class, Singleton.class);
53-
}
54-
55-
static void verifyClientScope(Class clientInterface, Class expectedScope) {
56-
BeanManager beanManager = Arc.container().beanManager();
57-
Set<Bean<?>> beans = beanManager.getBeans(clientInterface, RestClient.LITERAL);
58-
Bean<?> resolvedBean = beanManager.resolve(beans);
59-
Assertions.assertEquals(expectedScope, resolvedBean.getScope());
60-
}
61-
6218
}

extensions/resteasy-classic/resteasy-client/deployment/src/test/java/io/quarkus/restclient/configuration/QuarkusRestClientsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Tests clients configured with Quarkus-style configuration.
1414
*/
15-
public class QuarkusRestClientsTest extends MPRestClientsTest {
15+
public class QuarkusRestClientsTest extends AbstractRestClientsTest {
1616

1717
@RegisterExtension
1818
static final QuarkusUnitTest config = new QuarkusUnitTest()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.quarkus.resteasy.reactive.jackson.deployment.test;
2+
3+
import jakarta.inject.Singleton;
4+
5+
import org.hamcrest.Matchers;
6+
import org.junit.jupiter.api.Test;
7+
8+
import com.fasterxml.jackson.annotation.JsonInclude;
9+
import com.fasterxml.jackson.databind.DeserializationFeature;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
12+
import io.quarkus.jackson.ObjectMapperCustomizer;
13+
import io.restassured.RestAssured;
14+
15+
public abstract class AbstractNonAbsentSerializationTest {
16+
17+
@Singleton
18+
public static class NonAbsentObjectMapperCustomizer implements ObjectMapperCustomizer {
19+
20+
@Override
21+
public void customize(ObjectMapper objectMapper) {
22+
objectMapper
23+
.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)
24+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
25+
.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
26+
}
27+
}
28+
29+
@Test
30+
public void testObject() {
31+
RestAssured.get("/json-include/my-object")
32+
.then()
33+
.statusCode(200)
34+
.contentType("application/json")
35+
.body("name", Matchers.equalTo("name"))
36+
.body("description", Matchers.equalTo("description"))
37+
.body("map.test", Matchers.equalTo(1))
38+
.body("strings[0]", Matchers.equalTo("test"));
39+
}
40+
41+
@Test
42+
public void testEmptyObject() {
43+
RestAssured.get("/json-include/my-object-empty")
44+
.then()
45+
.statusCode(200)
46+
.contentType("application/json")
47+
.body("name", Matchers.nullValue())
48+
.body("description", Matchers.nullValue())
49+
.body("map", Matchers.anEmptyMap())
50+
.body("strings", Matchers.hasSize(0));
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.quarkus.resteasy.reactive.jackson.deployment.test;
2+
3+
import jakarta.inject.Singleton;
4+
5+
import org.hamcrest.Matchers;
6+
import org.junit.jupiter.api.Test;
7+
8+
import com.fasterxml.jackson.annotation.JsonInclude;
9+
import com.fasterxml.jackson.databind.DeserializationFeature;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
12+
import io.quarkus.jackson.ObjectMapperCustomizer;
13+
import io.restassured.RestAssured;
14+
15+
public abstract class AbstractNonEmptySerializationTest {
16+
17+
@Singleton
18+
public static class NonEmptyObjectMapperCustomizer implements ObjectMapperCustomizer {
19+
20+
@Override
21+
public void customize(ObjectMapper objectMapper) {
22+
objectMapper
23+
.enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)
24+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
25+
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
26+
}
27+
}
28+
29+
@Test
30+
public void testObject() {
31+
RestAssured.get("/json-include/my-object")
32+
.then()
33+
.statusCode(200)
34+
.contentType("application/json")
35+
.body("name", Matchers.equalTo("name"))
36+
.body("description", Matchers.equalTo("description"))
37+
.body("map.test", Matchers.equalTo(1))
38+
.body("strings[0]", Matchers.equalTo("test"));
39+
}
40+
41+
@Test
42+
public void testEmptyObject() {
43+
RestAssured.get("/json-include/my-object-empty")
44+
.then()
45+
.statusCode(200)
46+
.contentType("application/json")
47+
.body(Matchers.is("{}"));
48+
}
49+
}

0 commit comments

Comments
 (0)