Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V3] Improve models and API methods #6

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
60 changes: 34 additions & 26 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.touchbit.testrail4j.core.field;

import java.util.StringJoiner;

/**
* The estimate, e.g. “30s” or “1m 45s”
*
* <p>
* Created by Oleg Shaburov on 18.09.2020
* [email protected]
*/
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();
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long>() {{ 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long>() {{ 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")
Expand Down
45 changes: 8 additions & 37 deletions testrail4j-schema/src/main/resources/schema/TRCaseFieldConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,23 @@
"$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<Long>",
"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": [
"context",
"id",
"options"
]
}
}
Original file line number Diff line number Diff line change
@@ -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<Long>",
"items": {
"type": "integer",
"javaType" : "java.lang.Long"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Loading