diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentCommandController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentCommandController.java index 82360c4ae2f9..1afe176640ba 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentCommandController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentCommandController.java @@ -34,7 +34,6 @@ import org.apache.thrift.TBase; import org.apache.thrift.TException; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -59,7 +58,7 @@ public AgentCommandController(ConfigProperties webProperties, AgentService agent } @GetMapping(value = "/activeThreadDump") - public ResponseEntity getActiveThreadDump(@RequestParam(value = "applicationName") String applicationName, + public CodeResult getActiveThreadDump(@RequestParam(value = "applicationName") String applicationName, @RequestParam(value = "agentId") String agentId, @RequestParam(value = "limit", required = false, defaultValue = "-1") int limit, @RequestParam(value = "threadName", required = false) List threadNameList, @@ -155,7 +154,7 @@ public String getVersion() { } @GetMapping(value = "/activeThreadLightDump") - public ResponseEntity getActiveThreadLightDump(@RequestParam(value = "applicationName") String applicationName, + public CodeResult getActiveThreadLightDump(@RequestParam(value = "applicationName") String applicationName, @RequestParam(value = "agentId") String agentId, @RequestParam(value = "limit", required = false, defaultValue = "-1") int limit, @RequestParam(value = "threadName", required = false) List threadNameList, diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentDownloadController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentDownloadController.java index c8cdbfc75732..80b50f0dea24 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentDownloadController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentDownloadController.java @@ -5,7 +5,6 @@ import com.navercorp.pinpoint.web.vo.AgentDownloadInfo; import com.navercorp.pinpoint.web.vo.AgentInstallationInfo; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; @@ -22,7 +21,7 @@ public AgentDownloadController(AgentDownLoadService agentDownLoadService) { } @RequestMapping(value = "/getAgentInstallationInfo") - public ResponseEntity getAgentDownloadUrl() { + public CodeResult getAgentDownloadUrl() { AgentDownloadInfo latestStableAgentDownloadInfo = agentDownLoadService.getLatestStableAgentDownloadInfo(); if (latestStableAgentDownloadInfo != null) { return CodeResult.ok(new AgentInstallationInfo(latestStableAgentDownloadInfo)); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java index 910a8939ffdd..e48a1bed79b4 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java @@ -32,7 +32,6 @@ import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.vo.timeline.inspector.InspectorTimeline; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -177,7 +176,7 @@ public InspectorTimeline getAgentStatusTimeline( } @RequestMapping(value = "/isAvailableAgentId") - public ResponseEntity isAvailableAgentId(@RequestParam("agentId") String agentId) { + public CodeResult isAvailableAgentId(@RequestParam("agentId") String agentId) { final IdValidateUtils.CheckResult result = IdValidateUtils.checkId(agentId, PinpointConstants.AGENT_ID_MAX_LEN); if (result == IdValidateUtils.CheckResult.FAIL_LENGTH) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "length range is 1 ~ 24"); 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 709a01df7746..5b18e1c00727 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 @@ -28,7 +28,6 @@ import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -76,16 +75,16 @@ private boolean isRuleDataValidForPost(Rule rule) { } @PostMapping() - public ResponseEntity insertRule(@RequestBody Rule rule) { + public Response insertRule(@RequestBody Rule rule) { if (!isRuleDataValidForPost(rule)) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not applicationId/checkerName/userGroupId/threashold to insert alarm rule"); } String ruleId = alarmService.insertRule(rule); - return ResponseEntity.ok(getAlarmResponse("SUCCESS", ruleId)); + return getAlarmResponse("SUCCESS", ruleId); } @DeleteMapping() - public ResponseEntity deleteRule(@RequestBody Rule rule) { + public Response deleteRule(@RequestBody Rule rule) { if (StringUtils.isEmpty(rule.getRuleId())) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not ruleId to delete alarm rule"); } @@ -105,7 +104,7 @@ public Object getRule(@RequestParam(value=USER_GROUP_ID, required=false) String } @PutMapping() - public ResponseEntity updateRule(@RequestBody Rule rule) { + public Response updateRule(@RequestBody Rule rule) { if (StringUtils.isEmpty(rule.getRuleId()) || StringUtils.isEmpty(rule.getApplicationId()) || StringUtils.isEmpty(rule.getCheckerName()) || StringUtils.isEmpty(rule.getUserGroupId())) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not ruleId/userGroupId/applicationid/checkerName to update alarm rule"); } @@ -114,7 +113,7 @@ public ResponseEntity updateRule(@RequestBody Rule rule) { } @PostMapping(value = "/includeWebhooks") - public ResponseEntity insertRuleWithWebhooks(@RequestBody RuleWithWebhooks ruleWithWebhooks) { + public Response insertRuleWithWebhooks(@RequestBody RuleWithWebhooks ruleWithWebhooks) { Rule rule = ruleWithWebhooks.getRule(); if (!isRuleDataValidForPost(rule)) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not applicationId/checkerName/userGroupId/threashold to insert alarm rule"); @@ -123,11 +122,11 @@ public ResponseEntity insertRuleWithWebhooks(@RequestBody RuleWithWebh throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "webhook should be enabled to bind webhook to an alarm"); } String ruleId = alarmService.insertRuleWithWebhooks(rule, ruleWithWebhooks.getWebhookIds()); - return ResponseEntity.ok(getAlarmResponse("SUCCESS", ruleId)); + return getAlarmResponse("SUCCESS", ruleId); } @PutMapping(value = "/includeWebhooks") - public ResponseEntity updateRuleWithWebhooks(@RequestBody RuleWithWebhooks ruleWithWebhooks) { + public Response updateRuleWithWebhooks(@RequestBody RuleWithWebhooks ruleWithWebhooks) { Rule rule = ruleWithWebhooks.getRule(); if (StringUtils.isEmpty(rule.getRuleId()) || StringUtils.isEmpty(rule.getApplicationId()) || StringUtils.isEmpty(rule.getCheckerName()) || StringUtils.isEmpty(rule.getUserGroupId())) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not ruleId/userGroupId/applicationid/checkerName to update alarm rule"); 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 9705016e4a05..270607d1c105 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 @@ -25,9 +25,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -58,7 +56,7 @@ public UserController(UserService userService) { } @PostMapping() - public ResponseEntity insertUser(@RequestBody User user) { + public Response insertUser(@RequestBody User user) { if (!ValueValidator.validateUser(user)) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "User information validation failed to creating user information."); } @@ -67,7 +65,7 @@ public ResponseEntity insertUser(@RequestBody User user) { } @DeleteMapping() - public ResponseEntity deletetUser(@RequestBody User user) { + public Response deletetUser(@RequestBody User user) { if (StringUtils.isEmpty(user.getUserId())) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not userId in params to delete user"); } @@ -95,7 +93,7 @@ public List getUser(@RequestParam(value = "userId", required = false) Stri } @PutMapping() - public ResponseEntity updateUser(@RequestBody User user) { + public Response updateUser(@RequestBody User user) { if (!ValueValidator.validateUser(user)) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "User information validation failed to creating user infomation."); } 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 253bc4e45ce1..48f4dbfb6e8c 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 @@ -28,7 +28,6 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -59,14 +58,14 @@ public UserGroupController(UserGroupService userGroupService) { } @PostMapping() - public ResponseEntity createUserGroup(@RequestBody UserGroup userGroup) { + public Response createUserGroup(@RequestBody UserGroup userGroup) { if (!ValueValidator.validateUserGroupId(userGroup.getId())) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "usergroupId pattern is invalid to create user group"); } try { String userGroupNumber = userGroupService.createUserGroup(userGroup); - return ResponseEntity.ok(new CreateUserGroupResponse("SUCCESS", userGroupNumber)); + return new CreateUserGroupResponse("SUCCESS", userGroupNumber); } catch (PinpointUserGroupException e) { logger.error(e.getMessage(), e); throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage()); @@ -74,7 +73,7 @@ public ResponseEntity createUserGroup(@RequestBody UserGroup userGroup } @DeleteMapping() - public ResponseEntity deleteUserGroup(@RequestBody UserGroup userGroup) { + public Response deleteUserGroup(@RequestBody UserGroup userGroup) { if (StringUtils.isEmpty(userGroup.getId())) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is id of userGroup in params to delete user group"); } @@ -99,7 +98,7 @@ public List getUserGroup(@RequestParam(value = USER_ID, required = fa } @PostMapping(value = "/member") - public ResponseEntity insertUserGroupMember(@RequestBody UserGroupMemberParam userGroupMember) { + public Response insertUserGroupMember(@RequestBody UserGroupMemberParam userGroupMember) { if (StringUtils.isEmpty(userGroupMember.getMemberId()) || StringUtils.isEmpty(userGroupMember.getUserGroupId())) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "there is not userGroupId or memberId in params to insert user group member"); } @@ -108,7 +107,7 @@ public ResponseEntity insertUserGroupMember(@RequestBody UserGroupMemb } @DeleteMapping(value = "/member") - public ResponseEntity deleteUserGroupMember(@RequestBody UserGroupMemberParam userGroupMember) { + public Response deleteUserGroupMember(@RequestBody UserGroupMemberParam userGroupMember) { if (StringUtils.isEmpty(userGroupMember.getUserGroupId()) || StringUtils.isEmpty(userGroupMember.getMemberId())) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there is not userGroupId or memberId in params to delete user group member"); } 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 a35a3a106c69..5d5242d28763 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 @@ -23,7 +23,6 @@ import com.navercorp.pinpoint.web.vo.AgentCountStatistics; import com.navercorp.pinpoint.common.server.util.time.Range; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -47,12 +46,12 @@ public AgentStatisticsController(AgentStatisticsService agentStatisticsService) } @GetMapping(value = "/insertAgentCount", params = {"agentCount"}) - public ResponseEntity insertAgentCount(@RequestParam("agentCount") int agentCount) { + public Response insertAgentCount(@RequestParam("agentCount") int agentCount) { return insertAgentCount(agentCount, new Date().getTime()); } @GetMapping(value = "/insertAgentCount", params = {"agentCount", "timestamp"}) - public ResponseEntity insertAgentCount(@RequestParam("agentCount") int agentCount, @RequestParam("timestamp") long timestamp) { + public Response insertAgentCount(@RequestParam("agentCount") int agentCount, @RequestParam("timestamp") long timestamp) { if (timestamp < 0) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "negative timestamp."); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java index 8dcd133b039a..c98ba32bb3da 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java @@ -22,7 +22,6 @@ import com.navercorp.pinpoint.web.vo.ApplicationAgentHostList; import com.navercorp.pinpoint.web.response.CodeResult; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -63,7 +62,7 @@ public ApplicationAgentHostList getApplicationHostInfo ( } @RequestMapping(value = "/isAvailableApplicationName") - public ResponseEntity isAvailableApplicationName(@RequestParam("applicationName") String applicationName) { + public CodeResult isAvailableApplicationName(@RequestParam("applicationName") String applicationName) { final IdValidateUtils.CheckResult result = IdValidateUtils.checkId(applicationName, PinpointConstants.APPLICATION_NAME_MAX_LEN); if (result == IdValidateUtils.CheckResult.FAIL_LENGTH) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "length range is 1 ~ 24"); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/CommandController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/CommandController.java index c4da0eb2ed09..78b18b50db38 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/CommandController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/CommandController.java @@ -28,7 +28,6 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -53,7 +52,7 @@ public CommandController(AgentService agentService) { } @GetMapping(value = "/echo") - public ResponseEntity echo(@RequestParam("applicationName") String applicationName, @RequestParam("agentId") String agentId, + public CodeResult echo(@RequestParam("applicationName") String applicationName, @RequestParam("agentId") String agentId, @RequestParam("startTimeStamp") long startTimeStamp, @RequestParam("message") String message) throws TException { AgentInfo agentInfo = agentService.getAgentInfo(applicationName, agentId, startTimeStamp); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/WebhookController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/WebhookController.java index 7d202ff2b116..1f871c040025 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/WebhookController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/WebhookController.java @@ -9,7 +9,6 @@ import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; @@ -36,7 +35,7 @@ public WebhookController(WebhookService webhookService) { } @PostMapping() - public ResponseEntity insertWebhook(@RequestBody Webhook webhook) { + public Response insertWebhook(@RequestBody Webhook webhook) { if (!webhookEnable) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "webhook function is disabled"); } @@ -46,11 +45,11 @@ public ResponseEntity insertWebhook(@RequestBody Webhook webhook) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "there should be url, applicationId/serviceName to insert webhook"); } String webhookId = webhookService.insertWebhook(webhook); - return ResponseEntity.ok(new WebhookResponse("SUCCESS", webhookId)); + return new WebhookResponse("SUCCESS", webhookId); } @DeleteMapping() - public ResponseEntity deleteWebhook(@RequestBody Webhook webhook) { + public Response deleteWebhook(@RequestBody Webhook webhook) { if (!webhookEnable) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "webhook function is disabled"); } @@ -86,7 +85,7 @@ public List getWebhook(@RequestParam(value=APPLICATION_ID, required=fal } @PutMapping() - public ResponseEntity updateWebhook(@RequestBody Webhook webhook) { + public Response updateWebhook(@RequestBody Webhook webhook) { if (!webhookEnable) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "webhook function is disabled"); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/WebhookSendInfoController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/WebhookSendInfoController.java index cbaba74044ab..31315f1c4144 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/WebhookSendInfoController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/WebhookSendInfoController.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; @@ -36,7 +35,7 @@ public WebhookSendInfoController(WebhookService webhookService, WebhookSendInfoS @PostMapping() - public ResponseEntity insertWebhookSendInfo(@RequestBody WebhookSendInfo webhookSendInfo) { + public Response insertWebhookSendInfo(@RequestBody WebhookSendInfo webhookSendInfo) { if (!webhookEnable) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "webhook function is disabled"); } @@ -45,11 +44,11 @@ public ResponseEntity insertWebhookSendInfo(@RequestBody WebhookSendIn throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "there should be ruleId and webhookIdto insert webhookSendInfo"); } String webhookSendInfoId = webhookSendInfoService.insertWebhookSendInfo(webhookSendInfo); - return ResponseEntity.ok(new WebhookSendInfoResponse("SUCCESS", webhookSendInfoId)); + return new WebhookSendInfoResponse("SUCCESS", webhookSendInfoId); } @DeleteMapping() - public ResponseEntity deleteWebhookSendInfo(@RequestBody WebhookSendInfo webhookSendInfo) { + public Response deleteWebhookSendInfo(@RequestBody WebhookSendInfo webhookSendInfo) { if (!webhookEnable) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "webhook function is disabled"); } @@ -80,7 +79,7 @@ public Object getWebhookSendInfo(@RequestParam(value=WEBHOOK_ID, required=false) } @PutMapping() - public ResponseEntity updateWebhookSendInfo(@RequestBody WebhookSendInfo webhookSendInfo) { + public Response updateWebhookSendInfo(@RequestBody WebhookSendInfo webhookSendInfo) { if (!webhookEnable) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "webhook function is disabled"); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/response/CodeResult.java b/web/src/main/java/com/navercorp/pinpoint/web/response/CodeResult.java index 937d8d5d5802..ee52e29375ce 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/response/CodeResult.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/response/CodeResult.java @@ -17,9 +17,6 @@ package com.navercorp.pinpoint.web.response; import com.fasterxml.jackson.annotation.JsonInclude; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.server.ResponseStatusException; /** * @author Taejin Koo @@ -34,8 +31,8 @@ public class CodeResult { private final int code; private final Object message; - public static ResponseEntity ok(Object message) { - return ResponseEntity.ok(new CodeResult(CODE_SUCCESS, message)); + public static CodeResult ok(Object message) { + return new CodeResult(CODE_SUCCESS, message); } public CodeResult(int code) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/response/SuccessResponse.java b/web/src/main/java/com/navercorp/pinpoint/web/response/SuccessResponse.java index 656008e8441c..834a4a12cfb8 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/response/SuccessResponse.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/response/SuccessResponse.java @@ -1,7 +1,6 @@ package com.navercorp.pinpoint.web.response; import com.fasterxml.jackson.annotation.JsonInclude; -import org.springframework.http.ResponseEntity; import java.util.Objects; @@ -9,12 +8,12 @@ public class SuccessResponse implements Response { private final String result; private final String message; - public static ResponseEntity ok() { - return ResponseEntity.ok(new SuccessResponse("SUCCESS")); + public static Response ok() { + return new SuccessResponse("SUCCESS"); } - public static ResponseEntity ok(String message) { - return ResponseEntity.ok(new SuccessResponse("SUCCESS", message)); + public static Response ok(String message) { + return new SuccessResponse("SUCCESS", message); } public SuccessResponse(String result) { 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 new file mode 100644 index 000000000000..83b833743af0 --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/AlarmResponseTest.java @@ -0,0 +1,26 @@ +package com.navercorp.pinpoint.web.response; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.TextNode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class AlarmResponseTest { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testCreatedMessage() throws JsonProcessingException { + AlarmResponse result = new AlarmResponse("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.assertNull(jsonNode.get("message")); + Assertions.assertEquals(TextNode.valueOf("12345"), jsonNode.get("ruleId")); + } +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/CodeResultTest.java b/web/src/test/java/com/navercorp/pinpoint/web/response/CodeResultTest.java similarity index 66% rename from web/src/test/java/com/navercorp/pinpoint/web/vo/CodeResultTest.java rename to web/src/test/java/com/navercorp/pinpoint/web/response/CodeResultTest.java index 5f00715ed210..a95bdaa6be05 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/CodeResultTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/CodeResultTest.java @@ -1,9 +1,8 @@ -package com.navercorp.pinpoint.web.vo; +package com.navercorp.pinpoint.web.response; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.navercorp.pinpoint.web.response.CodeResult; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Assertions; @@ -18,10 +17,18 @@ public class CodeResultTest { @Test public void getMessage_NON_NULL() throws JsonProcessingException { CodeResult result = new CodeResult(1); + checkOutput(result); + } - String jsonString = mapper.writeValueAsString(result); - JsonNode jsonNode = mapper.readTree(jsonString); + @Test + public void getMessage_static() throws JsonProcessingException{ + CodeResult result = CodeResult.ok("test message"); + checkOutput(result); + } + private void checkOutput(CodeResult codeResult) throws JsonProcessingException { + String jsonString = mapper.writeValueAsString(codeResult); + JsonNode jsonNode = mapper.readTree(jsonString); Assertions.assertNotNull(jsonNode.get("code")); Assertions.assertNull(jsonNode.get("result")); } 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 new file mode 100644 index 000000000000..9cecfba2ddb2 --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/CreateUserGroupResponseTest.java @@ -0,0 +1,26 @@ +package com.navercorp.pinpoint.web.response; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.TextNode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class CreateUserGroupResponseTest { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testCreatedMessage() throws JsonProcessingException { + CreateUserGroupResponse result = new CreateUserGroupResponse("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.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/SuccessResponseTest.java new file mode 100644 index 000000000000..443dc76d994a --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/SuccessResponseTest.java @@ -0,0 +1,34 @@ +package com.navercorp.pinpoint.web.response; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.TextNode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SuccessResponseTest { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testStaticOk() throws JsonProcessingException { + Response result = SuccessResponse.ok();; + JsonNode jsonNode = checkOutput(result); + Assertions.assertEquals(TextNode.valueOf("SUCCESS"), jsonNode.get("result")); + Assertions.assertNull(jsonNode.get("message")); + } + + @Test + public void testStaticOkWithMessage() throws JsonProcessingException { + Response result = SuccessResponse.ok("Test Message");; + checkOutput(result); + JsonNode jsonNode = checkOutput(result); + Assertions.assertEquals(TextNode.valueOf("SUCCESS"), jsonNode.get("result")); + Assertions.assertEquals(TextNode.valueOf("Test Message"), jsonNode.get("message")); + } + + private JsonNode checkOutput(Response codeResult) throws JsonProcessingException { + String jsonString = mapper.writeValueAsString(codeResult); + return mapper.readTree(jsonString); + } +} 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 new file mode 100644 index 000000000000..09be09b2557a --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookResponseTest.java @@ -0,0 +1,28 @@ +package com.navercorp.pinpoint.web.response; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.TextNode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class WebhookResponseTest { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testCreatedMessage() throws JsonProcessingException { + WebhookResponse result = new WebhookResponse("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.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 new file mode 100644 index 000000000000..408647916cb6 --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/response/WebhookSendInfoResponseTest.java @@ -0,0 +1,28 @@ +package com.navercorp.pinpoint.web.response; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.TextNode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class WebhookSendInfoResponseTest { + private final ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testCreatedMessage() throws JsonProcessingException { + WebhookSendInfoResponse result = new WebhookSendInfoResponse("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.assertNull(jsonNode.get("message")); + Assertions.assertEquals(TextNode.valueOf("12345"), jsonNode.get("webhookSendInfoId")); + } + + +}