From d5101025c5a134c9414c762671a228e8ef976d22 Mon Sep 17 00:00:00 2001 From: emeroad Date: Wed, 10 Jul 2024 14:27:07 +0900 Subject: [PATCH] [#noissue] Cleanup Response --- .../manage/controller/AuthInterceptor.java | 4 ++- .../controller/HandlerManagerController.java | 23 +++++++------ .../common/server/response/MapResponse.java | 32 +++++-------------- .../common/server/response/Response.java | 3 +- .../common/server/response/Result.java | 12 +++++++ ...ccessResponse.java => SimpleResponse.java} | 16 +++++----- .../controller/AlarmController.java | 9 +++--- .../controller/UserController.java | 8 ++--- .../controller/UserGroupController.java | 11 ++++--- .../controller/WebhookAlarmController.java | 7 ++-- .../controller/AgentStatisticsController.java | 4 +-- .../pinpoint/web/response/AlarmResponse.java | 7 ++-- .../web/response/CreateUserGroupResponse.java | 7 ++-- .../web/response/AlarmResponseTest.java | 5 +-- .../response/CreateUserGroupResponseTest.java | 5 +-- ...ponseTest.java => SimpleResponseTest.java} | 14 ++++---- .../web/response/WebhookResponseTest.java | 5 +-- .../response/WebhookSendInfoResponseTest.java | 5 +-- .../webhook/controller/WebhookController.java | 9 +++--- .../controller/WebhookSendInfoController.java | 9 +++--- .../web/webhook/model/WebhookResponse.java | 7 ++-- .../model/WebhookSendInfoResponse.java | 7 ++-- 22 files changed, 112 insertions(+), 97 deletions(-) rename collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/SimpleResponse.java => commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java (53%) create mode 100644 commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java rename commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/{SuccessResponse.java => SimpleResponse.java} (61%) rename web/src/test/java/com/navercorp/pinpoint/web/response/{SuccessResponseTest.java => SimpleResponseTest.java} (70%) diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/AuthInterceptor.java b/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/AuthInterceptor.java index d294bef163be..7b397d725e21 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/AuthInterceptor.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/AuthInterceptor.java @@ -18,6 +18,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.navercorp.pinpoint.common.server.response.MapResponse; +import com.navercorp.pinpoint.common.server.response.Result; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; @@ -79,7 +81,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons } private String jsonError(String errorMessage) throws JsonProcessingException { - SimpleResponse response = new SimpleResponse(false, errorMessage); + MapResponse response = new MapResponse(Result.FAIL, errorMessage); return mapper.writeValueAsString(response); } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java b/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java index 80334ed33503..b5667e7b2072 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/HandlerManagerController.java @@ -17,6 +17,9 @@ package com.navercorp.pinpoint.collector.manage.controller; import com.navercorp.pinpoint.collector.manage.HandlerManager; +import com.navercorp.pinpoint.common.server.response.MapResponse; +import com.navercorp.pinpoint.common.server.response.Response; +import com.navercorp.pinpoint.common.server.response.Result; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -39,10 +42,10 @@ public HandlerManagerController(HandlerManager handlerManager) { } @GetMapping(value = "/enableAccess") - public ResponseEntity enableAccess() { + public ResponseEntity enableAccess() { try { handlerManager.enableAccess(); - return ResponseEntity.ok(SimpleResponse.success()); + return ResponseEntity.ok(MapResponse.ok()); } catch (Exception e) { return unauthorizedResponse(e.getMessage()); } @@ -51,27 +54,27 @@ public ResponseEntity enableAccess() { @GetMapping(value = "/disableAccess") - public ResponseEntity disableAccess() { + public ResponseEntity disableAccess() { try { handlerManager.disableAccess(); - return ResponseEntity.ok(SimpleResponse.success()); + return ResponseEntity.ok(MapResponse.ok()); } catch (Exception e) { return unauthorizedResponse(e.getMessage()); } } @GetMapping(value = "/isEnable") - public ResponseEntity isEnable() { + public ResponseEntity isEnable() { boolean isEnable = handlerManager.isEnable(); - SimpleResponse simpleResponse = SimpleResponse.success(); - simpleResponse.addAttribute("isEnable", isEnable); + MapResponse response = new MapResponse(Result.SUCCESS); + response.addAttribute("isEnable", isEnable); - return ResponseEntity.ok(simpleResponse); + return ResponseEntity.ok(response); } - private ResponseEntity unauthorizedResponse(String errorMessage) { - SimpleResponse body = new SimpleResponse(false, errorMessage); + private ResponseEntity unauthorizedResponse(String errorMessage) { + MapResponse body = new MapResponse(Result.FAIL, errorMessage); return ResponseEntity.status(HttpStatus.FORBIDDEN).body(body); } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/SimpleResponse.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java similarity index 53% rename from collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/SimpleResponse.java rename to commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java index 724f4d5375b8..5f248e67a07c 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/manage/controller/SimpleResponse.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/MapResponse.java @@ -1,42 +1,26 @@ -package com.navercorp.pinpoint.collector.manage.controller; +package com.navercorp.pinpoint.common.server.response; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonInclude; -import com.navercorp.pinpoint.common.server.response.Response; import java.util.HashMap; import java.util.Map; import java.util.Objects; @JsonInclude(JsonInclude.Include.NON_NULL) -public class SimpleResponse implements Response { - private final boolean result; - private final String message; +public class MapResponse extends SimpleResponse { private Map attributeMap; - public static SimpleResponse success() { - return new SimpleResponse(true); + public static Response ok() { + return new MapResponse(Result.SUCCESS); } - public SimpleResponse(boolean result, String message) { - this.result = result; - this.message = message; + public MapResponse(Result result, String message) { + super(result, message); } - public SimpleResponse(boolean result) { - this.result = result; - this.message = null; - } - - public String getResult() { - if (result) { - return "success"; - } - return "fail"; - } - - public String getMessage() { - return message; + public MapResponse(Result result) { + super(result); } public void addAttribute(String attributeName, Object attributeValue) { diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Response.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Response.java index d717ae2f6ff9..6def8a87d1ff 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Response.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Response.java @@ -1,4 +1,5 @@ package com.navercorp.pinpoint.common.server.response; public interface Response { -} + Result getResult(); +} \ No newline at end of file diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java new file mode 100644 index 000000000000..459890c1f766 --- /dev/null +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/Result.java @@ -0,0 +1,12 @@ +package com.navercorp.pinpoint.common.server.response; + +public enum Result { + SUCCESS, FAIL; + + public static Result of(boolean success) { + if (success) { + return SUCCESS; + } + return FAIL; + } +} diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SuccessResponse.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java similarity index 61% rename from commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SuccessResponse.java rename to commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java index 514371748a46..f68dca830c97 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SuccessResponse.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/response/SimpleResponse.java @@ -4,29 +4,29 @@ import java.util.Objects; -public class SuccessResponse implements Response { - private final String result; +public class SimpleResponse implements Response { + private final Result result; private final String message; public static Response ok() { - return new SuccessResponse("SUCCESS"); + return new SimpleResponse(Result.SUCCESS); } public static Response ok(String message) { - return new SuccessResponse("SUCCESS", message); + return new SimpleResponse(Result.SUCCESS, message); } - public SuccessResponse(String result) { + public SimpleResponse(Result result) { this(result, null); } - public SuccessResponse(String result, String message) { + public SimpleResponse(Result result, String message) { this.result = Objects.requireNonNull(result, "result"); this.message = message; - } - public String getResult() { + @Override + public Result getResult() { return result; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java index c20d68a88e77..d241773a9b6d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AlarmController.java @@ -17,7 +17,8 @@ package com.navercorp.pinpoint.web.authorization.controller; import com.navercorp.pinpoint.common.server.response.Response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import com.navercorp.pinpoint.common.util.StringUtils; import com.navercorp.pinpoint.web.alarm.CheckerCategory; import com.navercorp.pinpoint.web.alarm.vo.Rule; @@ -62,7 +63,7 @@ public AlarmResponse insertRule(@RequestBody Rule rule) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not applicationId/checkerName/userGroupId/threashold to insert alarm rule"); } final String ruleId = alarmService.insertRule(rule); - return new AlarmResponse("SUCCESS", ruleId); + return new AlarmResponse(Result.SUCCESS, ruleId); } @DeleteMapping @@ -71,7 +72,7 @@ public Response deleteRule(@RequestBody Rule rule) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not ruleId to delete alarm rule"); } alarmService.deleteRule(rule); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } @GetMapping(params = USER_GROUP_ID) @@ -93,7 +94,7 @@ public Response updateRule(@RequestBody Rule rule) { ); } alarmService.updateRule(rule); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } @GetMapping(value = "/checker") diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java index bf9d4c469f4f..3a49604d895c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserController.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.web.authorization.controller; import com.navercorp.pinpoint.common.server.response.Response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import com.navercorp.pinpoint.common.util.StringUtils; import com.navercorp.pinpoint.web.service.UserService; import com.navercorp.pinpoint.web.util.ValueValidator; @@ -65,7 +65,7 @@ public Response insertUser(@RequestBody User user) { ); } userService.insertUser(user); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } @DeleteMapping @@ -77,7 +77,7 @@ public Response deleteUser(@RequestBody User user) { ); } userService.deleteUser(user.getUserId()); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } @GetMapping(params = "userId") @@ -129,7 +129,7 @@ public Response updateUser(@RequestBody User user) { ); } userService.updateUser(user); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java index e21019906774..a9af34eaa32f 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/UserGroupController.java @@ -16,7 +16,8 @@ package com.navercorp.pinpoint.web.authorization.controller; import com.navercorp.pinpoint.common.server.response.Response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import com.navercorp.pinpoint.common.util.StringUtils; import com.navercorp.pinpoint.web.response.CreateUserGroupResponse; import com.navercorp.pinpoint.web.service.UserGroupService; @@ -71,7 +72,7 @@ public CreateUserGroupResponse createUserGroup(@RequestBody UserGroup userGroup) try { final String userGroupNumber = userGroupService.createUserGroup(userGroup); - return new CreateUserGroupResponse("SUCCESS", userGroupNumber); + return new CreateUserGroupResponse(Result.SUCCESS, userGroupNumber); } catch (PinpointUserGroupException e) { logger.error(e.getMessage(), e); throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); @@ -89,7 +90,7 @@ public Response deleteUserGroup(@RequestBody UserGroup userGroup) { try { userGroupService.deleteUserGroup(userGroup); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } catch (PinpointUserGroupException e) { logger.error(e.getMessage(), e); throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); @@ -122,7 +123,7 @@ public Response insertUserGroupMember(@RequestBody UserGroupMemberParam userGrou ); } userGroupService.insertMember(userGroupMember); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } @DeleteMapping(value = "/member") @@ -135,7 +136,7 @@ public Response deleteUserGroupMember(@RequestBody UserGroupMemberParam userGrou ); } userGroupService.deleteMember(userGroupMember); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } @GetMapping(value = "/member") diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/WebhookAlarmController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/WebhookAlarmController.java index 4aafa18104dc..ab981093d5c3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/WebhookAlarmController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/WebhookAlarmController.java @@ -18,7 +18,8 @@ package com.navercorp.pinpoint.web.authorization.controller; import com.navercorp.pinpoint.common.server.response.Response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import com.navercorp.pinpoint.web.alarm.vo.Rule; import com.navercorp.pinpoint.web.response.AlarmResponse; import com.navercorp.pinpoint.web.webhook.WebhookModule; @@ -57,7 +58,7 @@ public AlarmResponse insertRuleWithWebhooks(@RequestBody RuleWithWebhooks ruleWi } final String ruleId = webhookAlarmServiceFacade.insertRuleWithWebhooks(rule, ruleWithWebhooks.getWebhookIds()); - return new AlarmResponse("SUCCESS", ruleId); + return new AlarmResponse(Result.SUCCESS, ruleId); } @PutMapping(value = "/includeWebhooks") @@ -67,7 +68,7 @@ public Response updateRuleWithWebhooks(@RequestBody RuleWithWebhooks ruleWithWeb throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not ruleId/userGroupId/applicationid/checkerName to update alarm rule"); } webhookAlarmServiceFacade.updateRuleWithWebhooks(rule, ruleWithWebhooks.getWebhookIds()); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } static public class RuleWithWebhooks { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatisticsController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatisticsController.java index 8dd15502a4c2..73b6a234ee0d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatisticsController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentStatisticsController.java @@ -17,7 +17,7 @@ package com.navercorp.pinpoint.web.controller; import com.navercorp.pinpoint.common.server.response.Response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.service.AgentStatisticsService; import com.navercorp.pinpoint.web.util.DateTimeUtils; @@ -65,7 +65,7 @@ public Response insertAgentCount( boolean success = agentStatisticsService.insertAgentCount(agentCountStatistics); if (success) { - return SuccessResponse.ok(); + return SimpleResponse.ok(); } else { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "insert DAO error."); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/response/AlarmResponse.java b/web/src/main/java/com/navercorp/pinpoint/web/response/AlarmResponse.java index cec64fbf58ea..2ab8a7fb2b54 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/response/AlarmResponse.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/response/AlarmResponse.java @@ -1,12 +1,13 @@ package com.navercorp.pinpoint.web.response; import com.fasterxml.jackson.annotation.JsonInclude; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; -public class AlarmResponse extends SuccessResponse { +public class AlarmResponse extends SimpleResponse { private final String ruleId; - public AlarmResponse(String result, String ruleId) { + public AlarmResponse(Result result, String ruleId) { super(result); this.ruleId = ruleId; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponse.java b/web/src/main/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponse.java index 2329ff41dd5e..0c04fd2c32a0 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponse.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponse.java @@ -1,13 +1,14 @@ package com.navercorp.pinpoint.web.response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import java.util.Objects; -public class CreateUserGroupResponse extends SuccessResponse { +public class CreateUserGroupResponse extends SimpleResponse { private final String number; - public CreateUserGroupResponse(String result, String number) { + public CreateUserGroupResponse(Result result, String number) { super(result); this.number = Objects.requireNonNull(number, "number"); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/response/AlarmResponseTest.java b/web/src/test/java/com/navercorp/pinpoint/web/response/AlarmResponseTest.java index a1bf8384af14..1fad5b01f9cd 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/response/AlarmResponseTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/AlarmResponseTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.TextNode; +import com.navercorp.pinpoint.common.server.response.Result; import com.navercorp.pinpoint.common.server.util.json.Jackson; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -13,14 +14,14 @@ public class AlarmResponseTest { @Test public void testCreatedMessage() throws JsonProcessingException { - AlarmResponse result = new AlarmResponse("SUCCESS", "12345"); + AlarmResponse result = new AlarmResponse(Result.SUCCESS, "12345"); checkOutput(result); } private void checkOutput(AlarmResponse codeResult) throws JsonProcessingException { String jsonString = mapper.writeValueAsString(codeResult); JsonNode jsonNode = mapper.readTree(jsonString); - Assertions.assertEquals(TextNode.valueOf("SUCCESS"), jsonNode.get("result")); + Assertions.assertEquals(TextNode.valueOf(Result.SUCCESS.name()), jsonNode.get("result")); Assertions.assertNull(jsonNode.get("message")); Assertions.assertEquals(TextNode.valueOf("12345"), jsonNode.get("ruleId")); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponseTest.java b/web/src/test/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponseTest.java index 1361b1bd2e65..e04a009663c8 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponseTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponseTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.TextNode; +import com.navercorp.pinpoint.common.server.response.Result; import com.navercorp.pinpoint.common.server.util.json.Jackson; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -13,14 +14,14 @@ public class CreateUserGroupResponseTest { @Test public void testCreatedMessage() throws JsonProcessingException { - CreateUserGroupResponse result = new CreateUserGroupResponse("SUCCESS", "12345"); + CreateUserGroupResponse result = new CreateUserGroupResponse(Result.SUCCESS, "12345"); checkOutput(result); } private void checkOutput(CreateUserGroupResponse codeResult) throws JsonProcessingException { String jsonString = mapper.writeValueAsString(codeResult); JsonNode jsonNode = mapper.readTree(jsonString); - Assertions.assertEquals(TextNode.valueOf("SUCCESS"), jsonNode.get("result")); + Assertions.assertEquals(TextNode.valueOf(Result.SUCCESS.name()), jsonNode.get("result")); Assertions.assertNull(jsonNode.get("message")); Assertions.assertEquals(TextNode.valueOf("12345"), jsonNode.get("number")); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/response/SuccessResponseTest.java b/web/src/test/java/com/navercorp/pinpoint/web/response/SimpleResponseTest.java similarity index 70% rename from web/src/test/java/com/navercorp/pinpoint/web/response/SuccessResponseTest.java rename to web/src/test/java/com/navercorp/pinpoint/web/response/SimpleResponseTest.java index 003f346e0d8d..209cd1cb6da7 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/response/SuccessResponseTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/SimpleResponseTest.java @@ -4,29 +4,29 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.TextNode; -import com.navercorp.pinpoint.common.server.util.json.Jackson; import com.navercorp.pinpoint.common.server.response.Response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class SuccessResponseTest { +public class SimpleResponseTest { private final ObjectMapper mapper = new ObjectMapper(); @Test public void testStaticOk() throws JsonProcessingException { - Response result = SuccessResponse.ok();; + Response result = SimpleResponse.ok(); JsonNode jsonNode = checkOutput(result); - Assertions.assertEquals(TextNode.valueOf("SUCCESS"), jsonNode.get("result")); + Assertions.assertEquals(TextNode.valueOf(Result.SUCCESS.name()), jsonNode.get("result")); Assertions.assertNull(jsonNode.get("message")); } @Test public void testStaticOkWithMessage() throws JsonProcessingException { - Response result = SuccessResponse.ok("Test Message");; + Response result = SimpleResponse.ok("Test Message"); checkOutput(result); JsonNode jsonNode = checkOutput(result); - Assertions.assertEquals(TextNode.valueOf("SUCCESS"), jsonNode.get("result")); + Assertions.assertEquals(TextNode.valueOf(Result.SUCCESS.name()), jsonNode.get("result")); Assertions.assertEquals(TextNode.valueOf("Test Message"), jsonNode.get("message")); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookResponseTest.java b/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookResponseTest.java index c1bd856d2347..cde6121dbddf 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookResponseTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookResponseTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.TextNode; +import com.navercorp.pinpoint.common.server.response.Result; import com.navercorp.pinpoint.common.server.util.json.Jackson; import com.navercorp.pinpoint.web.webhook.model.WebhookResponse; import org.junit.jupiter.api.Assertions; @@ -14,14 +15,14 @@ public class WebhookResponseTest { @Test public void testCreatedMessage() throws JsonProcessingException { - WebhookResponse result = new WebhookResponse("SUCCESS", "12345"); + WebhookResponse result = new WebhookResponse(Result.SUCCESS, "12345"); checkOutput(result); } private void checkOutput(WebhookResponse codeResult) throws JsonProcessingException { String jsonString = mapper.writeValueAsString(codeResult); JsonNode jsonNode = mapper.readTree(jsonString); - Assertions.assertEquals(TextNode.valueOf("SUCCESS"), jsonNode.get("result")); + Assertions.assertEquals(TextNode.valueOf(Result.SUCCESS.name()), jsonNode.get("result")); Assertions.assertNull(jsonNode.get("message")); Assertions.assertEquals(TextNode.valueOf("12345"), jsonNode.get("webhookId")); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookSendInfoResponseTest.java b/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookSendInfoResponseTest.java index 99572c73591a..48e801ddfdcf 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookSendInfoResponseTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookSendInfoResponseTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.TextNode; +import com.navercorp.pinpoint.common.server.response.Result; import com.navercorp.pinpoint.common.server.util.json.Jackson; import com.navercorp.pinpoint.web.webhook.model.WebhookSendInfoResponse; import org.junit.jupiter.api.Assertions; @@ -14,14 +15,14 @@ public class WebhookSendInfoResponseTest { @Test public void testCreatedMessage() throws JsonProcessingException { - WebhookSendInfoResponse result = new WebhookSendInfoResponse("SUCCESS", "12345"); + WebhookSendInfoResponse result = new WebhookSendInfoResponse(Result.SUCCESS, "12345"); checkOutput(result); } private void checkOutput(WebhookSendInfoResponse codeResult) throws JsonProcessingException { String jsonString = mapper.writeValueAsString(codeResult); JsonNode jsonNode = mapper.readTree(jsonString); - Assertions.assertEquals(TextNode.valueOf("SUCCESS"), jsonNode.get("result")); + Assertions.assertEquals(TextNode.valueOf(Result.SUCCESS.name()), jsonNode.get("result")); Assertions.assertNull(jsonNode.get("message")); Assertions.assertEquals(TextNode.valueOf("12345"), jsonNode.get("webhookSendInfoId")); } diff --git a/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/controller/WebhookController.java b/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/controller/WebhookController.java index 67c92cb2e651..74858f172342 100644 --- a/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/controller/WebhookController.java +++ b/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/controller/WebhookController.java @@ -1,7 +1,8 @@ package com.navercorp.pinpoint.web.webhook.controller; import com.navercorp.pinpoint.common.server.response.Response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import com.navercorp.pinpoint.web.webhook.model.Webhook; import com.navercorp.pinpoint.web.webhook.model.WebhookResponse; import com.navercorp.pinpoint.web.webhook.service.WebhookService; @@ -58,7 +59,7 @@ public WebhookResponse insertWebhook(@RequestBody Webhook webhook) { } String webhookId = webhookService.insertWebhook(webhook); - return new WebhookResponse("SUCCESS", webhookId); + return new WebhookResponse(Result.SUCCESS, webhookId); } @DeleteMapping() @@ -69,7 +70,7 @@ public Response deleteWebhook(@RequestBody Webhook webhook) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Missing argument: webhook.id"); } webhookService.deleteWebhook(webhook); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } @GetMapping() @@ -110,7 +111,7 @@ public Response updateWebhook(@RequestBody Webhook webhook) { } webhookService.updateWebhook(webhook); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } private void validateURL(Webhook webhook) throws MalformedURLException, URISyntaxException { diff --git a/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/controller/WebhookSendInfoController.java b/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/controller/WebhookSendInfoController.java index a5d439073e0b..b1577a5dad83 100644 --- a/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/controller/WebhookSendInfoController.java +++ b/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/controller/WebhookSendInfoController.java @@ -1,7 +1,8 @@ package com.navercorp.pinpoint.web.webhook.controller; import com.navercorp.pinpoint.common.server.response.Response; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import com.navercorp.pinpoint.web.webhook.model.WebhookSendInfo; import com.navercorp.pinpoint.web.webhook.model.WebhookSendInfoResponse; import com.navercorp.pinpoint.web.webhook.service.WebhookSendInfoService; @@ -43,7 +44,7 @@ public WebhookSendInfoResponse insertWebhookSendInfo(@RequestBody WebhookSendInf throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there should be ruleId and webhookId to insert webhookSendInfo"); } String webhookSendInfoId = webhookSendInfoService.insertWebhookSendInfo(webhookSendInfo); - return new WebhookSendInfoResponse("SUCCESS", webhookSendInfoId); + return new WebhookSendInfoResponse(Result.SUCCESS, webhookSendInfoId); } @DeleteMapping() @@ -52,7 +53,7 @@ public Response deleteWebhookSendInfo(@RequestBody WebhookSendInfo webhookSendIn throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there should be webhookSendInfoId to delete webhook"); } webhookSendInfoService.deleteWebhookSendInfo(webhookSendInfo); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } @GetMapping() @@ -76,6 +77,6 @@ public Response updateWebhookSendInfo(@RequestBody WebhookSendInfo webhookSendIn throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "There should be webhookSendInfoId, webhookId and ruleId to update webhook send information"); } webhookSendInfoService.updateWebhookSendInfo(webhookSendInfo); - return SuccessResponse.ok(); + return SimpleResponse.ok(); } } diff --git a/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/model/WebhookResponse.java b/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/model/WebhookResponse.java index 3456e4f7d82e..a6a5ea70d1c9 100644 --- a/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/model/WebhookResponse.java +++ b/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/model/WebhookResponse.java @@ -1,14 +1,15 @@ package com.navercorp.pinpoint.web.webhook.model; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import java.util.Objects; -public class WebhookResponse extends SuccessResponse { +public class WebhookResponse extends SimpleResponse { private final String webhookId; - public WebhookResponse(String result, String webhookId) { + public WebhookResponse(Result result, String webhookId) { super(result); this.webhookId = Objects.requireNonNull(webhookId, "webhookId"); } diff --git a/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/model/WebhookSendInfoResponse.java b/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/model/WebhookSendInfoResponse.java index 681d5cfc1e41..68876a2e16f9 100644 --- a/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/model/WebhookSendInfoResponse.java +++ b/webhook/src/main/java/com/navercorp/pinpoint/web/webhook/model/WebhookSendInfoResponse.java @@ -1,14 +1,15 @@ package com.navercorp.pinpoint.web.webhook.model; -import com.navercorp.pinpoint.common.server.response.SuccessResponse; +import com.navercorp.pinpoint.common.server.response.Result; +import com.navercorp.pinpoint.common.server.response.SimpleResponse; import java.util.Objects; -public class WebhookSendInfoResponse extends SuccessResponse { +public class WebhookSendInfoResponse extends SimpleResponse { private final String webhookSendInfoId; - public WebhookSendInfoResponse(String result, String webhookSendInfoId) { + public WebhookSendInfoResponse(Result result, String webhookSendInfoId) { super(result); this.webhookSendInfoId = Objects.requireNonNull(webhookSendInfoId, "webhookSendInfoId"); }