The Litmus Java SDK makes it easy to communicate with Litmus’ internal servers.
This library requires Java 17 or later.
Litmus version 3.13.0 or later.
implementation 'io.litmuschaos:litmus-sdk:<VERSION>'
<dependency>
<groupId>io.litmuschaos</groupId>
<artifactId>litmus-sdk</artifactId>
<version>VERSION</version>
</dependency>
LitmusClient contains simple, easy-to-use interface for making requests to litmus internal servers.
import io.litmuschaos.LitmusClient;
import io.litmuschaos.request.UserCreateRequest;
import io.litmuschaos.response.UserResponse;
String host = "http://localhost:3000"; // LitmusChaos frontend url
String token = "eyJhbGciOiJIUzUxMiIsInR..." // api token
LitmusClient litmusClient = new LitmusClient(host, token);
UserCreateRequest request = UserCreateRequest.builder()
.username("litmus")
.password("passwd")
.role("user")
.email("[email protected]")
.build();
UserResponse response = litmusClient.createUser(request);
You can customize httpClient configuration by injecting LitmusConfig
class.
LitmusConfig config = new LitmusConfig();
config.setHttpClientReadTimeoutMillis(1000L);
config.setHttpClientWriteTimeoutMillis(1000L);
config.setHttpClientConnectTimeoutMillis(1000L);
LitmusClient litmusClient = new LitmusClient("host", "token", config);
// if you don't need to set custom properties, just pass host and token.
// Default configurations are applied.
LitmusClient litmusClient = new LitmusClient("host", "token");
You need to understand projectionRoot
for using Litmus Java SDK well. When you access to litmus graphQL backend server by SDK, you can filter response field by projectionRoot.
GetEnvironmentGraphQLQuery query = new GetEnvironmentGraphQLQuery.Builder()
.projectID("567ccf04-7195-4311-a215-0803fe5e93f6")
.environmentID("test-environments")
.build();
GetEnvironmentProjectionRoot projectionRoot = new GetEnvironmentProjectionRoot<>()
.projectID()
.createdBy().userID().username().root()
.name()
.updatedBy().userID().username().root();
Environment response = litmusClient.getEnvironment(query, projectionRoot);
litmusClient only return fields that selected by projectionRoot.
{
projectID="567ccf04-7195-4311-a215-0803fe5e93f6",
name="test",
createdBy={
userID="567ccf04-7195-4311",
username="test-user",
email=null // not selected
}
description=null, // not selected
tags=null, // not selected
...
}
ProjectionRoot is tree data structure, so you can explore object graph by parent()
and root()
method.
- parent() : move to upper position
- root() : move to root position
{
"name": "test",
"faultName": "test fault",
"executedByExperment": {
"experimentID": "test-id",
"experimentName": "test-experiment",
"updatedBy": {
"username": "test-user", // If you call parent() here, you can access to experimentName field
"email": "[email protected]" // If you call root() here, you can access to faultName field
}
}
}
This project contains the following sample code
We'd love to have you contribute! Please refer to CONTRIBUTING for details.
Here is a copy of the License: License