Skip to content

Commit

Permalink
fix: use new execution mode
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumelamirand committed Jun 29, 2023
1 parent ef278d8 commit 91bba78
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<gravitee-entrypoint-sse.version>3.1.0-alpha.2</gravitee-entrypoint-sse.version>
<gravitee-entrypoint-http-post.version>1.0.0-alpha.2</gravitee-entrypoint-http-post.version>
<gravitee-reactor-message.version>1.0.0-alpha.7</gravitee-reactor-message.version>
<gravitee-reactor-message.version>1.0.0-alpha.10</gravitee-reactor-message.version>

<maven-assembly-plugin.version>3.6.0</maven-assembly-plugin.version>
<!-- Property used by the publication job in CI-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import freemarker.template.TemplateException;
import io.gravitee.common.http.HttpStatusCode;
import io.gravitee.gateway.api.buffer.Buffer;
import io.gravitee.gateway.api.http.HttpHeaderNames;
import io.gravitee.gateway.api.http.HttpHeaders;
import io.gravitee.gateway.reactive.api.ExecutionFailure;
import io.gravitee.gateway.reactive.api.context.HttpExecutionContext;
import io.gravitee.gateway.reactive.api.context.MessageExecutionContext;
Expand Down Expand Up @@ -54,15 +56,15 @@ public String id() {

@Override
public Completable onRequest(HttpExecutionContext ctx) {
return ctx.request().onBody(body -> assignBodyContent(ctx, body, true));
return ctx.request().onBody(body -> assignBodyContent(ctx, ctx.request().headers(), body, true));
}

@Override
public Completable onResponse(HttpExecutionContext ctx) {
return ctx.response().onBody(body -> assignBodyContent(ctx, body, false));
return ctx.response().onBody(body -> assignBodyContent(ctx, ctx.response().headers(), body, false));
}

private Maybe<Buffer> assignBodyContent(HttpExecutionContext ctx, Maybe<Buffer> body, boolean isRequest) {
private Maybe<Buffer> assignBodyContent(HttpExecutionContext ctx, HttpHeaders httpHeaders, Maybe<Buffer> body, boolean isRequest) {
return body
.flatMap(content -> {
var writer = replaceContent(isRequest, ctx, content.toString());
Expand All @@ -76,6 +78,7 @@ private Maybe<Buffer> assignBodyContent(HttpExecutionContext ctx, Maybe<Buffer>
return Buffer.buffer(writer.toString());
})
)
.doOnSuccess(buffer -> httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, Integer.toString(buffer.length())))
.onErrorResumeNext(ioe -> {
log.debug("Unable to assign body content", ioe);
return ctx.interruptBodyWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
import static org.assertj.core.api.Assertions.assertThat;

import io.gravitee.apim.gateway.tests.sdk.annotations.DeployApi;
import io.gravitee.apim.gateway.tests.sdk.annotations.GatewayTest;
import io.gravitee.apim.gateway.tests.sdk.configuration.GatewayMode;
import io.gravitee.apim.gateway.tests.sdk.connector.fakes.MessageStorage;
import io.gravitee.common.http.MediaType;
import io.gravitee.gateway.api.http.HttpHeaderNames;
import io.reactivex.rxjava3.subscribers.TestSubscriber;
import io.vertx.core.http.HttpMethod;
import io.vertx.rxjava3.core.buffer.Buffer;
import io.vertx.rxjava3.core.http.HttpClient;
Expand All @@ -44,10 +41,9 @@
* @author Eric LELEU (eric.leleu at graviteesource.com)
* @author GraviteeSource Team
*/
public class AssignContentPolicyIntegrationTest {
public class AssignContentPolicyV4IntegrationTest {

@Nested
@GatewayTest(mode = GatewayMode.JUPITER)
@DeployApi("/apis/v4/assign-content-proxy.json")
class HttpProxy extends V4EngineTest {

Expand Down Expand Up @@ -86,7 +82,6 @@ void shouldAssignContentOnBody(HttpClient client) throws Exception {
}

@Nested
@GatewayTest(mode = GatewayMode.JUPITER)
@DeployApi("/apis/v4/assign-content-message-subscription.json")
class OnMessageResponse extends V4EngineTest {

Expand Down Expand Up @@ -118,7 +113,6 @@ void shouldAssignContentOnMessage(HttpClient client) throws Exception {
}

@Nested
@GatewayTest(mode = GatewayMode.JUPITER)
@DeployApi("/apis/v4/assign-content-message-publish.json")
class OnMessageRequest extends V4EngineTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.graviteesource.entrypoint.sse.SseEntrypointConnectorFactory;
import com.graviteesource.reactor.message.MessageApiReactorFactory;
import io.gravitee.apim.gateway.tests.sdk.AbstractPolicyTest;
import io.gravitee.apim.gateway.tests.sdk.annotations.GatewayTest;
import io.gravitee.apim.gateway.tests.sdk.connector.EndpointBuilder;
import io.gravitee.apim.gateway.tests.sdk.connector.EntrypointBuilder;
import io.gravitee.apim.gateway.tests.sdk.connector.fakes.PersistentMockEndpointConnectorFactory;
Expand All @@ -37,6 +38,7 @@
* @author Eric LELEU (eric.leleu at graviteesource.com)
* @author GraviteeSource Team
*/
@GatewayTest
public class V4EngineTest extends AbstractPolicyTest<AssignContentPolicy, AssignContentPolicyConfiguration> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.gravitee.apim.gateway.tests.sdk.annotations.DeployApi;
import io.gravitee.apim.gateway.tests.sdk.annotations.GatewayTest;
import io.gravitee.apim.gateway.tests.sdk.configuration.GatewayMode;
import io.gravitee.definition.model.ExecutionMode;
import io.gravitee.policy.assigncontent.AssignContentPolicy;
import io.gravitee.policy.assigncontent.configuration.AssignContentPolicyConfiguration;
import io.vertx.core.http.HttpMethod;
Expand All @@ -37,7 +38,7 @@
* @author Yann TAVERNIER (yann.tavernier at graviteesource.com)
* @author GraviteeSource Team
*/
@GatewayTest(mode = GatewayMode.V3)
@GatewayTest(v2ExecutionMode = ExecutionMode.V3)
@DeployApi("/apis/v3/assign-content.json")
class AssignContentPolicyV3IntegrationTest extends AbstractPolicyTest<AssignContentPolicy, AssignContentPolicyConfiguration> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.policy.v3.assigncontent;

import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static org.assertj.core.api.Assertions.assertThat;

import io.gravitee.apim.gateway.tests.sdk.AbstractPolicyTest;
import io.gravitee.apim.gateway.tests.sdk.annotations.DeployApi;
import io.gravitee.apim.gateway.tests.sdk.annotations.GatewayTest;
import io.gravitee.apim.gateway.tests.sdk.configuration.GatewayMode;
import io.gravitee.policy.assigncontent.AssignContentPolicy;
import io.gravitee.policy.assigncontent.configuration.AssignContentPolicyConfiguration;
import io.vertx.core.http.HttpMethod;
import io.vertx.rxjava3.core.http.HttpClient;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
@GatewayTest
class AssignContentPolicyV4EmulationEngineIntegrationTest extends AssignContentPolicyV3IntegrationTest {}

0 comments on commit 91bba78

Please sign in to comment.