From 62afa0c6a134f073ac42f22bf844bd4f20bbb164 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Wed, 13 Apr 2022 18:21:04 +0900 Subject: [PATCH 01/29] =?UTF-8?q?feat:=20SkillData=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EB=B0=8F=20SkillResponse=20Builder=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * JsonInclude를 이용하여 null인 값은 serialize되지 않도록 구현 --- .../skill/response/SKillResponseBuilder.java | 37 +++++++++++++ .../skill/response/SkillData.java | 41 -------------- .../skill/response/SkillDataBuilder.java | 22 -------- .../skill/response/SkillResponse.java | 55 +++++++++++++++++++ .../response/context/ContextControl.java | 8 +++ .../skill/response/template/Template.java | 8 +++ .../skill/response/SkillDataTest.java | 8 +-- 7 files changed, 112 insertions(+), 67 deletions(-) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java delete mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillData.java delete mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataBuilder.java create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/context/ContextControl.java create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java new file mode 100644 index 0000000..a84a09a --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java @@ -0,0 +1,37 @@ +package dev.mini.kakaoiopenbuilder.skill.response; + +import dev.mini.kakaoiopenbuilder.skill.response.context.ContextControl; +import dev.mini.kakaoiopenbuilder.skill.response.template.Template; + +import java.util.HashMap; +import java.util.Map; + +public class SKillResponseBuilder { + private Template template; + private ContextControl context; + private Map data = new HashMap<>(); + + static public SKillResponseBuilder builder() { + return new SKillResponseBuilder(); + } + + public SKillResponseBuilder addTemplate(Template template) { + this.template = template; + return this; + } + + public SKillResponseBuilder addContextControl(ContextControl context) { + this.context = context; + return this; + } + + public SKillResponseBuilder addData(String key, String value) { + data.put(key, value); + return this; + } + + public SkillResponse build() { + return new SkillResponse(template, context, data); + } + +} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillData.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillData.java deleted file mode 100644 index e1256c3..0000000 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillData.java +++ /dev/null @@ -1,41 +0,0 @@ -package dev.mini.kakaoiopenbuilder.skill.response; - -import java.util.Map; -import java.util.Objects; - -public class SkillData extends SkillResponse { - private Map data; - - public SkillData() { - - } - - public SkillData(Map data) { - this.data = data; - } - - public Map getData() { - return data; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SkillData that = (SkillData) o; - return Objects.equals(data, that.data); - } - - @Override - public int hashCode() { - return Objects.hash(data); - } - - @Override - public String toString() { - return "SkillData{" + - "version=" + super.getVersion() + "," + - "data=" + data + - '}'; - } -} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataBuilder.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataBuilder.java deleted file mode 100644 index a32b2ef..0000000 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataBuilder.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.mini.kakaoiopenbuilder.skill.response; - -import java.util.HashMap; -import java.util.Map; - -public class SkillDataBuilder { - private Map data = new HashMap<>(); - - public static SkillDataBuilder builder() { - return new SkillDataBuilder(); - } - - public SkillDataBuilder addData(String key, String value) { - data.put(key, value); - return this; - } - - public SkillData build() { - return new SkillData(data); - } - -} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java index 32bbede..b5b4dcd 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java @@ -1,10 +1,65 @@ package dev.mini.kakaoiopenbuilder.skill.response; +import com.fasterxml.jackson.annotation.JsonInclude; +import dev.mini.kakaoiopenbuilder.skill.response.context.ContextControl; +import dev.mini.kakaoiopenbuilder.skill.response.template.Template; + +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_NULL) public class SkillResponse { private String version = "2.0"; + private Template template; + private ContextControl context; + private Map data; + + public SkillResponse() { + + } + + public SkillResponse(Template template, ContextControl context, Map data) { + this.template = template; + this.context = context; + this.data = data; + } public String getVersion() { return version; } + public Template getTemplate() { + return template; + } + + public ContextControl getContext() { + return context; + } + + public Map getData() { + return data; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SkillResponse response = (SkillResponse) o; + return Objects.equals(version, response.version) && Objects.equals(template, response.template) && Objects.equals(context, response.context) && Objects.equals(data, response.data); + } + + @Override + public int hashCode() { + return Objects.hash(version, template, context, data); + } + + @Override + public String toString() { + return "SkillResponse{" + + "version='" + version + '\'' + + ", template=" + template + + ", context=" + context + + ", data=" + data + + '}'; + } } \ No newline at end of file diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/context/ContextControl.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/context/ContextControl.java new file mode 100644 index 0000000..58583e7 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/context/ContextControl.java @@ -0,0 +1,8 @@ +package dev.mini.kakaoiopenbuilder.skill.response.context; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ContextControl { + +} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java new file mode 100644 index 0000000..c6a3478 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java @@ -0,0 +1,8 @@ +package dev.mini.kakaoiopenbuilder.skill.response.template; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Template { + +} diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java index e1e8b5b..b4563e1 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java @@ -14,7 +14,7 @@ class SkillDataTest { private static final String SKILL_RESPONSE_DATA_TEST_FILE_PATH = "testResources/skill_response_data.json"; - private SkillData skillData; + private SkillResponse skillData; @BeforeEach public void setUp() throws IOException { @@ -25,10 +25,10 @@ public void setUp() throws IOException { @DisplayName("SkillData 포맷이 동일한지 검증한다.") void skillDataValidTest() { // given - SkillData actual = skillData; + SkillResponse actual = skillData; // when - SkillData expected = SkillDataBuilder.builder() + SkillResponse expected = SKillResponseBuilder.builder() .addData("msg","HI") .addData("name","Ryan") .addData("position","Senior Managing Director") @@ -42,7 +42,7 @@ private void loadSkillResponseDataJson() throws IOException { ObjectMapper objectMapper = new ObjectMapper(); try(InputStream fileStream = new FileInputStream(SKILL_RESPONSE_DATA_TEST_FILE_PATH)) { - skillData = objectMapper.readValue(fileStream, SkillData.class); + skillData = objectMapper.readValue(fileStream, SkillResponse.class); } } From 64094332f269f1c8a1d1fe97d331b152c2f5236a Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Wed, 13 Apr 2022 18:55:49 +0900 Subject: [PATCH 02/29] =?UTF-8?q?refactor:=20SkillResponse=20Data=20?= =?UTF-8?q?=EB=A6=AC=ED=8E=99=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * addData를key, value 또는 map으로 넣을 수 있게 변경 --- .../mini/kakaoiopenbuilder/skill/Main.java | 25 ++++++++++++++++++- .../skill/response/SKillResponseBuilder.java | 7 +++++- .../skill/response/SkillDataTest.java | 9 +++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java index 0668f67..62b8657 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java @@ -1,8 +1,31 @@ package dev.mini.kakaoiopenbuilder.skill; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import dev.mini.kakaoiopenbuilder.skill.response.SKillResponseBuilder; +import dev.mini.kakaoiopenbuilder.skill.response.SkillResponse; + +import java.util.HashMap; +import java.util.Map; + public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + System.out.println("Hello Kakao I OpenBuilder Java Library!"); + + // example: SkillResponse Data + Map dataMap = new HashMap(){{ + put("msg","HI"); + put("name","Ryan"); + put("position","Senior Managing Director"); + }}; + + SkillResponse skillResponse = SKillResponseBuilder.builder() + .addData(dataMap) + .build(); + + System.out.println("Skill Response Data example: " + objectMapper.writeValueAsString(skillResponse)); } } \ No newline at end of file diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java index a84a09a..9ee3441 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java @@ -26,7 +26,12 @@ public SKillResponseBuilder addContextControl(ContextControl context) { } public SKillResponseBuilder addData(String key, String value) { - data.put(key, value); + this.data.put(key, value); + return this; + } + + public SKillResponseBuilder addData(Map data) { + this.data.putAll(data); return this; } diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java index b4563e1..a5d51be 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java @@ -8,6 +8,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -26,12 +28,15 @@ public void setUp() throws IOException { void skillDataValidTest() { // given SkillResponse actual = skillData; + Map dataMap = new HashMap(){{ + put("name","Ryan"); + put("position","Senior Managing Director"); + }}; // when SkillResponse expected = SKillResponseBuilder.builder() .addData("msg","HI") - .addData("name","Ryan") - .addData("position","Senior Managing Director") + .addData(dataMap) .build(); // that From 84b227f6ecc386394474200880cf39c1aea34577 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Wed, 13 Apr 2022 19:14:07 +0900 Subject: [PATCH 03/29] =?UTF-8?q?refactor:=20SkillResponse=EC=9D=98=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=A5=BC=20final=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mini/kakaoiopenbuilder/skill/Main.java | 12 +++++----- .../skill/response/SkillResponse.java | 22 +++++++++++-------- .../skill/response/SkillDataTest.java | 7 +++--- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java index 62b8657..3d90a73 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java @@ -15,17 +15,17 @@ public static void main(String[] args) throws JsonProcessingException { System.out.println("Hello Kakao I OpenBuilder Java Library!"); // example: SkillResponse Data - Map dataMap = new HashMap(){{ - put("msg","HI"); - put("name","Ryan"); - put("position","Senior Managing Director"); - }}; + Map dataMap = new HashMap(); + dataMap.put("name","Ryan"); + dataMap.put("position","Senior Managing Director"); SkillResponse skillResponse = SKillResponseBuilder.builder() + .addData("msg","HI") .addData(dataMap) .build(); - System.out.println("Skill Response Data example: " + objectMapper.writeValueAsString(skillResponse)); + System.out.println("Skill Response Data example"); + System.out.println(objectMapper.writeValueAsString(skillResponse)); } } \ No newline at end of file diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java index b5b4dcd..9f16eca 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java @@ -1,6 +1,8 @@ package dev.mini.kakaoiopenbuilder.skill.response; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import dev.mini.kakaoiopenbuilder.skill.response.context.ContextControl; import dev.mini.kakaoiopenbuilder.skill.response.template.Template; @@ -9,16 +11,18 @@ @JsonInclude(JsonInclude.Include.NON_NULL) public class SkillResponse { - private String version = "2.0"; - private Template template; - private ContextControl context; - private Map data; + private final String version; + private final Template template; + private final ContextControl context; + private final Map data; - public SkillResponse() { - - } - - public SkillResponse(Template template, ContextControl context, Map data) { + @JsonCreator + public SkillResponse( + @JsonProperty("template") Template template, + @JsonProperty("context") ContextControl context, + @JsonProperty("data") Map data + ) { + this.version = "2.0"; this.template = template; this.context = context; this.data = data; diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java index a5d51be..4171598 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java @@ -28,10 +28,9 @@ public void setUp() throws IOException { void skillDataValidTest() { // given SkillResponse actual = skillData; - Map dataMap = new HashMap(){{ - put("name","Ryan"); - put("position","Senior Managing Director"); - }}; + Map dataMap = new HashMap<>(); + dataMap.put("name","Ryan"); + dataMap.put("position","Senior Managing Director"); // when SkillResponse expected = SKillResponseBuilder.builder() From 045745201f10320369aadb5d617400541fe1b428 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Fri, 15 Apr 2022 15:18:46 +0900 Subject: [PATCH 04/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20SimpleText=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20[#49]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Template빌더를 통해 SimpleText를 추가할 수 있도록 구현 --- .../skill/response/SkillResponse.java | 2 +- .../skill/response/component/Component.java | 17 ++++++++ .../skill/response/component/SimpleText.java | 40 ++++++++++++++++++ .../skill/response/template/Output.java | 37 ++++++++++++++++ .../skill/response/template/Template.java | 39 ++++++++++++++++- .../response/template/TemplateBuilder.java | 24 +++++++++++ .../skill/response/SkillResponseTest.java | 42 +++++++++++++++++++ testResources/skill_response_simple_text.json | 12 ++++++ 8 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/Component.java create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Output.java create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java create mode 100644 src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java create mode 100644 testResources/skill_response_simple_text.json diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java index 9f16eca..9180217 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java @@ -9,7 +9,7 @@ import java.util.Map; import java.util.Objects; -@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class SkillResponse { private final String version; private final Template template; diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/Component.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/Component.java new file mode 100644 index 0000000..bcc163c --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/Component.java @@ -0,0 +1,17 @@ +package dev.mini.kakaoiopenbuilder.skill.response.component; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "type", + defaultImpl = SimpleText.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = SimpleText.class, name = "simpleText"), +}) +public interface Component { + +} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java new file mode 100644 index 0000000..d3dc780 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java @@ -0,0 +1,40 @@ +package dev.mini.kakaoiopenbuilder.skill.response.component; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +public class SimpleText implements Component { + private String text; + + @JsonCreator + public SimpleText(@JsonProperty("text") String text) { + this.text = text; + } + + public String getText() { + return text; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SimpleText that = (SimpleText) o; + return Objects.equals(text, that.text); + } + + @Override + public int hashCode() { + return Objects.hash(text); + } + + @Override + public String toString() { + return "SimpleText{" + + "text='" + text + '\'' + + '}'; + } + +} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Output.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Output.java new file mode 100644 index 0000000..428af5e --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Output.java @@ -0,0 +1,37 @@ +package dev.mini.kakaoiopenbuilder.skill.response.template; + +import com.fasterxml.jackson.annotation.*; +import dev.mini.kakaoiopenbuilder.skill.response.component.Component; + +import java.util.Collections; +import java.util.Map; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class Output { + private Map component; + + @JsonCreator + public Output( + @JsonProperty("key") String key, + @JsonProperty("value") Component value) { + this.component = Collections.singletonMap(key, value); + } + + @JsonAnySetter + public void setComponents(String key, Component value) { + this.component = Collections.singletonMap(key, value); + } + + @JsonAnyGetter + public Map getComponent() { + return component; + } + + @Override + public String toString() { + return "Output{" + + "component=" + component + + '}'; + } + +} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java index c6a3478..952dd74 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java @@ -1,8 +1,45 @@ package dev.mini.kakaoiopenbuilder.skill.response.template; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; -@JsonInclude(JsonInclude.Include.NON_NULL) +import java.util.List; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class Template { + private final List output; + + @JsonCreator + public Template( + @JsonProperty("outputs") List output + ) { + this.output = output; + } + + public List getOutputs() { + return output; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Template template = (Template) o; + return Objects.equals(output, template.output); + } + + @Override + public int hashCode() { + return Objects.hash(output); + } + + @Override + public String toString() { + return "Template{" + + "output=" + output + + '}'; + } } diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java new file mode 100644 index 0000000..164473f --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java @@ -0,0 +1,24 @@ +package dev.mini.kakaoiopenbuilder.skill.response.template; + +import dev.mini.kakaoiopenbuilder.skill.response.component.SimpleText; + +import java.util.ArrayList; +import java.util.List; + +public class TemplateBuilder { + private List output = new ArrayList<>(); + + public static TemplateBuilder builder() { + return new TemplateBuilder(); + } + + public TemplateBuilder addSimpleText(String text) { + output.add(new Output("simpleText", new SimpleText(text))); + return this; + } + + public Template build() { + return new Template(output); + } + +} diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java new file mode 100644 index 0000000..694e430 --- /dev/null +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java @@ -0,0 +1,42 @@ +package dev.mini.kakaoiopenbuilder.skill.response; + +import com.fasterxml.jackson.databind.ObjectMapper; +import dev.mini.kakaoiopenbuilder.skill.response.template.Template; +import dev.mini.kakaoiopenbuilder.skill.response.template.TemplateBuilder; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import static org.assertj.core.api.Assertions.assertThat; + +class SkillResponseTest { + + private static final String SKILL_SIMPLE_TEXT_FILE_PATH = "testResources/skill_response_simple_text.json"; + + @Test + @DisplayName("SimpleText 포맷이 동일한지 검증한다.") + void validSimpleText() throws IOException { + // given + Template actual = loadSkillResponseTemplateJson(SKILL_SIMPLE_TEXT_FILE_PATH).getTemplate(); + + // when + Template expected = TemplateBuilder.builder() + .addSimpleText("간단한 텍스트 요소입니다.") + .build(); + + // that + assertThat(actual.toString()).isEqualTo(expected.toString()); + } + + private SkillResponse loadSkillResponseTemplateJson(String filePath) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + + try(InputStream fileStream = new FileInputStream(filePath)) { + return objectMapper.readValue(fileStream, SkillResponse.class); + } + } + +} diff --git a/testResources/skill_response_simple_text.json b/testResources/skill_response_simple_text.json new file mode 100644 index 0000000..f8efe8e --- /dev/null +++ b/testResources/skill_response_simple_text.json @@ -0,0 +1,12 @@ +{ + "version": "2.0", + "template": { + "outputs": [ + { + "simpleText": { + "text": "간단한 텍스트 요소입니다." + } + } + ] + } +} \ No newline at end of file From 17ff7654c6846c4edcc88ec2f186cb6a6339d984 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Fri, 15 Apr 2022 16:12:16 +0900 Subject: [PATCH 05/29] =?UTF-8?q?refactor:=20equals=20and=20hashcode=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 근거: Effective Java 10장 equals는 일반 규약을 지켜 재정의하라: equals는 필요하지 않은 상황에서는 재정의하지 않는것이 최선이다. * 사유 1. 테스트 코드에서만 equals를 사용하고 있다. 2. equals와 hashcode가 해당 라이브러리를 사용하고 있는 클라이언트에서 사용될 필요성이 없다. 3. 인스턴스의 논리적 동치성을 검사할 이유가 없다 --- .../skill/payload/SkillPayload.java | 17 +---------------- .../skill/payload/action/Action.java | 14 -------------- .../skill/payload/action/DetailParams.java | 15 --------------- .../skill/payload/bot/Bot.java | 15 --------------- .../skill/payload/intent/Extra.java | 15 --------------- .../skill/payload/intent/Intent.java | 15 --------------- .../skill/payload/intent/Knowledge.java | 14 -------------- .../skill/payload/intent/MatchedKnowledges.java | 14 -------------- .../skill/payload/intent/Reason.java | 15 --------------- .../skill/payload/userrequest/Block.java | 15 --------------- .../skill/payload/userrequest/Params.java | 15 --------------- .../skill/payload/userrequest/Properties.java | 15 --------------- .../skill/payload/userrequest/User.java | 15 --------------- .../skill/payload/userrequest/UserRequest.java | 15 --------------- .../skill/response/SkillResponse.java | 14 -------------- .../skill/response/component/SimpleText.java | 15 --------------- .../skill/response/template/Template.java | 14 -------------- .../skill/payload/SkillPayloadTest.java | 14 +++++++------- .../skill/response/SkillDataTest.java | 2 +- .../skill/response/SkillResponseTest.java | 2 +- 20 files changed, 10 insertions(+), 260 deletions(-) diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayload.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayload.java index 8d714ae..0da0475 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayload.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayload.java @@ -4,12 +4,10 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import dev.mini.kakaoiopenbuilder.skill.payload.action.Action; -import dev.mini.kakaoiopenbuilder.skill.payload.intent.Intent; import dev.mini.kakaoiopenbuilder.skill.payload.bot.Bot; +import dev.mini.kakaoiopenbuilder.skill.payload.intent.Intent; import dev.mini.kakaoiopenbuilder.skill.payload.userrequest.UserRequest; -import java.util.Objects; - public class SkillPayload { private Bot bot; private Intent intent; @@ -32,19 +30,6 @@ public UserRequest getUserRequest() { return userRequest; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SkillPayload that = (SkillPayload) o; - return Objects.equals(bot, that.bot) && Objects.equals(intent, that.intent) && Objects.equals(action, that.action) && Objects.equals(userRequest, that.userRequest); - } - - @Override - public int hashCode() { - return Objects.hash(bot, intent, action, userRequest); - } - @Override public String toString() { return "SkillPayload{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/action/Action.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/action/Action.java index cc5a325..5036be5 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/action/Action.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/action/Action.java @@ -1,7 +1,6 @@ package dev.mini.kakaoiopenbuilder.skill.payload.action; import java.util.Map; -import java.util.Objects; public class Action { private String id; @@ -30,19 +29,6 @@ public Map getClientExtra() { return clientExtra; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Action action = (Action) o; - return Objects.equals(id, action.id) && Objects.equals(name, action.name) && Objects.equals(params, action.params) && Objects.equals(detailParams, action.detailParams) && Objects.equals(clientExtra, action.clientExtra); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, params, detailParams, clientExtra); - } - @Override public String toString() { return "Action{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/action/DetailParams.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/action/DetailParams.java index c064fe3..568f3dd 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/action/DetailParams.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/action/DetailParams.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.action; -import java.util.Objects; - public class DetailParams { private String origin; private String value; @@ -19,19 +17,6 @@ public String getGroupName() { return groupName; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - DetailParams that = (DetailParams) o; - return Objects.equals(origin, that.origin) && Objects.equals(value, that.value) && Objects.equals(groupName, that.groupName); - } - - @Override - public int hashCode() { - return Objects.hash(origin, value, groupName); - } - @Override public String toString() { return "DetailParams{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/bot/Bot.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/bot/Bot.java index 6e15ae1..175e281 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/bot/Bot.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/bot/Bot.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.bot; -import java.util.Objects; - public class Bot { private String id; private String name; @@ -14,19 +12,6 @@ public String getName() { return name; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Bot bot = (Bot) o; - return Objects.equals(id, bot.id) && Objects.equals(name, bot.name); - } - - @Override - public int hashCode() { - return Objects.hash(id, name); - } - @Override public String toString() { return "Bot{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Extra.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Extra.java index 264b286..e28af2e 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Extra.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Extra.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.intent; -import java.util.Objects; - public class Extra { private Reason reason; private Knowledge knowledge; @@ -14,19 +12,6 @@ public Knowledge getKnowledge() { return knowledge; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Extra extra = (Extra) o; - return Objects.equals(reason, extra.reason) && Objects.equals(knowledge, extra.knowledge); - } - - @Override - public int hashCode() { - return Objects.hash(reason, knowledge); - } - @Override public String toString() { return "Extra{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Intent.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Intent.java index d817c4b..644eac1 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Intent.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Intent.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.intent; -import java.util.Objects; - public class Intent { private String id; private String name; @@ -19,19 +17,6 @@ public Extra getExtra() { return extra; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Intent intent = (Intent) o; - return Objects.equals(id, intent.id) && Objects.equals(name, intent.name) && Objects.equals(extra, intent.extra); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, extra); - } - @Override public String toString() { return "Intent{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Knowledge.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Knowledge.java index c9a953e..3c7e408 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Knowledge.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Knowledge.java @@ -1,7 +1,6 @@ package dev.mini.kakaoiopenbuilder.skill.payload.intent; import java.util.List; -import java.util.Objects; public class Knowledge { private String responseType; @@ -15,19 +14,6 @@ public List getMatchedKnowledges() { return matchedKnowledges; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Knowledge knowledge = (Knowledge) o; - return Objects.equals(responseType, knowledge.responseType) && Objects.equals(matchedKnowledges, knowledge.matchedKnowledges); - } - - @Override - public int hashCode() { - return Objects.hash(responseType, matchedKnowledges); - } - @Override public String toString() { return "Knowledge{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/MatchedKnowledges.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/MatchedKnowledges.java index fe5482a..a60e219 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/MatchedKnowledges.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/MatchedKnowledges.java @@ -1,7 +1,6 @@ package dev.mini.kakaoiopenbuilder.skill.payload.intent; import java.util.List; -import java.util.Objects; public class MatchedKnowledges { private List categories; @@ -30,19 +29,6 @@ public String getLandingUrl() { return landingUrl; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MatchedKnowledges that = (MatchedKnowledges) o; - return Objects.equals(categories, that.categories) && Objects.equals(question, that.question) && Objects.equals(answer, that.answer) && Objects.equals(imageUrl, that.imageUrl) && Objects.equals(landingUrl, that.landingUrl); - } - - @Override - public int hashCode() { - return Objects.hash(categories, question, answer, imageUrl, landingUrl); - } - @Override public String toString() { return "MatchedKnowledges{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Reason.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Reason.java index d0b9178..1e5a3f0 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Reason.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/intent/Reason.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.intent; -import java.util.Objects; - public class Reason { private String code; private String message; @@ -14,19 +12,6 @@ public String getMessage() { return message; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Reason reason = (Reason) o; - return Objects.equals(code, reason.code) && Objects.equals(message, reason.message); - } - - @Override - public int hashCode() { - return Objects.hash(code, message); - } - @Override public String toString() { return "Reason{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Block.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Block.java index 81160b6..4360cb8 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Block.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Block.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.userrequest; -import java.util.Objects; - public class Block { private String id; private String name; @@ -14,19 +12,6 @@ public String getName() { return name; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Block block = (Block) o; - return Objects.equals(id, block.id) && Objects.equals(name, block.name); - } - - @Override - public int hashCode() { - return Objects.hash(id, name); - } - @Override public String toString() { return "Block{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Params.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Params.java index 29e9fe9..aff8166 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Params.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Params.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.userrequest; -import java.util.Objects; - public class Params { private String surface; private String ignoreMe; @@ -14,19 +12,6 @@ public String getIgnoreMe() { return ignoreMe; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Params params = (Params) o; - return Objects.equals(surface, params.surface) && Objects.equals(ignoreMe, params.ignoreMe); - } - - @Override - public int hashCode() { - return Objects.hash(surface, ignoreMe); - } - @Override public String toString() { return "Params{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Properties.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Properties.java index a4d8c6d..6b6308b 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Properties.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/Properties.java @@ -3,8 +3,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Objects; - @JsonIgnoreProperties(value = "friend") public class Properties { private String plusfriendUserKey; @@ -25,19 +23,6 @@ public boolean isFriend() { return isFriend; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Properties that = (Properties) o; - return isFriend == that.isFriend && Objects.equals(plusfriendUserKey, that.plusfriendUserKey) && Objects.equals(appUserId, that.appUserId); - } - - @Override - public int hashCode() { - return Objects.hash(plusfriendUserKey, appUserId, isFriend); - } - @Override public String toString() { return "Properties{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/User.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/User.java index 7c35360..21b403a 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/User.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/User.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.userrequest; -import java.util.Objects; - public class User { private String id; private String type; @@ -19,19 +17,6 @@ public Properties getProperties() { return properties; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - User user = (User) o; - return Objects.equals(id, user.id) && Objects.equals(type, user.type) && Objects.equals(properties, user.properties); - } - - @Override - public int hashCode() { - return Objects.hash(id, type, properties); - } - @Override public String toString() { return "User{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/UserRequest.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/UserRequest.java index 2c2c380..600864d 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/UserRequest.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/payload/userrequest/UserRequest.java @@ -1,7 +1,5 @@ package dev.mini.kakaoiopenbuilder.skill.payload.userrequest; -import java.util.Objects; - public class UserRequest { private String timezone; private Block block; @@ -34,19 +32,6 @@ public User getUser() { return user; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - UserRequest that = (UserRequest) o; - return Objects.equals(timezone, that.timezone) && Objects.equals(block, that.block) && Objects.equals(utterance, that.utterance) && Objects.equals(params, that.params) && Objects.equals(lang, that.lang) && Objects.equals(user, that.user); - } - - @Override - public int hashCode() { - return Objects.hash(timezone, block, utterance, params, lang, user); - } - @Override public String toString() { return "UserRequest{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java index 9180217..baa4c06 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponse.java @@ -7,7 +7,6 @@ import dev.mini.kakaoiopenbuilder.skill.response.template.Template; import java.util.Map; -import java.util.Objects; @JsonInclude(JsonInclude.Include.NON_EMPTY) public class SkillResponse { @@ -44,19 +43,6 @@ public Map getData() { return data; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SkillResponse response = (SkillResponse) o; - return Objects.equals(version, response.version) && Objects.equals(template, response.template) && Objects.equals(context, response.context) && Objects.equals(data, response.data); - } - - @Override - public int hashCode() { - return Objects.hash(version, template, context, data); - } - @Override public String toString() { return "SkillResponse{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java index d3dc780..73604d3 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java @@ -3,8 +3,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Objects; - public class SimpleText implements Component { private String text; @@ -17,19 +15,6 @@ public String getText() { return text; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SimpleText that = (SimpleText) o; - return Objects.equals(text, that.text); - } - - @Override - public int hashCode() { - return Objects.hash(text); - } - @Override public String toString() { return "SimpleText{" + diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java index 952dd74..3b3e1c2 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/Template.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; -import java.util.Objects; @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Template { @@ -22,19 +21,6 @@ public List getOutputs() { return output; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Template template = (Template) o; - return Objects.equals(output, template.output); - } - - @Override - public int hashCode() { - return Objects.hash(output); - } - @Override public String toString() { return "Template{" + diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayloadTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayloadTest.java index b26678e..76869c1 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayloadTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayloadTest.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import dev.mini.kakaoiopenbuilder.skill.payload.intent.Intent; +import dev.mini.kakaoiopenbuilder.skill.payload.action.Action; import dev.mini.kakaoiopenbuilder.skill.payload.bot.Bot; +import dev.mini.kakaoiopenbuilder.skill.payload.intent.Intent; import dev.mini.kakaoiopenbuilder.skill.payload.userrequest.UserRequest; -import dev.mini.kakaoiopenbuilder.skill.payload.action.Action; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -42,7 +42,7 @@ void skillPayloadValidTest() throws JsonProcessingException { // that assertAll( () -> assertThat(json).doesNotContain("null"), - () -> assertThat(actual).isEqualTo(expected) + () -> assertThat(actual.toString()).hasToString(expected.toString()) ); } @@ -60,7 +60,7 @@ void userRequestValidTest() throws JsonProcessingException { // that assertAll( () -> assertThat(json).doesNotContain("null"), - () -> assertThat(actual).isEqualTo(expected) + () -> assertThat(actual.toString()).hasToString(expected.toString()) ); } @@ -78,7 +78,7 @@ void botValidTest() throws JsonProcessingException { // that assertAll( () -> assertThat(json).doesNotContain("null"), - () -> assertThat(actual).isEqualTo(expected) + () -> assertThat(actual.toString()).hasToString(expected.toString()) ); } @@ -96,7 +96,7 @@ void intentValidTest() throws JsonProcessingException { // that assertAll( () -> assertThat(json).doesNotContain("null"), - () -> assertThat(actual).isEqualTo(expected) + () -> assertThat(actual.toString()).hasToString(expected.toString()) ); } @@ -114,7 +114,7 @@ void actionValidTest() throws JsonProcessingException { // that assertAll( () -> assertThat(json).doesNotContain("null"), - () -> assertThat(actual).isEqualTo(expected) + () -> assertThat(actual.toString()).hasToString(expected.toString()) ); } diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java index 4171598..0c9f06e 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillDataTest.java @@ -39,7 +39,7 @@ void skillDataValidTest() { .build(); // that - assertThat(actual).isEqualTo(expected); + assertThat(actual.toString()).hasToString(expected.toString()); } private void loadSkillResponseDataJson() throws IOException { diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java index 694e430..0857042 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java @@ -28,7 +28,7 @@ void validSimpleText() throws IOException { .build(); // that - assertThat(actual.toString()).isEqualTo(expected.toString()); + assertThat(actual.toString()).hasToString(expected.toString()); } private SkillResponse loadSkillResponseTemplateJson(String filePath) throws IOException { From 05648355a776993fdd804ef5a7c7fe4750da3275 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Fri, 15 Apr 2022 16:31:50 +0900 Subject: [PATCH 06/29] =?UTF-8?q?feat:=20JaCoCo=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20Code=20Coverage=20=EC=B8=A1=EC=A0=95=20[#2?= =?UTF-8?q?3]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * LINE 80줄 미만 * BUNDLE, INSTRUCTION 기준 70% 이상 --- pom.xml | 61 +++++++++++++++++++ .../skill/payload/SkillPayloadTest.java | 15 +++++ 2 files changed, 76 insertions(+) diff --git a/pom.xml b/pom.xml index 702f6c6..1b0272a 100644 --- a/pom.xml +++ b/pom.xml @@ -101,6 +101,66 @@ + + + org.jacoco + jacoco-maven-plugin + 0.8.8 + + + XML + HTML + CSV + + + dev/mini/**/Main.class + dev/mini/**/util/*.class + + + + + jacoco-prepare-agent + + prepare-agent + + + + jacoco-report + + report + + + + jacoco-check + + check + + + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + 0.70 + + + METHOD + + + LINE + TOTALCOUNT + 80 + + + + + + + + + org.apache.maven.plugins maven-jar-plugin @@ -116,6 +176,7 @@ + org.apache.maven.plugins maven-assembly-plugin diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayloadTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayloadTest.java index 76869c1..64b78e8 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayloadTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/payload/SkillPayloadTest.java @@ -118,6 +118,21 @@ void actionValidTest() throws JsonProcessingException { ); } + @Test + @DisplayName("parse 메서드를 통해 json 문자열을 SkillPayload 객체로 변환할 수 있다.") + void skillPayloadParse() throws JsonProcessingException { + // given + ObjectMapper objectMapper = new ObjectMapper(); + SkillPayload actual = skillPayload; + + // when + String json = objectMapper.writeValueAsString(actual); + SkillPayload expected = SkillPayload.parse(json); + + // that + assertThat(actual.toString()).hasToString(expected.toString()); + } + private void loadSkillPayloadJson() throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); From b75579cc2af1e4c4fce7cda3ef8ad9040074d925 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Fri, 15 Apr 2022 19:50:34 +0900 Subject: [PATCH 07/29] =?UTF-8?q?chore:=20sonar=20qube=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EA=B0=90=EC=A7=80=EB=90=9C=20code=20smell=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/mini/kakaoiopenbuilder/skill/Main.java | 16 ++++++++++------ .../skill/response/SKillResponseBuilder.java | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java index 3d90a73..8de6be7 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/Main.java @@ -7,15 +7,17 @@ import java.util.HashMap; import java.util.Map; +import java.util.logging.Logger; public class Main { - public static void main(String[] args) throws JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); + private static final Logger log = Logger.getLogger(Main.class.getName()); + private static final ObjectMapper objectMapper = new ObjectMapper(); - System.out.println("Hello Kakao I OpenBuilder Java Library!"); + public static void main(String[] args) throws JsonProcessingException { + log.info("Hello Kakao I OpenBuilder Java Library!"); // example: SkillResponse Data - Map dataMap = new HashMap(); + Map dataMap = new HashMap<>(); dataMap.put("name","Ryan"); dataMap.put("position","Senior Managing Director"); @@ -24,8 +26,10 @@ public static void main(String[] args) throws JsonProcessingException { .addData(dataMap) .build(); - System.out.println("Skill Response Data example"); - System.out.println(objectMapper.writeValueAsString(skillResponse)); + String json = objectMapper.writeValueAsString(skillResponse); + + log.info("Skill Response Data example"); + log.info(json); } } \ No newline at end of file diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java index 9ee3441..dfe574c 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/SKillResponseBuilder.java @@ -11,7 +11,7 @@ public class SKillResponseBuilder { private ContextControl context; private Map data = new HashMap<>(); - static public SKillResponseBuilder builder() { + public static SKillResponseBuilder builder() { return new SKillResponseBuilder(); } From a18e883b207b8dc602c2eafd85e1c34895fa3b89 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Sun, 17 Apr 2022 14:09:14 +0900 Subject: [PATCH 08/29] =?UTF-8?q?feat:=20=EC=B6=9C=EB=A0=A5=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8A=94=20=EC=8A=A4=ED=82=AC=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EB=84=8C=ED=8A=B8=EC=9D=98=20=EA=B0=9C=EC=88=98=20?= =?UTF-8?q?=EC=A0=9C=ED=95=9C=20[#49]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 스킬 컴포넌트의 개수는 1개 이상 3개 이하여야 한다. * 만약 넘거나 모자르다면 ComponentsOutOfBoundsException 발생 --- .../ComponentsOutOfBoundsException.java | 11 ++++++++ .../response/template/TemplateBuilder.java | 8 ++++++ .../skill/response/SkillResponseTest.java | 28 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/exception/ComponentsOutOfBoundsException.java diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/exception/ComponentsOutOfBoundsException.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/exception/ComponentsOutOfBoundsException.java new file mode 100644 index 0000000..225d128 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/exception/ComponentsOutOfBoundsException.java @@ -0,0 +1,11 @@ +package dev.mini.kakaoiopenbuilder.skill.exception; + +public class ComponentsOutOfBoundsException extends IndexOutOfBoundsException { + + private static final String message = "출력할 수 있는 Skill Component의 개수는 1개 이상 3개 이하입니다."; + + public ComponentsOutOfBoundsException() { + super(message); + } + +} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java index 164473f..8d8503a 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java @@ -1,5 +1,6 @@ package dev.mini.kakaoiopenbuilder.skill.response.template; +import dev.mini.kakaoiopenbuilder.skill.exception.ComponentsOutOfBoundsException; import dev.mini.kakaoiopenbuilder.skill.response.component.SimpleText; import java.util.ArrayList; @@ -18,7 +19,14 @@ public TemplateBuilder addSimpleText(String text) { } public Template build() { + isValidComponent(); return new Template(output); } + private void isValidComponent() { + if(output.size() < 1 || output.size() > 3) { + throw new ComponentsOutOfBoundsException(); + } + } + } diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java index 0857042..54fda0d 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java @@ -1,6 +1,7 @@ package dev.mini.kakaoiopenbuilder.skill.response; import com.fasterxml.jackson.databind.ObjectMapper; +import dev.mini.kakaoiopenbuilder.skill.exception.ComponentsOutOfBoundsException; import dev.mini.kakaoiopenbuilder.skill.response.template.Template; import dev.mini.kakaoiopenbuilder.skill.response.template.TemplateBuilder; import org.junit.jupiter.api.DisplayName; @@ -11,11 +12,38 @@ import java.io.InputStream; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class SkillResponseTest { private static final String SKILL_SIMPLE_TEXT_FILE_PATH = "testResources/skill_response_simple_text.json"; + @Test + @DisplayName("출력할 수 있는 Skill Component는 1개 미만일 수 없다.") + void invalidComponentsExceptionWhenZero() { + // given when that + assertThatThrownBy(() -> { + Template template = new TemplateBuilder() + .build(); + }).isInstanceOf(ComponentsOutOfBoundsException.class) + .hasMessage("출력할 수 있는 Skill Component의 개수는 1개 이상 3개 이하입니다."); + } + + @Test + @DisplayName("출력할 수 있는 Skill Component의 개수는 3개 초과일 수 없다.") + void invalidComponentsExceptionWhenExceedsThree() { + // given when that + assertThatThrownBy(() -> { + Template template = new TemplateBuilder() + .addSimpleText("test1") + .addSimpleText("test2") + .addSimpleText("test3") + .addSimpleText("test4") + .build(); + }).isInstanceOf(ComponentsOutOfBoundsException.class) + .hasMessage("출력할 수 있는 Skill Component의 개수는 1개 이상 3개 이하입니다."); + } + @Test @DisplayName("SimpleText 포맷이 동일한지 검증한다.") void validSimpleText() throws IOException { From b38fd484a5efb7acf78c74616825399fc3ed6fe1 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Sun, 17 Apr 2022 14:25:56 +0900 Subject: [PATCH 09/29] =?UTF-8?q?refactor:=20SonarQube=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EA=B0=90=EC=A7=80=EB=90=9C=20Code=20Smell=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skill/exception/ComponentsOutOfBoundsException.java | 4 ++-- .../skill/response/template/TemplateBuilder.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/exception/ComponentsOutOfBoundsException.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/exception/ComponentsOutOfBoundsException.java index 225d128..3cef18d 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/exception/ComponentsOutOfBoundsException.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/exception/ComponentsOutOfBoundsException.java @@ -2,10 +2,10 @@ public class ComponentsOutOfBoundsException extends IndexOutOfBoundsException { - private static final String message = "출력할 수 있는 Skill Component의 개수는 1개 이상 3개 이하입니다."; + private static final String MESSAGE = "출력할 수 있는 Skill Component의 개수는 1개 이상 3개 이하입니다."; public ComponentsOutOfBoundsException() { - super(message); + super(MESSAGE); } } diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java index 8d8503a..a43d13c 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java @@ -24,7 +24,7 @@ public Template build() { } private void isValidComponent() { - if(output.size() < 1 || output.size() > 3) { + if(output.isEmpty() || output.size() > 3) { throw new ComponentsOutOfBoundsException(); } } From 36c21b736bd38aa28ab355ac371b250b672105c4 Mon Sep 17 00:00:00 2001 From: Dongmin Kang Date: Tue, 3 May 2022 15:20:01 +0900 Subject: [PATCH 10/29] Update README.md --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fec467a..61c9e09 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ -# Kakao_ChatBot_Library -카카오 I 오픈빌더 챗봇 라이브러리 입니다. +# Kakao I OpenBuilder Java Library +[![example workflow](https://github.com/Sejong-OSS/Kakao_I_OpenBuilder_Library/actions/workflows/build.yml/badge.svg)](https://github.com/Sejong-OSS/Kakao_I_OpenBuilder_Library/actions/workflows/build.yml) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Sejong-OSS_Kakao_I_OpenBuilder_Library&metric=coverage)](https://sonarcloud.io/summary/new_code?id=Sejong-OSS_Kakao_I_OpenBuilder_Library) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Sejong-OSS_Kakao_I_OpenBuilder_Library&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Sejong-OSS_Kakao_I_OpenBuilder_Library) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Sejong-OSS_Kakao_I_OpenBuilder_Library&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Sejong-OSS_Kakao_I_OpenBuilder_Library) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Sejong-OSS_Kakao_I_OpenBuilder_Library&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Sejong-OSS_Kakao_I_OpenBuilder_Library) + +## Getting Starting +### Maven +```xml + + dev.mini + kakao-i-openbuilder + 1.0.0 + +``` +### Gradle +```groovy +implementation 'dev.mini:kakao-i-openbuilder:1.0.0' +``` From ca7fe0ec2da72d72825af5aa0ac56a371d6a810c Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Wed, 18 May 2022 21:48:56 +0900 Subject: [PATCH 11/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20Link=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20[ossmini#69]=20*=20Link=EB=A5=BC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closed ossmini#69 --- .../skill/response/common/Link.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java new file mode 100644 index 0000000..154a0c5 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java @@ -0,0 +1,43 @@ +package dev.mini.kakaoiopenbuilder.skill.response.common; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Link { + private String pc; + private String mobile; + private String web; + + @JsonCreator + public Link( + @JsonProperty("pc") String pc, + @JsonProperty("mobile") String mobile, + @JsonProperty("web") String web + ) { + this.pc = pc; + this.mobile = mobile; + this.web = web; + } + + public String getPC() { + return pc; + } + + public String getMobile() { + return mobile; + } + + public String getWeb() { + return web; + } + + @Override + public String toString() { + return "Link{" + + "pc='" + pc + '\'' + + "mobile='" + mobile + '\'' + + "web='" + web + '\'' + + '}'; + } + +} \ No newline at end of file From 58eb5e54e37cb0de889ae9ac5373fb6ae55e12db Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Wed, 18 May 2022 21:42:49 +0900 Subject: [PATCH 12/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20Profile=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20[ossmini#68]=20*=20Profile=EC=9D=84=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closed ossmini#68 --- .../skill/response/common/Profile.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java new file mode 100644 index 0000000..19563c2 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java @@ -0,0 +1,35 @@ +package dev.mini.kakaoiopenbuilder.skill.response.common; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Profile { + private String nickname; + private String imageUrl; + + @JsonCreator + public Profile( + @JsonProperty("nickname") String nickname, + @JsonProperty("imageUrl") String imageUrl + ) { + this.nickname = nickname; + this.imageUrl = imageUrl; + } + + public String getNickname() { + return nickname; + } + + public String getImageUrl() { + return imageUrl; + } + + @Override + public String toString() { + return "Profile{" + + "nickname='" + nickname + '\'' + + "imageUrl='" + imageUrl + '\'' + + '}'; + } + +} \ No newline at end of file From d8bb72c6b1e9d7b53c11266cb60e6d217de26709 Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Thu, 26 May 2022 18:35:42 +0900 Subject: [PATCH 13/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20Link=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20[ossmini#69]=20*=20Link=EB=A5=BC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=ED=95=9C=EB=8B=A4.=20*=20IntelliJ=EC=9D=98?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=ED=86=B5=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?toString=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closed ossmini#69 --- .../skill/response/common/Profile.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java index 19563c2..7905266 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java @@ -16,6 +16,14 @@ public Profile( this.imageUrl = imageUrl; } + @Override + public String toString() { + return "Profile{" + + "nickname='" + nickname + '\'' + + ", imageUrl='" + imageUrl + '\'' + + '}'; + } + public String getNickname() { return nickname; } @@ -24,12 +32,4 @@ public String getImageUrl() { return imageUrl; } - @Override - public String toString() { - return "Profile{" + - "nickname='" + nickname + '\'' + - "imageUrl='" + imageUrl + '\'' + - '}'; - } - } \ No newline at end of file From 6f92e4e452c5ead21e8524611d97215de0c167f2 Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Sat, 28 May 2022 21:17:40 +0900 Subject: [PATCH 14/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20Link=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20[ossmini#69]=20*=20Link=EB=A5=BC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=ED=95=9C=EB=8B=A4.=20*=20IntelliJ=EC=9D=98?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=ED=86=B5=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?toString=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closed ossmini#69 --- .../skill/response/common/Link.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java index 154a0c5..2d005e5 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java @@ -8,6 +8,15 @@ public class Link { private String mobile; private String web; + @Override + public String toString() { + return "Link{" + + "pc='" + pc + '\'' + + ", mobile='" + mobile + '\'' + + ", web='" + web + '\'' + + '}'; + } + @JsonCreator public Link( @JsonProperty("pc") String pc, @@ -31,13 +40,4 @@ public String getWeb() { return web; } - @Override - public String toString() { - return "Link{" + - "pc='" + pc + '\'' + - "mobile='" + mobile + '\'' + - "web='" + web + '\'' + - '}'; - } - } \ No newline at end of file From 26c695cce20b9405a82de0fbf786db0d3bc7ccf5 Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Sat, 28 May 2022 21:40:19 +0900 Subject: [PATCH 15/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20Button=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20[ossmini#65]=20*=20Button=EC=9D=84=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=ED=95=9C=EB=8B=A4.=20*=20IntelliJ=EC=9D=98?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=ED=86=B5=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?toString=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closed ossmini#65 --- .../skill/response/common/Button.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java new file mode 100644 index 0000000..2b263b5 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java @@ -0,0 +1,72 @@ +package dev.mini.kakaoiopenbuilder.skill.response.common; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Map; + +public class Button { + private String label; + private String action; + private String webLinkUrl; + private String messageText; + private String phoneNumber; + private String blockId; + private Map extra; + + @JsonCreator + public Button( + @JsonProperty("label") String label, + @JsonProperty("action") String action, + @JsonProperty("webLinkUrl") String webLinkUrl, + @JsonProperty("messageText") String messageText, + @JsonProperty("phoneNumber") String phoneNumber, + @JsonProperty("blockId") String blockId, + @JsonProperty("extra") Map extra + ) { + this.label = label; + this.action = action; + this.webLinkUrl = webLinkUrl; + this.messageText = messageText; + this.phoneNumber = phoneNumber; + this.blockId = blockId; + this.extra = extra; + } + + public String getlabel() { + return label; + } + + public String getAction() { + return action; + } + + public String getMessageText() { + return messageText; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public String getBlockId() { + return blockId; + } + + public Map getExtra() { + return extra; + } + + @Override + public String toString() { + return "Button{" + + "label='" + label + '\'' + + ", action='" + action + '\'' + + ", webLinkUrl='" + webLinkUrl + '\'' + + ", messageText='" + messageText + '\'' + + ", phoneNumber='" + phoneNumber + '\'' + + ", blockId='" + blockId + '\'' + + ", extra=" + extra + + '}'; + } +} \ No newline at end of file From 6e785659eca00881387d0a63685b1a22c1b8e47e Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Sat, 28 May 2022 21:46:58 +0900 Subject: [PATCH 16/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20Forwardable?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84=20[ossmini#66]=20*=20Forwardable=EC=9D=84?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84=ED=95=9C=EB=8B=A4.=20*=20IntelliJ?= =?UTF-8?q?=EC=9D=98=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=ED=86=B5=ED=95=B4?= =?UTF-8?q?=EC=84=9C=20toString=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closed ossmini#66 --- .../skill/response/common/Forwardable.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Forwardable.java diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Forwardable.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Forwardable.java new file mode 100644 index 0000000..40c3f30 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Forwardable.java @@ -0,0 +1,26 @@ +package dev.mini.kakaoiopenbuilder.skill.response.common; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Forwardable { + private boolean forwardable; + + @JsonCreator + public Forwardable( + @JsonProperty("forwardable") boolean forwardable + ) { + this.forwardable = forwardable; + } + + public boolean getForwardable() { + return forwardable; + } + + @Override + public String toString() { + return "Forwardable{" + + "forwardable=" + forwardable + + '}'; + } +} \ No newline at end of file From 77b6d7c31c84a21df794add85461a1006e8e53a3 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Sun, 29 May 2022 15:23:24 +0900 Subject: [PATCH 17/29] =?UTF-8?q?chore:=20common=20=EA=B2=BD=EB=A1=9C?= =?UTF-8?q?=EC=9D=98=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=93=A4=EC=9D=84=20cov?= =?UTF-8?q?erage=20=EC=B8=A1=EC=A0=95=20=EB=8C=80=EC=83=81=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * common의 대부분은 자료구조로서 테스트 코드 작성이 필요없다고 판단되기 때문에 coverage 측정 대상에서 제외한다. --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 1b0272a..9f8553b 100644 --- a/pom.xml +++ b/pom.xml @@ -115,6 +115,7 @@ dev/mini/**/Main.class dev/mini/**/util/*.class + dev/mini/**/response/common/*.class From a47f8facb248e2a79cd0579fe04e88d85e1c4265 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Sun, 29 May 2022 15:49:25 +0900 Subject: [PATCH 18/29] =?UTF-8?q?chore:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20Co?= =?UTF-8?q?nvention=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skill/response/common/Button.java | 7 ++++++- .../skill/response/common/Forwardable.java | 3 ++- .../skill/response/common/Link.java | 20 +++++++++---------- .../skill/response/common/Profile.java | 16 +++++++-------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java index 2b263b5..32a3dda 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java @@ -33,7 +33,7 @@ public Button( this.extra = extra; } - public String getlabel() { + public String getLabel() { return label; } @@ -41,6 +41,10 @@ public String getAction() { return action; } + public String getWebLinkUrl() { + return webLinkUrl; + } + public String getMessageText() { return messageText; } @@ -69,4 +73,5 @@ public String toString() { ", extra=" + extra + '}'; } + } \ No newline at end of file diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Forwardable.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Forwardable.java index 40c3f30..29e4dc8 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Forwardable.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Forwardable.java @@ -13,7 +13,7 @@ public Forwardable( this.forwardable = forwardable; } - public boolean getForwardable() { + public boolean isForwardable() { return forwardable; } @@ -23,4 +23,5 @@ public String toString() { "forwardable=" + forwardable + '}'; } + } \ No newline at end of file diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java index 2d005e5..e566f1b 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Link.java @@ -8,15 +8,6 @@ public class Link { private String mobile; private String web; - @Override - public String toString() { - return "Link{" + - "pc='" + pc + '\'' + - ", mobile='" + mobile + '\'' + - ", web='" + web + '\'' + - '}'; - } - @JsonCreator public Link( @JsonProperty("pc") String pc, @@ -28,7 +19,7 @@ public Link( this.web = web; } - public String getPC() { + public String getPc() { return pc; } @@ -40,4 +31,13 @@ public String getWeb() { return web; } + @Override + public String toString() { + return "Link{" + + "pc='" + pc + '\'' + + ", mobile='" + mobile + '\'' + + ", web='" + web + '\'' + + '}'; + } + } \ No newline at end of file diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java index 7905266..8d8395b 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Profile.java @@ -16,14 +16,6 @@ public Profile( this.imageUrl = imageUrl; } - @Override - public String toString() { - return "Profile{" + - "nickname='" + nickname + '\'' + - ", imageUrl='" + imageUrl + '\'' + - '}'; - } - public String getNickname() { return nickname; } @@ -32,4 +24,12 @@ public String getImageUrl() { return imageUrl; } + @Override + public String toString() { + return "Profile{" + + "nickname='" + nickname + '\'' + + ", imageUrl='" + imageUrl + '\'' + + '}'; + } + } \ No newline at end of file From 4e2f8641104692f9a5bdef8380e7f28673799216 Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Sat, 28 May 2022 21:29:51 +0900 Subject: [PATCH 19/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20Thumbnail=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20[ossmini#64]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Thumbnail을 구현한다. * IntelliJ의 기능을 통해서 toString 메서드를 생성한다. Closed ossmini#64 --- .../skill/response/common/Thumbnail.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Thumbnail.java diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Thumbnail.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Thumbnail.java new file mode 100644 index 0000000..2fd4731 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Thumbnail.java @@ -0,0 +1,58 @@ +package dev.mini.kakaoiopenbuilder.skill.response.common; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Thumbnail { + private String imageUrl; + private Link link; + private boolean fixedRatio; + private int width; + private int height; + + @JsonCreator + public Thumbnail( + @JsonProperty("imageUrl") String imageUrl, + @JsonProperty("link") Link link, + @JsonProperty("fixedRatio") boolean fixedRatio, + @JsonProperty("width") int width, + @JsonProperty("height") int height + ) { + this.imageUrl = imageUrl; + this.link = link; + this.fixedRatio = fixedRatio; + this.width = width; + this.height = height; + } + + public String getImageUrl() { + return imageUrl; + } + + public Link getLink() { + return link; + } + + public boolean getFixedRatio() { + return fixedRatio; + } + + public int width() { + return width; + } + + public int height() { + return height; + } + + @Override + public String toString() { + return "Thumbnail{" + + "imageUrl='" + imageUrl + '\'' + + ", link=" + link + + ", fixedRatio=" + fixedRatio + + ", width=" + width + + ", height=" + height + + '}'; + } +} \ No newline at end of file From ef21189337a035bbd8c804661c6048e7ed015b75 Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Sat, 28 May 2022 21:37:40 +0900 Subject: [PATCH 20/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20CarouselHeade?= =?UTF-8?q?r=20=EA=B5=AC=ED=98=84=20[ossmini#67]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CarouselHeader를 구현한다. * IntelliJ의 기능을 통해서 toString 메서드를 생성한다. Closed ossmini#67 --- .../skill/response/common/CarouselHeader.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/CarouselHeader.java diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/CarouselHeader.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/CarouselHeader.java new file mode 100644 index 0000000..e823682 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/CarouselHeader.java @@ -0,0 +1,42 @@ +package dev.mini.kakaoiopenbuilder.skill.response.common; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CarouselHeader { + private String title; + private String description; + private Thumbnail thumbnail; + + @JsonCreator + public CarouselHeader( + @JsonProperty("title") String title, + @JsonProperty("description") String description, + @JsonProperty("thumbnail") Thumbnail thumbnail + ) { + this.title = title; + this.description = description; + this.thumbnail = thumbnail; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public Thumbnail getThumbnail() { + return thumbnail; + } + + @Override + public String toString() { + return "CarouselHeader{" + + "title='" + title + '\'' + + ", description='" + description + '\'' + + ", thumbnail=" + thumbnail + + '}'; + } +} \ No newline at end of file From b8c2feaee7b3437fabaf6f437996e86f2ccc2628 Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Mon, 18 Apr 2022 15:44:23 +0900 Subject: [PATCH 21/29] =?UTF-8?q?feat:=20SkillTemplate=20-=20SimpleImage?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84=20[#55]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skill/response/component/Component.java | 11 ++++-- .../skill/response/component/SimpleImage.java | 36 +++++++++++++++++++ .../skill/response/component/SimpleText.java | 3 +- .../response/template/TemplateBuilder.java | 10 +++++- .../skill/response/SkillResponseTest.java | 19 ++++++++++ .../skill_response_simple_image.json | 14 ++++++++ testResources/skill_response_simple_text.json | 1 + 7 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleImage.java create mode 100644 testResources/skill_response_simple_image.json diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/Component.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/Component.java index bcc163c..5abaa50 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/Component.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/Component.java @@ -5,13 +5,18 @@ @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = SimpleText.class ) @JsonSubTypes({ - @JsonSubTypes.Type(value = SimpleText.class, name = "simpleText"), + @JsonSubTypes.Type(value = SimpleText.class), + @JsonSubTypes.Type(value = SimpleImage.class) }) -public interface Component { +public class Component { + private final String type; + + public Component(String type) { + this.type = type; + } } diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleImage.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleImage.java new file mode 100644 index 0000000..648346f --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleImage.java @@ -0,0 +1,36 @@ +package dev.mini.kakaoiopenbuilder.skill.response.component; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SimpleImage extends Component { + private String imageUrl; + private String altText; + + @JsonCreator + public SimpleImage( + @JsonProperty("imageUrl") String imageUrl, + @JsonProperty("altText") String altText + ) { + super("SimpleImage"); + this.imageUrl = imageUrl; + this.altText = altText; + } + + public String getImageUrl() { + return imageUrl; + } + + public String getAltText() { + return altText; + } + + @Override + public String toString() { + return "SimpleImage{" + + "imageUrl='" + imageUrl + '\'' + + ", altText='" + altText + '\'' + + '}'; + } + +} diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java index 73604d3..31bc70f 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/SimpleText.java @@ -3,11 +3,12 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -public class SimpleText implements Component { +public class SimpleText extends Component { private String text; @JsonCreator public SimpleText(@JsonProperty("text") String text) { + super("SimpleText"); this.text = text; } diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java index a43d13c..1846a0a 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/template/TemplateBuilder.java @@ -1,6 +1,7 @@ package dev.mini.kakaoiopenbuilder.skill.response.template; import dev.mini.kakaoiopenbuilder.skill.exception.ComponentsOutOfBoundsException; +import dev.mini.kakaoiopenbuilder.skill.response.component.SimpleImage; import dev.mini.kakaoiopenbuilder.skill.response.component.SimpleText; import java.util.ArrayList; @@ -14,7 +15,14 @@ public static TemplateBuilder builder() { } public TemplateBuilder addSimpleText(String text) { - output.add(new Output("simpleText", new SimpleText(text))); + SimpleText simpleText = new SimpleText(text); + output.add(new Output("simpleText", simpleText)); + return this; + } + + public TemplateBuilder addSimpleImage(String imageUrl, String altText) { + SimpleImage simpleImage = new SimpleImage(imageUrl, altText); + output.add(new Output("simpleImage", simpleImage)); return this; } diff --git a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java index 54fda0d..4ab6c92 100644 --- a/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java +++ b/src/test/java/dev/mini/kakaoiopenbuilder/skill/response/SkillResponseTest.java @@ -17,6 +17,7 @@ class SkillResponseTest { private static final String SKILL_SIMPLE_TEXT_FILE_PATH = "testResources/skill_response_simple_text.json"; + private static final String SKILL_SIMPLE_IMAGE_FILE_PATH = "testResources/skill_response_simple_image.json"; @Test @DisplayName("출력할 수 있는 Skill Component는 1개 미만일 수 없다.") @@ -59,6 +60,24 @@ void validSimpleText() throws IOException { assertThat(actual.toString()).hasToString(expected.toString()); } + @Test + @DisplayName("SimpleImage 포맷이 동일한지 검증한다.") + void validSimpleImage() throws IOException { + // given + Template actual = loadSkillResponseTemplateJson(SKILL_SIMPLE_IMAGE_FILE_PATH).getTemplate(); + + String imageUrl = "http://k.kakaocdn.net/dn/83BvP/bl20duRC1Q1/lj3JUcmrzC53YIjNDkqbWK/i_6piz1p.jpg"; + String altText = "보물상자입니다"; + + // when + Template expected = TemplateBuilder.builder() + .addSimpleImage(imageUrl, altText) + .build(); + + // that + assertThat(actual.toString()).hasToString(expected.toString()); + } + private SkillResponse loadSkillResponseTemplateJson(String filePath) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); diff --git a/testResources/skill_response_simple_image.json b/testResources/skill_response_simple_image.json new file mode 100644 index 0000000..5b6a020 --- /dev/null +++ b/testResources/skill_response_simple_image.json @@ -0,0 +1,14 @@ +{ + "version": "2.0", + "template": { + "outputs": [ + { + "simpleImage": { + "type": "SimpleImage", + "imageUrl": "http://k.kakaocdn.net/dn/83BvP/bl20duRC1Q1/lj3JUcmrzC53YIjNDkqbWK/i_6piz1p.jpg", + "altText": "보물상자입니다" + } + } + ] + } +} \ No newline at end of file diff --git a/testResources/skill_response_simple_text.json b/testResources/skill_response_simple_text.json index f8efe8e..7888e04 100644 --- a/testResources/skill_response_simple_text.json +++ b/testResources/skill_response_simple_text.json @@ -4,6 +4,7 @@ "outputs": [ { "simpleText": { + "type": "SimpleText", "text": "간단한 텍스트 요소입니다." } } From 1dd85242e145f1ccfef48a2cd24897d7e50aadff Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Sun, 29 May 2022 20:29:41 +0900 Subject: [PATCH 22/29] =?UTF-8?q?fix:=20SonarCloud=EC=97=90=EC=84=9C=20Cov?= =?UTF-8?q?erage=EA=B0=80=20=EC=9E=98=EB=AA=BB=20=EC=B8=A1=EC=A0=95?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?[#78]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * pom.xml에 sonar.coverage.exclusions 추가 Resolved #78 --- .github/workflows/sonar.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 7cd3c1e..fdacc86 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -41,4 +41,5 @@ jobs: -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} -Dsonar.pullrequest.key=${{ env.PR_NUMBER }} -Dsonar.pullrequest.branch=${{ env.HEAD_REF }} - -Dsonar.pullrequest.base=${{ env.BASE_REF }} \ No newline at end of file + -Dsonar.pullrequest.base=${{ env.BASE_REF }} + -Dsonar.sonar.coverage.exclusions=**/Main.class,**/util/*.class,**/response/common/*.class \ No newline at end of file From fa647cf92cbecf96efbcb7cdbc57ffe17f757e9e Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Sun, 29 May 2022 21:41:03 +0900 Subject: [PATCH 23/29] =?UTF-8?q?fix:=20workflow=EC=9D=98=20SonarQube=20Co?= =?UTF-8?q?verage=20=EC=84=A4=EC=A0=95=EA=B0=92=20=EC=88=98=EC=A0=95=20[#7?= =?UTF-8?q?8]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sonar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index fdacc86..b959cbd 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -42,4 +42,4 @@ jobs: -Dsonar.pullrequest.key=${{ env.PR_NUMBER }} -Dsonar.pullrequest.branch=${{ env.HEAD_REF }} -Dsonar.pullrequest.base=${{ env.BASE_REF }} - -Dsonar.sonar.coverage.exclusions=**/Main.class,**/util/*.class,**/response/common/*.class \ No newline at end of file + -Dsonar.coverage.exclusions=**/Main.class,**/util/*.class,**/response/common/*.class \ No newline at end of file From d5ab62f9150f51611cd2bb9fb4ed9640fff2183c Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Thu, 2 Jun 2022 20:53:00 +0900 Subject: [PATCH 24/29] =?UTF-8?q?docs:=20README.md=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?[ossmini#27]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * README.md의 내용을 추가한다. Closed #27 --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61c9e09..bf0277d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Kakao I OpenBuilder Java Library [![example workflow](https://github.com/Sejong-OSS/Kakao_I_OpenBuilder_Library/actions/workflows/build.yml/badge.svg)](https://github.com/Sejong-OSS/Kakao_I_OpenBuilder_Library/actions/workflows/build.yml) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Sejong-OSS_Kakao_I_OpenBuilder_Library&metric=coverage)](https://sonarcloud.io/summary/new_code?id=Sejong-OSS_Kakao_I_OpenBuilder_Library) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Sejong-OSS_Kakao_I_OpenBuilder_Library&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Sejong-OSS_Kakao_I_OpenBuilder_Library) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Sejong-OSS_Kakao_I_OpenBuilder_Library&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Sejong-OSS_Kakao_I_OpenBuilder_Library) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Sejong-OSS_Kakao_I_OpenBuilder_Library&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Sejong-OSS_Kakao_I_OpenBuilder_Library) -## Getting Starting +## Getting Started ### Maven ```xml @@ -12,5 +12,24 @@ ``` ### Gradle ```groovy -implementation 'dev.mini:kakao-i-openbuilder:1.0.0' +implementation 'dev.mini:kakao-i-openbuilder:1.0.1' +``` + +### Example +There is an example code implementing this library, you can check it out over [here](https://github.com/ossmini/Kakao_ChatBot_Example). + +## Resources +- [Kakao i Developers Docs](https://i.kakao.com/docs/getting-started-overview) + +## Contributing +- [Submit bugs and feature requests](https://github.com/ossmini/Kakao_I_OpenBuilder_Library/issues) + +## License +Licensed under the [Apache-2.0](https://github.com/ossmini/Kakao_I_OpenBuilder_Library/blob/main/LICENSE) license. +## Development +### Build +You need [Apache Maven](http://maven.apache.org/) to build the project: + +```bash +mvn clean install ``` From e9f6c6fac5cbd9470a6274289960b3c10e903b9b Mon Sep 17 00:00:00 2001 From: Donghwan Suh <62374010+donghwansuh@users.noreply.github.com> Date: Thu, 2 Jun 2022 21:26:34 +0900 Subject: [PATCH 25/29] =?UTF-8?q?docs:=20CODE=5FOF=5FCONDUCT.md=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20[ossmini#80]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CODE_OF_CONDUCT.md를 추가한다. Closed #80 --- CODE_OF_CONDUCT.md | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..3fee6bb --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +riyenas0925@gmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. From d6762db0379090e443b2d304b6d15b4888b6a08c Mon Sep 17 00:00:00 2001 From: donghwansuh Date: Thu, 2 Jun 2022 22:19:52 +0900 Subject: [PATCH 26/29] =?UTF-8?q?docs:=20CONTRIBUTING.md=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20[ossmini#81]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CONTRIBUTING.md를 추가한다. Closed #81 --- CONTRIBUTING.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ee0e6f5 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,30 @@ +# Contributing to Kakao I OpenBuilder Java Library +Thank you for having an interest in contributing to Kakao I OpenBuilder Java Library! + +Not a developer? Submitting a bug report or giving your opinion about the project can help! + +## Creating an issue on Github +Most of the issues are maintained in the issue section of the project's Github repository. + +You can open an issue [here](https://github.com/ossmini/Kakao_I_OpenBuilder_Library/issues). + +When opening an issue, please select a label from the list below. +``` +- chore: Chores such as build. +- docs: Make changes to documents. +- feature: Request or add a feature. +- fix: File a bug report or submit a fixed code. +- question: Feel free to ask a question! +- refactor: You can also refactor code. +- test: Add a missing test code. +``` +Please check [Opened issues](https://github.com/ossmini/Kakao_I_OpenBuilder_Library/issues?q=label%3Afix+is%3Aopen) before reporting a bug. + + +## Creating a pull request +Before starting a pull request, please create a corresponding issue on Github. + +1. Fork the project's [git repository](https://github.com/ossmini/Kakao_I_OpenBuilder_Library). +2. Create a branch from 'develop' branch at your repo. The branch's name should be like 'label/issue-number'. +3. Make changes! +4. Open a pull request from your branch to upstream/develop. \ No newline at end of file From 27c97675fbd3d35e1dffb0d67ba78f23261e2bbe Mon Sep 17 00:00:00 2001 From: riyenas0925 Date: Fri, 3 Jun 2022 12:17:42 +0900 Subject: [PATCH 27/29] =?UTF-8?q?feat:=20SkillResponse=20-=20Basic=20Card?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84=20[#56]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolved #56 --- .../skill/response/common/Button.java | 8 +++ .../skill/response/common/Thumbnail.java | 4 ++ .../skill/response/component/BasicCard.java | 56 +++++++++++++++++++ .../skill/response/component/Component.java | 3 +- .../response/template/TemplateBuilder.java | 9 +++ .../skill/response/SkillResponseTest.java | 28 ++++++++++ testResources/skill_response_basic_card.json | 29 ++++++++++ 7 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/BasicCard.java create mode 100644 testResources/skill_response_basic_card.json diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java index 32a3dda..6222267 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Button.java @@ -33,6 +33,14 @@ public Button( this.extra = extra; } + public static Button message(String label, String messageText) { + return new Button(label, "message", null, messageText, null, null, null); + } + + public static Button weblink(String label, String webLinkUrl) { + return new Button(label, "webLink", webLinkUrl, null, null, null, null); + } + public String getLabel() { return label; } diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Thumbnail.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Thumbnail.java index 2fd4731..e007968 100644 --- a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Thumbnail.java +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/common/Thumbnail.java @@ -25,6 +25,10 @@ public Thumbnail( this.height = height; } + public static Thumbnail of(String imageUrl) { + return new Thumbnail(imageUrl, null, false, 0, 0); + } + public String getImageUrl() { return imageUrl; } diff --git a/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/BasicCard.java b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/BasicCard.java new file mode 100644 index 0000000..2aa2dd0 --- /dev/null +++ b/src/main/java/dev/mini/kakaoiopenbuilder/skill/response/component/BasicCard.java @@ -0,0 +1,56 @@ +package dev.mini.kakaoiopenbuilder.skill.response.component; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import dev.mini.kakaoiopenbuilder.skill.response.common.Button; +import dev.mini.kakaoiopenbuilder.skill.response.common.Thumbnail; + +import java.util.List; + +public class BasicCard extends Component { + String title; + String description; + Thumbnail thumbnail; + List