Skip to content

Commit

Permalink
add test for reverse proxy configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Apr 11, 2023
1 parent 3f946b3 commit 8f59cad
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

package com.commercetools;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;

import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.defaultconfig.ApiRootBuilder;

import io.vrap.rmf.base.client.ApiHttpRequest;
import io.vrap.rmf.base.client.ApiHttpResponse;
import io.vrap.rmf.base.client.VrapHttpClient;
import io.vrap.rmf.base.client.oauth2.ClientCredentials;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class ReverseProxyTest {

static class TestClient implements VrapHttpClient {
private ApiHttpRequest request;
@Override
public CompletableFuture<ApiHttpResponse<byte[]>> execute(ApiHttpRequest request) {
this.request = request;
return CompletableFuture
.completedFuture(new ApiHttpResponse<>(200, null, "{}".getBytes(StandardCharsets.UTF_8)));
}

public ApiHttpRequest getRequest() {
return request;
}
}
@Test
public void reverseProxy() {
TestClient client = new TestClient();
ProjectApiRoot apiRoot = ApiRootBuilder.of(client)
.defaultClient(ClientCredentials.of().withClientId("").withClientSecret("").build(),
"https://auth.europe-west1.gcp.commercetools.com/oauth/token", "https://myapi.example.com/api/v1/")
.build("test");

apiRoot.carts().get().executeBlocking();

ApiHttpRequest request = client.getRequest();
Assertions.assertThat(request.getUri().toString()).isEqualTo("https://myapi.example.com/api/v1/test/carts");
}
}

0 comments on commit 8f59cad

Please sign in to comment.