Skip to content

Commit

Permalink
remove mapper from constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
torbjokv committed Oct 30, 2024
1 parent a873fd9 commit 6cd6b23
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public abstract class ApiGatewayHandler<I, O> extends RestRequestHandler<I, O> {
private boolean isBase64Encoded;

public ApiGatewayHandler(Class<I> iclass) {
this(iclass, new Environment(), defaultRestObjectMapper, HttpClient.newBuilder().build());
this(iclass, new Environment(), HttpClient.newBuilder().build());
}

public ApiGatewayHandler(Class<I> iclass, Environment environment, ObjectMapper objectMapper, HttpClient httpClient) {
super(iclass, environment, objectMapper, httpClient);
public ApiGatewayHandler(Class<I> iclass, Environment environment, HttpClient httpClient) {
super(iclass, environment, defaultRestObjectMapper, httpClient);
this.additionalSuccessHeadersSupplier = Collections::emptyMap;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package nva.commons.apigateway;

import static nva.commons.apigateway.RestConfig.defaultRestObjectMapper;
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.http.HttpClient;
import nva.commons.apigateway.exceptions.ApiGatewayException;
import nva.commons.core.Environment;
Expand All @@ -20,12 +18,12 @@ public abstract class ApiGatewayProxyHandler<I, O> extends ApiGatewayHandler<I,

@JacocoGenerated
protected ApiGatewayProxyHandler(Class<I> iclass) {
this(iclass, new Environment(), defaultRestObjectMapper, HttpClient.newBuilder().build());
this(iclass, new Environment(), HttpClient.newBuilder().build());
}

@JacocoGenerated
protected ApiGatewayProxyHandler(Class<I> iclass, Environment environment, ObjectMapper objectMapper, HttpClient httpClient) {
super(iclass, environment, objectMapper, httpClient);
protected ApiGatewayProxyHandler(Class<I> iclass, Environment environment, HttpClient httpClient) {
super(iclass, environment, httpClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nva.commons.apigateway;

import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.http.HttpClient;
import java.time.Duration;
import nva.commons.apigateway.exceptions.BadRequestException;
Expand Down Expand Up @@ -30,9 +29,8 @@ public ApiS3GatewayHandler(Class<I> iclass,
S3Client s3client,
S3Presigner s3Presigner,
Environment environment,
ObjectMapper objectMapper,
HttpClient httpClient) {
super(iclass, s3Presigner, environment, objectMapper, httpClient);
super(iclass, s3Presigner, environment, httpClient);
this.s3client = s3client;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nva.commons.apigateway;

import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.HttpURLConnection;
import java.net.http.HttpClient;
import java.time.Duration;
Expand Down Expand Up @@ -32,9 +31,8 @@ public ApiS3PresignerGatewayHandler(Class<I> iclass, S3Presigner s3Presigner) {
public ApiS3PresignerGatewayHandler(Class<I> iclass,
S3Presigner s3Presigner,
Environment environment,
ObjectMapper objectMapper,
HttpClient httpClient) {
super(iclass, environment, objectMapper, httpClient);
super(iclass, environment, httpClient);
this.s3presigner = s3Presigner;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
Expand Down Expand Up @@ -104,7 +99,7 @@ public void setup() {
httpClient = mock(HttpClient.class);
environment = mock(Environment.class);
when(environment.readEnv("ALLOWED_ORIGIN")).thenReturn("*");
handler = new Handler(defaultRestObjectMapper, environment, httpClient);
handler = new Handler(environment, httpClient);
}

@Test
Expand Down Expand Up @@ -397,16 +392,6 @@ void shouldReturnContentTypeMatchingSupportedMediaTypeWhenSupportedMediaTypeIsRe
assertThat(response.getHeaders().get(CONTENT_TYPE), is(equalTo(mediaType)));
}

@Test
void handlerSerializesBodyWithNonDefaultSerializationWhenDefaultSerializerIsOverridden() throws IOException {
ObjectMapper spiedMapper = spy(defaultRestObjectMapper);
var handler = new Handler(spiedMapper, environment, httpClient);
var inputStream = requestWithHeaders();
var outputStream = outputStream();
handler.handleRequest(inputStream, outputStream, context);
verify(spiedMapper, atLeast(1)).writeValueAsString(any());
}

@Test
void handlerSerializesWithIsBase64Encoded() throws IOException {
var output = outputStream();
Expand Down Expand Up @@ -508,7 +493,7 @@ void shouldEchoAllowedOriginWhenEnvironmentContainsOrigin() throws IOException {
}

private RawStringResponseHandler getRawStringResponseHandler() {
return new RawStringResponseHandler(dtoObjectMapper, environment, httpClient);
return new RawStringResponseHandler(environment, httpClient);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nva.commons.apigateway;

import static nva.commons.apigateway.ApiGatewayHandler.ALLOWED_ORIGIN_ENV;
import static nva.commons.apigateway.RestConfig.defaultRestObjectMapper;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
Expand Down Expand Up @@ -81,7 +80,7 @@ private class VoidHandler extends ApiGatewayHandler<Void, String> {
public static final String SAMPLE_STRING = "sampleString";

public VoidHandler(Environment environment, HttpClient httpClient) {
super(Void.class, environment, defaultRestObjectMapper, httpClient);
super(Void.class, environment, httpClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static nva.commons.apigateway.RequestInfoConstants.PROXY_TAG;
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.net.HttpHeaders;
import java.net.HttpURLConnection;
import java.net.http.HttpClient;
Expand All @@ -26,11 +25,9 @@ public Handler() {

/**
* Constructor that overrides default serialization.
*
* @param mapper Object Mapper
*/
public Handler(ObjectMapper mapper,Environment environment, HttpClient httpClient) {
super(RequestBody.class, environment, mapper, httpClient);
public Handler(Environment environment, HttpClient httpClient) {
super(RequestBody.class, environment, httpClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static nva.commons.apigateway.RequestInfoConstants.PROXY_TAG;
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.net.HttpHeaders;
import java.net.http.HttpClient;
import java.util.Collections;
Expand All @@ -27,11 +26,9 @@ public ProxyHandler() {

/**
* Constructor that overrides default serialization.
*
* @param mapper Object Mapper
*/
public ProxyHandler(ObjectMapper mapper, Environment environment, HttpClient httpClient) {
super(RequestBody.class, environment, mapper, httpClient);
public ProxyHandler(Environment environment, HttpClient httpClient) {
super(RequestBody.class, environment, httpClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ public RawStringResponseHandler() {

/**
* Constructor that overrides default serialization.
*
* @param mapper Object Mapper
*/
public RawStringResponseHandler(ObjectMapper mapper, Environment environment, HttpClient httpClient) {
super(RequestBody.class, environment, mapper, httpClient);
public RawStringResponseHandler(Environment environment, HttpClient httpClient) {
super(RequestBody.class, environment, httpClient);
}

@Override
Expand Down

0 comments on commit 6cd6b23

Please sign in to comment.