diff --git a/README.rst b/README.rst index bf2ee0f..84a6c65 100644 --- a/README.rst +++ b/README.rst @@ -56,34 +56,37 @@ or .. code:: java public class Example { - public static void main(String[] a) { - TestRailClient client = TestRailClientBuilder - .build("user", "pass", "http://localhost"); - - Project project = client.addProject("name", "announcement", true, 3); - - Section section = new Section() - .withName(UUID.randomUUID().toString()) - .withDescription(UUID.randomUUID().toString()); - - Section section = client.addSection(section, project.getId()); - - Case caze = new Case() - .withTitle("test_20190101201312") - .withPriorityId(CRITICAL.getId()) - .withSuiteId(section.getSuiteId()) - .withRefs("JIRA-123") - .withTypeId(ACCEPTANCE.getId()) - .withTemplateId(TEST_CASE_TEXT.getId()) - .withEstimate("1m 45s") - .withCustomPreconds("withCustomPreconds") - .withCustomSteps("withCustomSteps") - .withCustomExpected("withCustomExpected") - .withCustomStepsSeparated(null); - - Case caze = client.addCase(caze, section); - System.out.println(caze.getId()); - } + public static void main(String[] a) { + TestRailClient client = TestRailClientBuilder + .build("user", "pass", "http://localhost"); + + TRProject trProject = new TRProject() + .withName("name") + .withAnnouncement("Announcement") + .withSuiteMode(MULTIPLE.getId()); + TRProject resultProject = client.addProject(trProject); + + TRSection trSection = new TRSection() + .withName(UUID.randomUUID().toString()) + .withDescription(UUID.randomUUID().toString()); + TRSection resultSection = client.addSection(trSection, resultProject); + + TRCase trCase = new TRCase() + .withTitle("test_20190101201312") + .withPriorityId(CRITICAL.getId()) + .withSuiteId(resultSection.getSuiteId()) + .withRefs("JIRA-123") + .withTypeId(ACCEPTANCE.getId()) + .withTemplateId(TEST_CASE_TEXT.getId()) + .withEstimate(new Estimate().withHour(4).toString()) + .withCustomPreconds("withCustomPreconds") + .withCustomSteps("withCustomSteps") + .withCustomExpected("withCustomExpected") + .withCustomStepsSeparated(null); + TRCase resultCase = client.addCase(trCase, resultSection); + + System.out.println(resultCase.getId()); + } } * You can build the Feign client yourself and customize it to fit your needs. diff --git a/docs/index.rst b/docs/index.rst index d0470f7..012f990 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -37,34 +37,42 @@ Build client using `TestRailClientBuilder` and call the necessary method .. code:: java import org.touchbit.testrail4j.jackson2.gson.feign.TestRailClientBuilder; - import org.touchbit.testrail4j.core.BasicAuth; - import org.touchbit.testrail4j.jackson2.model.Case; + import org.touchbit.testrail4j.jackson2.model.*; + import org.touchbit.testrail4j.core.field.*; + import org.touchbit.testrail4j.core.type.*; public class Example { - public static void main(String[] a) { - TestRailClient client = TestRailClientBuilder - .build("user", "pass", "http://localhost"); - - Project project = client.addProject("name", "announcement", true, 3); - Section section = new Section() - .withName(UUID.randomUUID().toString()) - .withDescription(UUID.randomUUID().toString()); - Section section = client.addSection(section, project.getId()); - Case caze = new Case() - .withTitle("test_20190101201312") - .withPriorityId(CRITICAL.getId()) - .withSuiteId(section.getSuiteId()) - .withRefs("JIRA-123") - .withTypeId(ACCEPTANCE.getId()) - .withTemplateId(TEST_CASE_TEXT.getId()) - .withEstimate("1m 45s") - .withCustomPreconds("withCustomPreconds") - .withCustomSteps("withCustomSteps") - .withCustomExpected("withCustomExpected") - .withCustomStepsSeparated(null); - Case caze = client.addCase(caze, section); - System.out.println(caze.getId()); - } + public static void main(String[] a) { + TestRailClient client = TestRailClientBuilder + .build("user", "pass", "http://localhost"); + + TRProject trProject = new TRProject() + .withName("name") + .withAnnouncement("Announcement") + .withSuiteMode(MULTIPLE.getId()); + TRProject resultProject = client.addProject(trProject); + + TRSection trSection = new TRSection() + .withName(UUID.randomUUID().toString()) + .withDescription(UUID.randomUUID().toString()); + TRSection resultSection = client.addSection(trSection, resultProject); + + TRCase trCase = new TRCase() + .withTitle("test_20190101201312") + .withPriorityId(CRITICAL.getId()) + .withSuiteId(resultSection.getSuiteId()) + .withRefs("JIRA-123") + .withTypeId(ACCEPTANCE.getId()) + .withTemplateId(TEST_CASE_TEXT.getId()) + .withEstimate(new Estimate().withHour(4).toString()) + .withCustomPreconds("withCustomPreconds") + .withCustomSteps("withCustomSteps") + .withCustomExpected("withCustomExpected") + .withCustomStepsSeparated(null); + TRCase resultCase = client.addCase(trCase, resultSection); + + System.out.println(resultCase.getId()); + } } Restrictions diff --git a/testrail4j-core/src/main/java/org/touchbit/testrail4j/core/field/Estimate.java b/testrail4j-core/src/main/java/org/touchbit/testrail4j/core/field/Estimate.java new file mode 100644 index 0000000..d00a215 --- /dev/null +++ b/testrail4j-core/src/main/java/org/touchbit/testrail4j/core/field/Estimate.java @@ -0,0 +1,89 @@ +package org.touchbit.testrail4j.core.field; + +import java.util.StringJoiner; + +/** + * The estimate, e.g. ā€œ30sā€ or ā€œ1m 45sā€ + * + *

+ * Created by Oleg Shaburov on 18.09.2020 + * shaburov.o.a@gmail.com + */ +public class Estimate { + + private int day = 0; + private int hour = 0; + private int min = 0; + private int sec = 0; + + public int getDay() { + return day; + } + + public int getMin() { + return min; + } + + public int getSec() { + return sec; + } + + public void setDay(int day) { + this.day = day; + } + + public void setMin(int min) { + this.min = min; + } + + public void setSec(int sec) { + this.sec = sec; + } + + public int getHour() { + return hour; + } + + public void setHour(int hour) { + this.hour = hour; + } + + public Estimate withDay(int day) { + this.day = day; + return this; + } + + public Estimate withHour(int hour) { + this.hour = hour; + return this; + } + + public Estimate withMin(int min) { + this.min = min; + return this; + } + + public Estimate withSec(int sec) { + this.sec = sec; + return this; + } + + @Override + public String toString() { + StringJoiner stringJoiner = new StringJoiner(" "); + if (day > 0) { + stringJoiner.add(day + "d"); + } + if (hour > 0) { + stringJoiner.add(hour + "h"); + } + if (min > 0) { + stringJoiner.add(min + "m"); + } + if (sec > 0) { + stringJoiner.add(sec + "s"); + } + return stringJoiner.toString(); + } + +} diff --git a/testrail4j-core/src/test/java/org/touchbit/testrail4j/core/FieldTests.java b/testrail4j-core/src/test/java/org/touchbit/testrail4j/core/FieldTests.java new file mode 100644 index 0000000..a9e8b62 --- /dev/null +++ b/testrail4j-core/src/test/java/org/touchbit/testrail4j/core/FieldTests.java @@ -0,0 +1,23 @@ +package org.touchbit.testrail4j.core; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.touchbit.testrail4j.core.field.Estimate; + +import static org.assertj.core.api.Assertions.assertThat; + +@DisplayName("DTO fields classes tests") +public class FieldTests { + + @Test + @DisplayName("Estimate.class") + void unitTest_20200918164754() { + Estimate estimate = new Estimate() + .withDay(1) + .withHour(2) + .withMin(3) + .withSec(4); + assertThat(estimate).hasToString("1d 2h 3m 4s"); + } + +} diff --git a/testrail4j-integration-tests/src/main/java/org/touchbit/testrail4j/integration/tests/gson/CaseFieldTests.java b/testrail4j-integration-tests/src/main/java/org/touchbit/testrail4j/integration/tests/gson/CaseFieldTests.java index 4ceb739..a97329c 100644 --- a/testrail4j-integration-tests/src/main/java/org/touchbit/testrail4j/integration/tests/gson/CaseFieldTests.java +++ b/testrail4j-integration-tests/src/main/java/org/touchbit/testrail4j/integration/tests/gson/CaseFieldTests.java @@ -59,10 +59,10 @@ public void test_20200106014139() { public void test_20200106015332() { TRProject project = CLIENT.getProject(); TRCaseFieldConfig config = new TRCaseFieldConfig() - .withContext(new Context() + .withContext(new TRCaseFieldConfigContext() .withIsGlobal(false) .withProjectIds(new ArrayList() {{ add(project.getId()); }})) - .withOptions(new Options().withIsRequired(false).withItems("0, A\n1, B").withDefaultValue("1")); + .withOptions(new TRCaseFieldConfigOptions().withIsRequired(false).withItems("0, A\n1, B").withDefaultValue("1")); TRCaseField field = new TRCaseField() .withName("with_name_" + getRandomString(5)) .withDescription("withDescription") diff --git a/testrail4j-integration-tests/src/main/java/org/touchbit/testrail4j/integration/tests/jackson2/CaseFieldTests.java b/testrail4j-integration-tests/src/main/java/org/touchbit/testrail4j/integration/tests/jackson2/CaseFieldTests.java index 8c89fbe..a907914 100644 --- a/testrail4j-integration-tests/src/main/java/org/touchbit/testrail4j/integration/tests/jackson2/CaseFieldTests.java +++ b/testrail4j-integration-tests/src/main/java/org/touchbit/testrail4j/integration/tests/jackson2/CaseFieldTests.java @@ -63,10 +63,11 @@ public void test_20190106014139() { public void test_20190106015332() { TRProject project = CLIENT.getProject(); TRCaseFieldConfig config = new TRCaseFieldConfig() - .withContext(new Context() + .withContext(new TRCaseFieldConfigContext() .withIsGlobal(false) .withProjectIds(new ArrayList() {{ add(project.getId()); }})) - .withOptions(new Options().withIsRequired(false).withItems("0, A\n1, B").withDefaultValue("1")); + .withOptions(new TRCaseFieldConfigOptions() + .withIsRequired(false).withItems("0, A\n1, B").withDefaultValue("1")); TRCaseField field = new TRCaseField() .withName("with_name_" + getRandomString(5)) .withDescription("withDescription") diff --git a/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfig.json b/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfig.json index c75633e..65593e5 100644 --- a/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfig.json +++ b/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfig.json @@ -2,47 +2,18 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { - "context": { - "type": "object", - "properties": { - "is_global": { - "type": "boolean" - }, - "project_ids": { - "type": "array", - "javaType": "java.util.List", - "items": { - "type": "integer", - "javaType" : "java.lang.Long" - } - } - } - }, "id": { "type": "string" }, + "context": { + "type": "object", + "javaType": "TRCaseFieldConfigContext", + "$ref": "TRCaseFieldConfigContext.json" + }, "options": { "type": "object", - "properties": { - "default_value": { - "type": "string" - }, - "format": { - "type": "string" - }, - "is_required": { - "type": "boolean" - }, - "rows": { - "type": "string" - }, - "items": { - "type": "string" - }, - "id": { - "type": "string" - } - } + "javaType": "TRCaseFieldConfigOptions", + "$ref": "TRCaseFieldConfigOptions.json" } }, "required": [ @@ -50,4 +21,4 @@ "id", "options" ] -} \ No newline at end of file +} diff --git a/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfigContext.json b/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfigContext.json new file mode 100644 index 0000000..0ac29f6 --- /dev/null +++ b/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfigContext.json @@ -0,0 +1,17 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "is_global": { + "type": "boolean" + }, + "project_ids": { + "type": "array", + "javaType": "java.util.List", + "items": { + "type": "integer", + "javaType" : "java.lang.Long" + } + } + } +} diff --git a/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfigOptions.json b/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfigOptions.json new file mode 100644 index 0000000..35207ba --- /dev/null +++ b/testrail4j-schema/src/main/resources/schema/TRCaseFieldConfigOptions.json @@ -0,0 +1,24 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "default_value": { + "type": "string" + }, + "format": { + "type": "string" + }, + "is_required": { + "type": "boolean" + }, + "rows": { + "type": "string" + }, + "items": { + "type": "string" + }, + "id": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/testrail4j-schema/src/main/resources/schema/TRResultFieldConfig.json b/testrail4j-schema/src/main/resources/schema/TRResultFieldConfig.json index 7c29a34..1005dba 100644 --- a/testrail4j-schema/src/main/resources/schema/TRResultFieldConfig.json +++ b/testrail4j-schema/src/main/resources/schema/TRResultFieldConfig.json @@ -2,54 +2,18 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { - "context": { - "type": "object", - "properties": { - "is_global": { - "type": "boolean" - }, - "project_ids": { - "type": "array", - "javaType": "java.util.List", - "items": { - "type": "integer", - "javaType" : "java.lang.Long" - } - } - }, - "required": [ - "is_global", - "project_ids" - ] - }, "id": { "type": "string" }, + "context": { + "type": "object", + "javaType": "TRResultFieldConfigContext", + "$ref": "TRResultFieldConfigContext.json" + }, "options": { "type": "object", - "properties": { - "format": { - "type": "string" - }, - "has_actual": { - "type": "boolean" - }, - "has_expected": { - "type": "boolean" - }, - "is_required": { - "type": "boolean" - }, - "rows": { - "type": "string" - } - }, - "required": [ - "format", - "has_actual", - "has_expected", - "is_required" - ] + "javaType": "TRResultFieldConfigOptions", + "$ref": "TRResultFieldConfigOptions.json" } }, "required": [ diff --git a/testrail4j-schema/src/main/resources/schema/TRResultFieldConfigContext.json b/testrail4j-schema/src/main/resources/schema/TRResultFieldConfigContext.json new file mode 100644 index 0000000..3868e14 --- /dev/null +++ b/testrail4j-schema/src/main/resources/schema/TRResultFieldConfigContext.json @@ -0,0 +1,21 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "is_global": { + "type": "boolean" + }, + "project_ids": { + "type": "array", + "javaType": "java.util.List", + "items": { + "type": "integer", + "javaType" : "java.lang.Long" + } + } + }, + "required": [ + "is_global", + "project_ids" + ] +} \ No newline at end of file diff --git a/testrail4j-schema/src/main/resources/schema/TRResultFieldConfigOptions.json b/testrail4j-schema/src/main/resources/schema/TRResultFieldConfigOptions.json new file mode 100644 index 0000000..7e93a1d --- /dev/null +++ b/testrail4j-schema/src/main/resources/schema/TRResultFieldConfigOptions.json @@ -0,0 +1,27 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "format": { + "type": "string" + }, + "has_actual": { + "type": "boolean" + }, + "has_expected": { + "type": "boolean" + }, + "is_required": { + "type": "boolean" + }, + "rows": { + "type": "string" + } + }, + "required": [ + "format", + "has_actual", + "has_expected", + "is_required" + ] +} \ No newline at end of file