Skip to content

Commit

Permalink
chore: bump to rxJava
Browse files Browse the repository at this point in the history
BREAKING CHANGE: rxJava3 required
  • Loading branch information
jhaeyaert authored and marcambier committed Oct 20, 2022
1 parent ea8be1e commit bae3eff
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ workflows:
setup_release:
when:
matches:
pattern: "^[0-9]+\\.[0-9]+\\.[0-9]+$"
pattern: "/^[0-9]+\\.[0-9]+\\.[0-9]+(-(alpha|beta|rc)\\.[0-9]+)?$/"
value: << pipeline.git.tag >>
jobs:
- gravitee/setup_plugin-release-config:
Expand All @@ -32,4 +32,4 @@ workflows:
- /.*/
tags:
only:
- /^[0-9]+\.[0-9]+\.[0-9]+$/
- /^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.[0-9]+)?$/
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>io.gravitee.policy</groupId>
<artifactId>gravitee-policy-apikey</artifactId>
<version>2.9.0</version>
<version>3.0.0-alpha.1</version>

<name>Gravitee.io APIM - Policy - ApiKey</name>
<description>Description of the ApiKey Gravitee Policy</description>
Expand All @@ -34,8 +34,8 @@
</parent>

<properties>
<gravitee-bom.version>2.6</gravitee-bom.version>
<gravitee-gateway-api.version>1.44.0</gravitee-gateway-api.version>
<gravitee-bom.version>2.7</gravitee-bom.version>
<gravitee-gateway-api.version>2.0.0-alpha.1</gravitee-gateway-api.version>
<gravitee-policy-api.version>1.11.0</gravitee-policy-api.version>
<json-schema-generator-maven-plugin.version>1.1.0</json-schema-generator-maven-plugin.version>
<json-schema-generator-maven-plugin.outputDirectory>${project.build.directory}/schemas
Expand All @@ -48,9 +48,9 @@
<publish-folder-path>graviteeio-apim/plugins/policies</publish-folder-path>
<gravitee-apim-gateway-tests-sdk.version>3.20.0-SNAPSHOT</gravitee-apim-gateway-tests-sdk.version>
<gravitee-node-api.version>1.21.0</gravitee-node-api.version>
<gravitee-node.version>1.24.2</gravitee-node.version>
<gravitee-common.version>1.27.0</gravitee-common.version>
<gravitee-expression-language.version>1.11.0</gravitee-expression-language.version>
<gravitee-node.version>2.0.0-alpha.3</gravitee-node.version>
<gravitee-common.version>2.0.0-alpha.1</gravitee-common.version>
<gravitee-expression-language.version>2.0.0-alpha.2</gravitee-expression-language.version>
<gravitee-plugin.version>1.24.1</gravitee-plugin.version>
<gravitee-connector-api.version>1.1.0</gravitee-connector-api.version>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/gravitee/policy/apikey/ApiKeyPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import io.gravitee.gateway.jupiter.api.policy.SecurityToken;
import io.gravitee.policy.apikey.configuration.ApiKeyPolicyConfiguration;
import io.gravitee.policy.v3.apikey.ApiKeyPolicyV3;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Maybe;
import java.util.Date;
import java.util.Optional;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static io.gravitee.gateway.jupiter.api.policy.SecurityToken.TokenType.API_KEY;
import static io.vertx.core.http.HttpMethod.GET;
import static java.time.temporal.ChronoUnit.HOURS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.*;
Expand All @@ -35,10 +36,14 @@
import io.gravitee.gateway.api.service.SubscriptionService;
import io.gravitee.gateway.jupiter.api.policy.SecurityToken;
import io.gravitee.policy.apikey.configuration.ApiKeyPolicyConfiguration;
import io.reactivex.observers.TestObserver;
import io.vertx.reactivex.core.buffer.Buffer;
import io.vertx.reactivex.ext.web.client.HttpResponse;
import io.vertx.reactivex.ext.web.client.WebClient;
import io.reactivex.rxjava3.observers.TestObserver;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.RequestOptions;
import io.vertx.rxjava3.core.buffer.Buffer;
import io.vertx.rxjava3.core.http.HttpClient;
import io.vertx.rxjava3.core.http.HttpClientRequest;
import io.vertx.rxjava3.ext.web.client.HttpResponse;
import io.vertx.rxjava3.ext.web.client.WebClient;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -80,16 +85,21 @@ public void configureApi(Api api) {

@Test
@DisplayName("Should receive 401 - Unauthorized when calling without an API-Key")
void shouldGet401IfNoApiKey(WebClient client) {
void shouldGet401IfNoApiKey(HttpClient client) throws InterruptedException {
wiremock.stubFor(get("/team").willReturn(ok("response from backend")));

final TestObserver<HttpResponse<Buffer>> obs = client.get("/test").rxSend().test();

awaitTerminalEvent(obs)
.assertComplete()
.assertValue(response -> {
client
.rxRequest(GET, "/test")
.flatMap(HttpClientRequest::rxSend)
.flatMapPublisher(response -> {
assertThat(response.statusCode()).isEqualTo(401);
assertThat(response.bodyAsString()).isEqualTo("Unauthorized");
return response.toFlowable();
})
.test()
.await()
.assertComplete()
.assertValue(body -> {
assertThat(body.toString()).isEqualTo("Unauthorized");
return true;
})
.assertNoErrors();
Expand All @@ -99,21 +109,26 @@ void shouldGet401IfNoApiKey(WebClient client) {

@Test
@DisplayName("Should receive 401 - Unauthorized when calling with an API key, without subscription")
void shouldGet401IfNoSubscription(WebClient client) {
void shouldGet401IfNoSubscription(HttpClient client) throws InterruptedException {
wiremock.stubFor(get("/team").willReturn(ok("response from backend")));

final ApiKey apiKey = fakeApiKeyFromCache();

when(getBean(ApiKeyService.class).getByApiAndKey(any(), any())).thenReturn(Optional.of(apiKey));
when(getBean(SubscriptionService.class).getByApiAndSecurityToken(any(), any(), any())).thenReturn(Optional.empty());

final TestObserver<HttpResponse<Buffer>> obs = client.get("/test").putHeader("X-Gravitee-Api-Key", "apiKeyValue").rxSend().test();

awaitTerminalEvent(obs)
.assertComplete()
.assertValue(response -> {
client
.rxRequest(new RequestOptions().setMethod(GET).setURI("/test").putHeader("X-Gravitee-Api-Key", "apiKeyValue"))
.flatMap(HttpClientRequest::rxSend)
.flatMapPublisher(response -> {
assertThat(response.statusCode()).isEqualTo(401);
assertUnauthorizedResponseBody(response.bodyAsString());
return response.toFlowable();
})
.test()
.await()
.assertComplete()
.assertValue(body -> {
assertUnauthorizedResponseBody(body.toString());
return true;
})
.assertNoErrors();
Expand All @@ -123,21 +138,26 @@ void shouldGet401IfNoSubscription(WebClient client) {

@Test
@DisplayName("Should receive 401 - Unauthorized when calling with an API key, with expired subscription")
void shouldGet401IfExpiredSubscription(WebClient client) {
void shouldGet401IfExpiredSubscription(HttpClient client) throws InterruptedException {
wiremock.stubFor(get("/team").willReturn(ok("response from backend")));

final ApiKey apiKey = fakeApiKeyFromCache();

when(getBean(ApiKeyService.class).getByApiAndKey(any(), any())).thenReturn(Optional.of(apiKey));
whenSearchingSubscription(apiKey).thenReturn(Optional.of(fakeSubscriptionFromCache(true)));

final TestObserver<HttpResponse<Buffer>> obs = client.get("/test").putHeader("X-Gravitee-Api-Key", "apiKeyValue").rxSend().test();

awaitTerminalEvent(obs)
.assertComplete()
.assertValue(response -> {
client
.rxRequest(new RequestOptions().setMethod(GET).setURI("/test").putHeader("X-Gravitee-Api-Key", "apiKeyValue"))
.flatMap(HttpClientRequest::rxSend)
.flatMapPublisher(response -> {
assertThat(response.statusCode()).isEqualTo(401);
assertUnauthorizedResponseBody(response.bodyAsString());
return response.toFlowable();
})
.test()
.await()
.assertComplete()
.assertValue(body -> {
assertUnauthorizedResponseBody(body.toString());
return true;
})
.assertNoErrors();
Expand All @@ -147,21 +167,26 @@ void shouldGet401IfExpiredSubscription(WebClient client) {

@Test
@DisplayName("Should access API with API-Key header")
void shouldAccessApiWithApiKeyHeader(WebClient client) {
void shouldAccessApiWithApiKeyHeader(HttpClient client) throws InterruptedException {
wiremock.stubFor(get("/team").willReturn(ok("response from backend")));

final ApiKey apiKey = fakeApiKeyFromCache();

when(getBean(ApiKeyService.class).getByApiAndKey(any(), any())).thenReturn(Optional.of(apiKey));
whenSearchingSubscription(apiKey).thenReturn(Optional.of(fakeSubscriptionFromCache(false)));

final TestObserver<HttpResponse<Buffer>> obs = client.get("/test").putHeader("X-Gravitee-Api-Key", "apiKeyValue").rxSend().test();

awaitTerminalEvent(obs)
.assertComplete()
.assertValue(response -> {
client
.rxRequest(new RequestOptions().setMethod(GET).setURI("/test").putHeader("X-Gravitee-Api-Key", "apiKeyValue"))
.flatMap(HttpClientRequest::rxSend)
.flatMapPublisher(response -> {
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.bodyAsString()).isEqualTo("response from backend");
return response.toFlowable();
})
.test()
.await()
.assertComplete()
.assertValue(body -> {
assertThat(body.toString()).isEqualTo("response from backend");
return true;
})
.assertNoErrors();
Expand All @@ -171,21 +196,26 @@ void shouldAccessApiWithApiKeyHeader(WebClient client) {

@Test
@DisplayName("Should access API with API-Key query param")
void shouldAccessApiWithApiKeyQueryParam(WebClient client) {
void shouldAccessApiWithApiKeyQueryParam(HttpClient client) throws InterruptedException {
wiremock.stubFor(get("/team").willReturn(ok("response from backend")));

final ApiKey apiKey = fakeApiKeyFromCache();

when(getBean(ApiKeyService.class).getByApiAndKey(any(), any())).thenReturn(Optional.of(apiKey));
whenSearchingSubscription(apiKey).thenReturn(Optional.of(fakeSubscriptionFromCache(false)));

final TestObserver<HttpResponse<Buffer>> obs = client.get("/test").addQueryParam("api-key", "apiKeyValue").rxSend().test();

awaitTerminalEvent(obs)
.assertComplete()
.assertValue(response -> {
client
.rxRequest(new RequestOptions().setMethod(GET).setURI("/test?api-key=apiKeyValue"))
.flatMap(HttpClientRequest::rxSend)
.flatMapPublisher(response -> {
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.bodyAsString()).isEqualTo("response from backend");
return response.toFlowable();
})
.test()
.await()
.assertComplete()
.assertValue(body -> {
assertThat(body.toString()).isEqualTo("response from backend");
return true;
})
.assertNoErrors();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/gravitee/policy/apikey/ApiKeyPolicyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import io.gravitee.gateway.jupiter.api.context.Response;
import io.gravitee.gateway.jupiter.api.policy.SecurityToken;
import io.gravitee.policy.apikey.configuration.ApiKeyPolicyConfiguration;
import io.reactivex.Completable;
import io.reactivex.observers.TestObserver;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.observers.TestObserver;
import java.util.Date;
import java.util.List;
import java.util.Optional;
Expand Down

0 comments on commit bae3eff

Please sign in to comment.