Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "requestId" field in ExceptionDetail class. #45

Merged
merged 3 commits into from
Jan 18, 2021
Merged
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
@@ -1,8 +1,12 @@
package xyz.groundx.caver_ext_kas.exception;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ExceptionDetail {
int code;
String message = "";
String requestId = "";

public ExceptionDetail() {
}
Expand All @@ -14,4 +18,8 @@ public int getCode() {
public String getMessage() {
return message;
}

public String getRequestId() {
return requestId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package xyz.groundx.caver_ext_kas.exception;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.*;

public class ExceptionDetailTest {
@Test
public void parse() throws IOException {
String test = "{\"code\":1061010,\"message\":\"data don't exist\",\"requestId\":\"6a1d4aba-fdc3-9a8a-bec7-c5de75abf9dd\"}";

ObjectMapper mapper = new ObjectMapper();
ExceptionDetail detail = mapper.readValue(test, ExceptionDetail.class);

assertEquals(1061010, detail.getCode());
assertEquals("data don't exist", detail.getMessage());
assertEquals("6a1d4aba-fdc3-9a8a-bec7-c5de75abf9dd", detail.getRequestId());
}

@Test
public void ignoreNotExistedField() throws IOException {
String test = "{\"code\":1061010,\"message\":\"data don't exist\"}";

ObjectMapper mapper = new ObjectMapper();
ExceptionDetail detail = mapper.readValue(test, ExceptionDetail.class);

assertEquals(1061010, detail.getCode());
assertEquals("data don't exist", detail.getMessage());
}

@Test
public void ignoreUnknownField() throws IOException {
String test = "{\"code\":1061010,\"message\":\"data don't exist\",\"requestId\":\"6a1d4aba-fdc3-9a8a-bec7-c5de75abf9dd\", \"unknown\": 1234}";

ObjectMapper mapper = new ObjectMapper();
ExceptionDetail detail = mapper.readValue(test, ExceptionDetail.class);

assertEquals(1061010, detail.getCode());
assertEquals("data don't exist", detail.getMessage());
assertEquals("6a1d4aba-fdc3-9a8a-bec7-c5de75abf9dd", detail.getRequestId());
}
}