Skip to content

Commit

Permalink
[#noissue] Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Jul 5, 2022
1 parent f9c803a commit 916ccd0
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}


}
Original file line number Diff line number Diff line change
@@ -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"));
}


}

0 comments on commit 916ccd0

Please # to comment.