TestRail4J TestRail4J Java

Java HTTP-client for the TestRail API.

A feign HTTP-clients are represented by the TestRailClient interface for each type of model annotation. Annotated jackson2 and gson models are generated using the jsonschema2pojo plugin from the json schemas.

Usage

TestRail4J represented by two client modules with gson and Jackson2 models respectively. This is done for the convenience of the end user, so as not to use unnecessary dependencies in the project if one of the presented models is already used in the project.

Add the client to the pom.xml file. For example jackson2:

<dependency>
   <groupId>org.touchbit.testrail4j</groupId>
   <artifactId>jackson2-feign-client</artifactId>
   <version>${testrail4j.version}</version>
</dependency>

Build client using TestRailClientBuilder and call the necessary method

import org.touchbit.testrail4j.jackson2.gson.feign.TestRailClientBuilder;
import org.touchbit.testrail4j.core.BasicAuth;
import org.touchbit.testrail4j.jackson2.model.Case;

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());
    }
}

Restrictions

TestRailClient#addCaseField(TRCaseField)

The returned object for the method of creating a new test case custom field is not available until the correction of the defect

Table of Contents

Customisation

TestRailClient

If you have a need to expand calls to TestRail (new version has been released), then you can always create your own interface inherited from TestRailClient with your own methods of working with API. For example:

public interface CustomTestRailClient extends TestRailClient {

    @RequestLine(value = "GET /index.php/api/v2/get_results/{foo}/{bar}")
    List<TRResult> getResultsWithFooBar(@Param("foo") Long foo, @Param("bar") Long bar);
}

Next you need to build your specific TestRail client.

public class Example {
    public static void main(String[] a) {
        CustomTestRailClient client = TestRailClientBuilder
                .build("login", "pass", "http://tr.host", CustomTestRailClient.class);
        client.getResultsWithFooBar("foooooo", "baaaaaar");
    }
}

TestRailClientBuilder

TestRailClientBuilder - not necessary to use. You can always build your own TestRailClient using Feign.Builder()

public class Example {
    public static void main(String[] a) {
        CustomTestRailClient client = new Feign.Builder()
            .client(new Client.Proxied(sslContextFactory, hostnameVerifier, proxy))
            .encoder(new GsonEncoder())
            .decoder(new GsonDecoder())
            .logger(new CustomLogger())
            .logLevel(FULL)
            .requestInterceptors(Arrays.asList(interceptors))
            .options(new Request.Options(10, TimeUnit.SECONDS, 60, TimeUnit.SECONDS, true))
            .errorDecoder(new CustomTestRailErrorDecoder())
            .target(CustomTestRailClient.class, "https://testrail.custom");
        client.getResultsWithFooBar("foooooo", "baaaaaar");
    }
}

Query Maps

All QueryMaps are empty interfaces to allow the end user to create and use their own filter with presets. Secondly to level surprises from TR when updating the version of the server.

All existing default filters are presented in the package org.touchbit.testrail4j.core.query.filter

public class Example {
    public static void main(String[] a) {
        TestRailClient client = TestRailClientBuilder
                                    .build("user", "pass", "http://localhost");
        List<TRProject> projects = client
                            .getProjects(new GetProjectsFilter().withIsCompleted(true);
    }
}

Modules

Common

  • testrail4j-core - contains a common implementation for TestRail4J HTTP clients. Used in modules: jackson2-feign-client, gson-feign-client.

Clients

  • jackson2-feign-client - jackson2 annotated interface for the feign http-client
<dependency>
    <groupId>org.touchbit.testrail4j</groupId>
    <artifactId>jackson2-feign-client</artifactId>
    <version>${testrail4j.version}</version>
</dependency>
  • gson-feign-client - gson annotated interface for the feign http-client
<dependency>
    <groupId>org.touchbit.testrail4j</groupId>
    <artifactId>gson-feign-client</artifactId>
    <version>${testrail4j.version}</version>
</dependency>

Models

  • jackson2-api-model - Jackson2 annotated models. Used in modules: jackson2-feign-client.
<dependency>
    <groupId>org.touchbit.testrail4j</groupId>
    <artifactId>jackson2-api-model</artifactId>
    <version>${testrail4j.version}</version>
</dependency>
  • gson-api-model - Gson annotated models. Used in modules: gson-feign-client.
<dependency>
    <groupId>org.touchbit.testrail4j</groupId>
    <artifactId>gson-api-model</artifactId>
    <version>${testrail4j.version}</version>
</dependency>
  • testrail4j-schema - Json schemas for TestRail API (if you need to generate your own models).
<dependency>
    <groupId>org.touchbit.testrail4j</groupId>
    <artifactId>testrail4j-schema</artifactId>
    <version>${testrail4j.version}</version>
</dependency>

Dependency tree

Jackson2

jackson2-feign-client
org.touchbit.testrail4j:jackson2-feign-client:jar:0.0.0
+- org.touchbit.testrail4j:testrail4j-core:jar:0.0.0:compile
|  +- io.github.openfeign:feign-core:jar:11.0:compile
|  \- org.slf4j:slf4j-api:jar:2.0.0-alpha1:compile
+- org.touchbit.testrail4j:jackson2-api-model:jar:0.0.0:compile
|  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.11.2:compile
\- io.github.openfeign:feign-jackson:jar:11.0:compile
   \- com.fasterxml.jackson.core:jackson-databind:jar:2.10.0.pr3:compile
      \- com.fasterxml.jackson.core:jackson-core:jar:2.10.0.pr3:compile
jackson2-api-model
org.touchbit.testrail4j:jackson2-api-model:jar:0.0.0
\- com.fasterxml.jackson.core:jackson-annotations:jar:2.11.2:compile

Gson

gson-feign-client
org.touchbit.testrail4j:gson-feign-client:jar:0.0.0
+- org.touchbit.testrail4j:testrail4j-core:jar:0.0.0:compile
|  +- io.github.openfeign:feign-core:jar:11.0:compile
|  \- org.slf4j:slf4j-api:jar:2.0.0-alpha1:compile
+- org.touchbit.testrail4j:gson-api-model:jar:0.0.0:compile
|  \- com.google.code.gson:gson:jar:2.8.6:compile
\- io.github.openfeign:feign-gson:jar:11.0:compile
gson-api-model
org.touchbit.testrail4j:gson-api-model:jar:0.0.0
\- com.google.code.gson:gson:jar:2.8.6:compile

Core

testrail4j-core
org.touchbit.testrail4j:testrail4j-core:jar:0.0.0
+- io.github.openfeign:feign-core:jar:11.0:compile
\- org.slf4j:slf4j-api:jar:2.0.0-alpha1:compile

MIT License

  • Copyright (c) 2020 TouchBIT.
  • Copyright (c) 2020 Oleg Shaburov.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.