Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.eclipse.microprofile.rest.client.tck;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
Expand All @@ -28,9 +28,11 @@
import static org.testng.Assert.fail;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

import com.github.tomakehurst.wiremock.client.MappingBuilder;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.eclipse.microprofile.rest.client.tck.ext.HeaderGenerator;
import org.eclipse.microprofile.rest.client.tck.interfaces.ClientHeaderParamClient;
import org.eclipse.microprofile.rest.client.tck.providers.ReturnWithAllClientHeadersFilter;
import org.jboss.arquillian.container.test.api.Deployment;
Expand All @@ -40,12 +42,18 @@
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import javax.json.JsonObject;

public class ClientHeaderParamTest extends WiremockArquillianTest {
@Deployment
public static Archive<?> createDeployment() {
return ShrinkWrap.create(WebArchive.class, ClientHeaderParamTest.class.getSimpleName()+".war")
.addClasses(ClientHeaderParamClient.class, ReturnWithAllClientHeadersFilter.class,
WiremockArquillianTest.class);
.addClasses(
ClientHeaderParamClient.class,
ReturnWithAllClientHeadersFilter.class,
HeaderGenerator.class,
WiremockArquillianTest.class
);
}

private static ClientHeaderParamClient client(Class<?>... providers) {
Expand All @@ -66,9 +74,14 @@ private static void stub(String expectedHeaderName, String... expectedHeaderValu
String expectedIncomingHeader = Arrays.stream(expectedHeaderValue)
.collect(Collectors.joining(","));
String outputBody = expectedIncomingHeader.replace(',', '-');
MappingBuilder mappingBuilder = get(urlEqualTo("/"));

// headers can be sent either in a single line with comma-separated values o in multiple lines
// this should match both cases:
Arrays.stream(expectedHeaderValue)
.forEach(val -> mappingBuilder.withHeader(expectedHeaderName, containing(val)));
stubFor(
get(urlEqualTo("/"))
.withHeader(expectedHeaderName, equalTo(expectedIncomingHeader))
mappingBuilder
.willReturn(
aResponse().withStatus(200)
.withBody(outputBody)));
Expand Down Expand Up @@ -163,16 +176,16 @@ public void testExceptionInRequiredComputeMethodThrowsClientErrorException() {

@Test
public void testHeaderNotSentWhenExceptionThrownAndRequiredIsFalse() {
Map<String, String> headers = client(ReturnWithAllClientHeadersFilter.class)
JsonObject headers = client(ReturnWithAllClientHeadersFilter.class)
.methodOptionalMethodHeaderNotSentWhenComputeThrowsException();

assertFalse(headers.containsKey("OptionalInterfaceHeader"));
assertFalse(headers.containsKey("OptionalMethodHeader"));

//sanity check that the filter did return _some_ headers
assertEquals(headers.get("OverrideableExplicit"), "overrideableInterfaceExplicit");
assertEquals(headers.get("InterfaceHeaderComputed"), "interfaceComputed");
assertEquals(headers.get("MethodHeaderExplicit"), "SomeValue");
assertEquals(headers.getString("OverrideableExplicit"), "overrideableInterfaceExplicit");
assertEquals(headers.getString("InterfaceHeaderComputed"), "interfaceComputed");
assertEquals(headers.getString("MethodHeaderExplicit"), "SomeValue");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.testng.Assert.assertFalse;

import java.net.URI;
import java.util.Map;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.eclipse.microprofile.rest.client.tck.interfaces.ClientHeadersFactoryClient;
import org.eclipse.microprofile.rest.client.tck.ext.CustomClientHeadersFactory;
Expand All @@ -34,11 +33,15 @@
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.testng.annotations.Test;

import javax.json.JsonObject;

public class ClientHeadersFactoryTest extends Arquillian {
@Deployment
public static Archive<?> createDeployment() {
return ShrinkWrap.create(WebArchive.class, ClientHeadersFactoryTest.class.getSimpleName()+".war")
.addClasses(ClientHeadersFactoryClient.class, ReturnWithAllClientHeadersFilter.class);
.addClasses(ClientHeadersFactoryClient.class,
CustomClientHeadersFactory.class,
ReturnWithAllClientHeadersFilter.class);
}

private static ClientHeadersFactoryClient client(Class<?>... providers) {
Expand All @@ -61,7 +64,7 @@ public void testClientHeadersFactoryInvoked() {
CustomClientHeadersFactory.isOutgoingHeadersMapNull = true;
CustomClientHeadersFactory.passedInOutgoingHeaders.clear();

Map<String, String> headers = client(ReturnWithAllClientHeadersFilter.class).delete("argValue");
JsonObject headers = client(ReturnWithAllClientHeadersFilter.class).delete("argValue");

assertFalse(CustomClientHeadersFactory.isIncomingHeadersMapNull);
assertFalse(CustomClientHeadersFactory.isOutgoingHeadersMapNull);
Expand All @@ -70,9 +73,9 @@ public void testClientHeadersFactoryInvoked() {
assertEquals(CustomClientHeadersFactory.passedInOutgoingHeaders.getFirst("ArgHeader"), "argValue");


assertEquals(headers.get("IntfHeader"), "intfValueModified");
assertEquals(headers.get("MethodHeader"), "methodValueModified");
assertEquals(headers.get("ArgHeader"), "argValueModified");
assertEquals(headers.get("FactoryHeader"), "factoryValue");
assertEquals(headers.getString("IntfHeader"), "intfValueModified");
assertEquals(headers.getString("MethodHeader"), "methodValueModified");
assertEquals(headers.getString("ArgHeader"), "argValueModified");
assertEquals(headers.getString("FactoryHeader"), "factoryValue");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

package org.eclipse.microprofile.rest.client.tck.interfaces;

import java.util.Map;

import javax.json.JsonObject;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -73,7 +72,7 @@ public interface ClientHeaderParamClient {
@GET
@ClientHeaderParam(name="OptionalMethodHeader", value="{fail}", required=false)
@ClientHeaderParam(name="MethodHeaderExplicit", value="SomeValue")
Map<String, String> methodOptionalMethodHeaderNotSentWhenComputeThrowsException();
JsonObject methodOptionalMethodHeaderNotSentWhenComputeThrowsException();
Copy link
Contributor Author

@michalszynkiewicz michalszynkiewicz Feb 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RestEasy doesn't want to work with Map here, if there's a reason why Map should be supported here, I will revert this part.


@GET
@ClientHeaderParam(name="WillCauseFailure", value="{fail}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

package org.eclipse.microprofile.rest.client.tck.interfaces;

import java.util.Map;

import javax.json.JsonObject;
import javax.ws.rs.DELETE;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
Expand All @@ -35,5 +34,5 @@
public interface ClientHeadersFactoryClient {
@DELETE
@ClientHeaderParam(name="MethodHeader", value="methodValue")
Map<String, String> delete(@HeaderParam("ArgHeader") String argHeader);
JsonObject delete(@HeaderParam("ArgHeader") String argHeader);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@

package org.eclipse.microprofile.rest.client.tck.providers;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.json.Json;
import javax.json.JsonObjectBuilder;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import java.io.IOException;


public class ReturnWithAllClientHeadersFilter implements ClientRequestFilter {
Expand All @@ -37,12 +36,12 @@ public class ReturnWithAllClientHeadersFilter implements ClientRequestFilter {

@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
Map<String,String> allClientHeaders = new HashMap<>();
JsonObjectBuilder allClientHeaders = Json.createObjectBuilder();
MultivaluedMap<String,String> clientHeaders = headers.getRequestHeaders();
for (String headerName : clientHeaders.keySet()) {
allClientHeaders.put(headerName, clientHeaders.getFirst(headerName));
allClientHeaders.add(headerName, clientHeaders.getFirst(headerName));
}
clientRequestContext.abortWith(Response.ok(allClientHeaders).build());
clientRequestContext.abortWith(Response.ok(allClientHeaders.build()).build());

}
}