Skip to content

Commit ddc1d98

Browse files
committed
Updated ObjectMapper to shared version
1 parent 6806068 commit ddc1d98

File tree

8 files changed

+36
-51
lines changed

8 files changed

+36
-51
lines changed

src/test/java/app/component/Core.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package app.component;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.uid2.shared.util.Mapper;
35
import common.Const;
46
import common.EnvUtil;
57
import common.HttpClient;
6-
import common.Mapper;
78
import com.fasterxml.jackson.databind.JsonNode;
89

910
import java.util.HashMap;
1011
import java.util.Map;
1112

1213
public class Core extends App {
14+
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
1315
private static final String OPERATOR_API_KEY = EnvUtil.getEnv(Const.Config.Core.OPERATOR_API_KEY);
1416
private static final String OPTOUT_API_KEY = EnvUtil.getEnv(Const.Config.Core.OPTOUT_API_KEY);
1517
public static final String CORE_URL = EnvUtil.getEnv(Const.Config.Core.CORE_URL);
@@ -25,7 +27,7 @@ public Core(String host, String name) {
2527

2628
public JsonNode attest(String attestationRequest) throws Exception {
2729
String response = HttpClient.post(getBaseUrl() + "/attest", attestationRequest, OPERATOR_API_KEY);
28-
return Mapper.OBJECT_MAPPER.readTree(response);
30+
return OBJECT_MAPPER.readTree(response);
2931
}
3032

3133
public JsonNode getWithCoreApiToken(String path) throws Exception {
@@ -37,11 +39,11 @@ public JsonNode getWithCoreApiToken(String path, boolean encrypted) throws Excep
3739
if (encrypted)
3840
headers.put("Encrypted", "true");
3941
String response = HttpClient.get(getBaseUrl() + path, OPERATOR_API_KEY, headers);
40-
return Mapper.OBJECT_MAPPER.readTree(response);
42+
return OBJECT_MAPPER.readTree(response);
4143
}
4244

4345
public JsonNode getWithOptOutApiToken(String path) throws Exception {
4446
String response = HttpClient.get(getBaseUrl() + path, OPTOUT_API_KEY);
45-
return Mapper.OBJECT_MAPPER.readTree(response);
47+
return OBJECT_MAPPER.readTree(response);
4648
}
4749
}

src/test/java/app/component/Operator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package app.component;
22

33
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
45
import com.google.gson.JsonArray;
56
import com.google.gson.JsonObject;
67
import com.uid2.client.IdentityScope;
78
import com.uid2.client.*;
9+
import com.uid2.shared.util.Mapper;
810
import common.*;
911
import lombok.Getter;
1012
import okhttp3.Request;
@@ -66,6 +68,7 @@ private record V2Envelope(String envelope, byte[] nonce) {
6668
// When running via IntelliJ, environment variables are defined in the uid2-dev-workspace repo under .idea/runConfigurations.
6769
// Test data is defined in the uid2-admin repo.
6870

71+
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
6972
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
7073
private static final int TIMESTAMP_LENGTH = 8;
7174
private static final int PUBLIC_KEY_PREFIX_LENGTH = 9;
@@ -340,14 +343,14 @@ private JsonNode v2DecryptEncryptedResponse(String encryptedResponse, byte[] non
340343
cons.setAccessible(true);
341344
Uid2Helper uid2Helper = cons.newInstance(secret);
342345
String decryptedResponse = uid2Helper.decrypt(encryptedResponse, nonceInRequest);
343-
return Mapper.OBJECT_MAPPER.readTree(decryptedResponse);
346+
return OBJECT_MAPPER.readTree(decryptedResponse);
344347
}
345348

346349
private JsonNode v2DecryptResponseWithoutNonce(String response, byte[] key) throws Exception {
347350
Method decryptTokenRefreshResponseMethod = Uid2Helper.class.getDeclaredMethod("decryptTokenRefreshResponse", String.class, byte[].class);
348351
decryptTokenRefreshResponseMethod.setAccessible(true);
349352
String decryptedResponse = (String) decryptTokenRefreshResponseMethod.invoke(Uid2Helper.class, response, key);
350-
return Mapper.OBJECT_MAPPER.readTree(decryptedResponse);
353+
return OBJECT_MAPPER.readTree(decryptedResponse);
351354
}
352355

353356
private byte[] encryptGDM(byte[] b, byte[] secretBytes) throws Exception {

src/test/java/common/EnvUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.core.type.TypeReference;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.uid2.shared.util.Mapper;
57
import org.apache.commons.lang3.StringUtils;
68
import org.junit.platform.commons.logging.Logger;
79
import org.junit.platform.commons.logging.LoggerFactory;
@@ -11,6 +13,7 @@
1113

1214
public final class EnvUtil {
1315
private static final Logger LOGGER = LoggerFactory.getLogger(EnvUtil.class);
16+
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
1417
private static final Map<String, String> ARGS = new HashMap<>();
1518

1619
static {
@@ -20,7 +23,7 @@ public final class EnvUtil {
2023
if (StringUtils.isNotBlank(args)) {
2124
TypeReference<HashMap<String, String>> typeRef = new TypeReference<>() {
2225
};
23-
ARGS.putAll(Mapper.OBJECT_MAPPER.readValue(args, typeRef));
26+
ARGS.putAll(OBJECT_MAPPER.readValue(args, typeRef));
2427
}
2528
} catch (JsonProcessingException e) {
2629
LOGGER.error(e::getMessage);

src/test/java/common/HttpClient.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package common;
22

33
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.uid2.shared.util.Mapper;
6+
import lombok.Getter;
47
import okhttp3.*;
58

69
import java.util.Map;
710
import java.util.Objects;
811

912
public final class HttpClient {
13+
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
14+
1015
public static final OkHttpClient RAW_CLIENT = new OkHttpClient();
1116
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
1217

@@ -15,6 +20,7 @@ public enum HttpMethod {
1520
POST
1621
}
1722

23+
@Getter
1824
public static class HttpException extends Exception {
1925
private final HttpMethod method;
2026
private final String url;
@@ -32,28 +38,8 @@ public HttpException(HttpMethod method, String url, int code, String codeMessage
3238
this.response = response;
3339
}
3440

35-
public HttpMethod getMethod() {
36-
return method;
37-
}
38-
39-
public String getUrl() {
40-
return url;
41-
}
42-
43-
public int getCode() {
44-
return code;
45-
}
46-
47-
public String getCodeMessage() {
48-
return codeMessage;
49-
}
50-
51-
public String getResponse() {
52-
return response;
53-
}
54-
5541
public JsonNode getResponseJson() throws Exception {
56-
return Mapper.OBJECT_MAPPER.readTree(response);
42+
return OBJECT_MAPPER.readTree(response);
5743
}
5844

5945
private static String createErrorMessage(HttpMethod method, String url, int code, String message, String response) {

src/test/java/common/Mapper.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test/java/suite/operator/V2ApiOperatorPublicOnlyTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package suite.operator;
22

33
import common.HttpClient;
4-
import common.Mapper;
54
import app.component.Operator;
65
import com.fasterxml.jackson.databind.JsonNode;
7-
import com.uid2.client.DecryptionResponse;
86
import com.uid2.client.IdentityTokens;
97
import com.uid2.client.TokenRefreshResponse;
10-
import org.junit.jupiter.api.Disabled;
118
import org.junit.jupiter.api.condition.EnabledIf;
129
import org.junit.jupiter.params.ParameterizedTest;
1310
import org.junit.jupiter.params.provider.MethodSource;

src/test/java/suite/operator/V2ApiOperatorTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package suite.operator;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.uid2.shared.util.Mapper;
35
import common.Const;
46
import common.EnvUtil;
5-
import common.Mapper;
67
import app.component.Operator;
78
import com.fasterxml.jackson.databind.JsonNode;
89
import com.uid2.client.*;
@@ -25,6 +26,7 @@ public class V2ApiOperatorTest {
2526
// The advertiser token will be different on every call due to randomness used in encryption,
2627
// so we can't assert on it
2728

29+
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
2830
private static final String CLIENT_SITE_ID = EnvUtil.getEnv(Const.Config.Operator.CLIENT_SITE_ID);
2931

3032
@ParameterizedTest(name = "/v2/token/generate - {0} - {2}")
@@ -86,7 +88,7 @@ public void testV2TokenValidate(String label, Operator operator, String operator
8688
String advertisingToken = currentIdentity.getAdvertisingToken();
8789
JsonNode response = operator.v2TokenValidate(type, identity, advertisingToken);
8890

89-
assertThat(response).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":true,\"status\":\"success\"}"));
91+
assertThat(response).isEqualTo(OBJECT_MAPPER.readTree("{\"body\":true,\"status\":\"success\"}"));
9092
}
9193

9294
@ParameterizedTest(name = "/v2/identity/map - {0} - {2}")

src/test/java/suite/optout/OptoutTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package suite.optout;
22

3-
import common.Mapper;
43
import app.component.Operator;
54
import com.fasterxml.jackson.databind.JsonNode;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
66
import com.uid2.client.IdentityTokens;
7+
import com.uid2.shared.util.Mapper;
78
import org.junit.jupiter.api.*;
89
import org.junit.jupiter.params.ParameterizedTest;
910
import org.junit.jupiter.params.provider.Arguments;
@@ -24,6 +25,7 @@
2425
public class OptoutTest {
2526
// TODO: Test failure case
2627

28+
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
2729
private static final int OPTOUT_DELAY_MS = 1000;
2830
private static final int OPTOUT_WAIT_SECONDS = 300;
2931

@@ -46,14 +48,14 @@ public void testV2LogoutWithV2TokenGenerate(String label, Operator operator, Str
4648
IdentityTokens generateResponse = operator.v2TokenGenerate(type, identity, false).getIdentity();
4749
Thread.sleep(OPTOUT_DELAY_MS);
4850
JsonNode logoutResponse = operator.v2TokenLogout(type, identity);
49-
assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
51+
assertThat(logoutResponse).isEqualTo(OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
5052
addToken(
5153
label,
5254
operator,
5355
"v2",
5456
"v2",
5557
generateResponse.getRefreshToken(),
56-
Mapper.OBJECT_MAPPER.readTree(generateResponse.getJsonString()).at("/refresh_response_key").asText()
58+
OBJECT_MAPPER.readTree(generateResponse.getJsonString()).at("/refresh_response_key").asText()
5759
);
5860
}
5961

@@ -67,14 +69,14 @@ public void testV2LogoutWithV2TokenGenerateOldParticipant(String label, Operator
6769
IdentityTokens generateResponse = operator.v2TokenGenerate(type, identity, true).getIdentity();
6870
Thread.sleep(OPTOUT_DELAY_MS);
6971
JsonNode logoutResponse = operator.v2TokenLogout(type, identity);
70-
assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
72+
assertThat(logoutResponse).isEqualTo(OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
7173
addToken(
7274
"old participant " + label,
7375
operator,
7476
"v2",
7577
"v2",
7678
generateResponse.getRefreshToken(),
77-
Mapper.OBJECT_MAPPER.readTree(generateResponse.getJsonString()).at("/refresh_response_key").asText()
79+
OBJECT_MAPPER.readTree(generateResponse.getJsonString()).at("/refresh_response_key").asText()
7880
);
7981
}
8082

@@ -92,7 +94,7 @@ public void testV2LogoutWithV2IdentityMap(String label, Operator operator, Strin
9294
if (toOptOut) {
9395
Thread.sleep(OPTOUT_DELAY_MS);
9496
JsonNode logoutResponse = operator.v2TokenLogout(type, emailOrPhone);
95-
assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
97+
assertThat(logoutResponse).isEqualTo(OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
9698
}
9799
outputAdvertisingIdArgs.add(Arguments.of(label, operator, operatorName, rawUID, toOptOut, beforeOptOutTimestamp));
98100
}
@@ -105,7 +107,7 @@ public void testV2LogoutWithV2IdentityMap(String label, Operator operator, Strin
105107
public void testV2TokenRefreshAfterOptOut(String label, Operator operator, String tokenGenerateVersion, String tokenLogoutVersion, String refreshToken, String refreshResponseKey) throws Exception {
106108
assumeThat(tokenGenerateVersion).isEqualTo("v2");
107109

108-
with().pollInterval(5, TimeUnit.SECONDS).await("Get V2 Token Response").atMost(OPTOUT_WAIT_SECONDS, TimeUnit.SECONDS).until(() -> operator.v2TokenRefresh(refreshToken, refreshResponseKey).equals(Mapper.OBJECT_MAPPER.readTree("{\"status\":\"optout\"}")));
110+
with().pollInterval(5, TimeUnit.SECONDS).await("Get V2 Token Response").atMost(OPTOUT_WAIT_SECONDS, TimeUnit.SECONDS).until(() -> operator.v2TokenRefresh(refreshToken, refreshResponseKey).equals(OBJECT_MAPPER.readTree("{\"status\":\"optout\"}")));
109111
}
110112

111113
@Order(5)
@@ -164,7 +166,7 @@ private void addToken(String label, Operator operator, String tokenGenerateVersi
164166
private void waitForOptOutResponse(Function<String, JsonNode> tokenRefreshFunction, String refreshToken, String expectedResponse) {
165167
with().pollInterval(5, TimeUnit.SECONDS).await("Get Token Response").atMost(OPTOUT_WAIT_SECONDS, TimeUnit.SECONDS).until(() -> {
166168
JsonNode response = tokenRefreshFunction.apply(refreshToken);
167-
return response.equals(Mapper.OBJECT_MAPPER.readTree(expectedResponse));
169+
return response.equals(OBJECT_MAPPER.readTree(expectedResponse));
168170
});
169171
}
170172
}

0 commit comments

Comments
 (0)