Skip to content

Commit 95315e8

Browse files
Apply feedback related to sync
Signed-off-by: gabriel-farache <[email protected]>
1 parent 453e58c commit 95315e8

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed

client/deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void verifyOneOfDiscriminatorGeneration() throws java.net.URISyntaxException, Fi
104104
final CompilationUnit compilationUnit = StaticJavaParser.parse(classWithDiscriminator.orElseThrow());
105105
assertThat(compilationUnit.findFirst(ClassOrInterfaceDeclaration.class)
106106
.flatMap(first -> first.getAnnotationByClass(com.fasterxml.jackson.annotation.JsonSubTypes.class)))
107-
.isNotPresent();
107+
.isNotPresent();
108108
}
109109

110110
/**

client/integration-tests/auth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/KeycloakServiceMock.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public class KeycloakServiceMock implements QuarkusTestResourceLifecycleManager
3535

3636
public static final String AUTH_REQUEST_BODY = "grant_type=client_credentials";
3737

38-
private WireMockServer wireMockServer;
38+
private static final ThreadLocal<WireMockServer> wireMockServer = new ThreadLocal<>();
3939

4040
@Override
4141
public Map<String, String> start() {
42-
wireMockServer = new WireMockServer(options().dynamicPort());
43-
wireMockServer.start();
44-
configureFor(wireMockServer.port());
42+
wireMockServer.set(new WireMockServer(options().dynamicPort()));
43+
wireMockServer.get().start();
44+
configureFor(wireMockServer.get().port());
4545

4646
stubFor(post(KEY_CLOAK_SERVICE_TOKEN_PATH_VALUE)
4747
.withHeader(CONTENT_TYPE, equalTo(APPLICATION_FORM_URLENCODED))
@@ -52,7 +52,7 @@ public Map<String, String> start() {
5252
.withBody(getTokenResult())));
5353

5454
Map<String, String> properties = new HashMap<>();
55-
properties.put(KEY_CLOAK_SERVICE_URL, wireMockServer.baseUrl());
55+
properties.put(KEY_CLOAK_SERVICE_URL, wireMockServer.get().baseUrl());
5656
properties.put(KEY_CLOAK_SERVICE_TOKEN_PATH, KEY_CLOAK_SERVICE_TOKEN_PATH_VALUE);
5757
return properties;
5858
}
@@ -74,8 +74,9 @@ private static String getTokenResult() {
7474

7575
@Override
7676
public void stop() {
77-
if (wireMockServer != null) {
78-
wireMockServer.stop();
77+
if (wireMockServer.get() != null) {
78+
wireMockServer.get().stop();
79+
wireMockServer.remove();
7980
}
8081
}
8182
}

client/integration-tests/auth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/TokenWithCustomCredentialProviderTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class TokenWithCustomCredentialProviderTest {
2727
@ParameterizedTest
2828
@ValueSource(strings = { "service1", "service2", "service3", "service5" })
2929
void testService(String service) {
30-
Map<String, String> headers = new HashMap<>();
31-
// service token-external-service1 and token-external-service2 will receive the AUTHORIZATION_TOKEN
32-
headers.put(HttpHeaders.AUTHORIZATION, AUTHORIZATION_TOKEN);
30+
Map<String, String> headers = Map.of(HttpHeaders.AUTHORIZATION, AUTHORIZATION_TOKEN);
3331

3432
given()
3533
.headers(headers)

client/integration-tests/security/src/test/java/io/quarkiverse/openapi/generator/it/security/KeycloakServiceMock.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ public class KeycloakServiceMock implements QuarkusTestResourceLifecycleManager
3535

3636
public static final String AUTH_REQUEST_BODY = "grant_type=client_credentials";
3737

38-
private WireMockServer wireMockServer;
39-
38+
private static final ThreadLocal<WireMockServer> wireMockServer = new ThreadLocal<>();
4039
@Override
4140
public Map<String, String> start() {
42-
wireMockServer = new WireMockServer(options().dynamicPort());
43-
wireMockServer.start();
44-
configureFor(wireMockServer.port());
41+
wireMockServer.set(new WireMockServer(options().dynamicPort()));
42+
wireMockServer.get().start();
43+
configureFor(wireMockServer.get().port());
4544

4645
stubFor(post(KEY_CLOAK_SERVICE_TOKEN_PATH_VALUE)
4746
.withHeader(CONTENT_TYPE, equalTo(APPLICATION_FORM_URLENCODED))
@@ -52,7 +51,7 @@ public Map<String, String> start() {
5251
.withBody(getTokenResult())));
5352

5453
Map<String, String> properties = new HashMap<>();
55-
properties.put(KEY_CLOAK_SERVICE_URL, wireMockServer.baseUrl());
54+
properties.put(KEY_CLOAK_SERVICE_URL, wireMockServer.get().baseUrl());
5655
properties.put(KEY_CLOAK_SERVICE_TOKEN_PATH, KEY_CLOAK_SERVICE_TOKEN_PATH_VALUE);
5756
return properties;
5857
}
@@ -74,8 +73,9 @@ private static String getTokenResult() {
7473

7574
@Override
7675
public void stop() {
77-
if (wireMockServer != null) {
78-
wireMockServer.stop();
76+
if (wireMockServer.get() != null) {
77+
wireMockServer.get().stop();
78+
wireMockServer.remove();
7979
}
8080
}
8181
}

client/oidc/src/test/java/io/quarkiverse/openapi/generator/oidc/ReactiveOAuth2AuthenticationProviderTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import org.assertj.core.api.Assertions;
1717
import org.eclipse.microprofile.config.Config;
1818
import org.eclipse.microprofile.config.ConfigProvider;
19-
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext;
19+
import org.jboss.resteasy.reactive.client.impl.ClientRequestContextImpl;
20+
import org.jboss.resteasy.reactive.client.impl.RestClientRequestContext;
2021
import org.junit.jupiter.api.BeforeEach;
2122
import org.junit.jupiter.api.Test;
2223
import org.junit.jupiter.api.extension.ExtendWith;
@@ -44,7 +45,10 @@ public class ReactiveOAuth2AuthenticationProviderTest {
4445

4546
private static final String HEADER_NAME = "HEADER_NAME";
4647
@Mock
47-
private ResteasyReactiveClientRequestContext reactiveRequestContext;
48+
private ClientRequestContextImpl reactiveRequestContext;
49+
50+
@Mock
51+
private RestClientRequestContext restClientRequestContext;
4852
private MultivaluedMap<String, Object> headers;
4953

5054
private ReactiveOidcClientRequestFilterDelegate reactiveDelegate;
@@ -57,7 +61,11 @@ public class ReactiveOAuth2AuthenticationProviderTest {
5761
void setUp() {
5862
headers = new MultivaluedHashMap<>();
5963
Mockito.lenient().doReturn(headers).when(reactiveRequestContext).getHeaders();
60-
64+
Mockito.lenient().doReturn(restClientRequestContext).when(reactiveRequestContext).getRestClientRequestContext();
65+
Mockito.lenient().doAnswer(invocationOnMock -> restClientRequestContext.setSuspended(true))
66+
.when(restClientRequestContext).suspend();
67+
Mockito.lenient().doAnswer(invocationOnMock -> restClientRequestContext.setSuspended(false))
68+
.when(restClientRequestContext).resume();
6169
reactiveDelegate = Mockito.mock(ReactiveOidcClientRequestFilterDelegate.class);
6270
try {
6371
Mockito.lenient().doCallRealMethod().when(reactiveDelegate).filter(Mockito.any(ClientRequestContext.class));
@@ -87,19 +95,23 @@ static Stream<Arguments> filterWithPropagationTestValues() {
8795
}
8896

8997
@Test
90-
void filterReactive() throws IOException {
98+
void filterReactive() throws IOException, InterruptedException {
9199
filter(provider, "Bearer " + ACCESS_TOKEN);
92100
}
93101

94-
private void filter(OAuth2AuthenticationProvider provider, String expectedAuthorizationHeader) throws IOException {
102+
private void filter(OAuth2AuthenticationProvider provider, String expectedAuthorizationHeader)
103+
throws IOException, InterruptedException {
95104
provider.filter(reactiveRequestContext);
105+
while (reactiveRequestContext.getRestClientRequestContext().isSuspended()) {
106+
Thread.sleep(1000);
107+
}
96108
assertHeader(headers, HttpHeaders.AUTHORIZATION, expectedAuthorizationHeader);
97109
}
98110

99111
@ParameterizedTest
100112
@MethodSource("filterWithPropagationTestValues")
101113
void filterWithPropagation(String headerName,
102-
String expectedAuthorizationHeader) throws IOException {
114+
String expectedAuthorizationHeader) throws IOException, InterruptedException {
103115
String propagatedHeaderName;
104116
if (headerName == null) {
105117
propagatedHeaderName = propagationHeaderName(OPEN_API_FILE_SPEC_ID, AUTH_SCHEME_NAME,

0 commit comments

Comments
 (0)