Skip to content

Commit

Permalink
Merge pull request #6 from telekom/feature/prepare-for-tt2
Browse files Browse the repository at this point in the history
Updated connector for Testerra 2
  • Loading branch information
martingrossmann authored Jul 21, 2022
2 parents 86dd950 + 395f653 commit 8c0d575
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 74 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,28 @@ It will register automatically by using Testerra `ModuleHook`, but you have to p
### Requirements


| Azure devops connector | Testerra |
| -------------------- | --------------|
| `>= 1.0` | `>= 1.9` |
| Azure devops connector | Testerra |
|------------------------|----------|
| `>= 1.0` | `>= 1.9` |
| `>= 2.0` | `>=2.0` |

Tested with API version 5.0 at Azure DevOps Server 2020 Update 1.1 (5.1 and 6.0 are not working, cannot add result to run)

### Usage

Include the following dependency in your project.

Gradle:
````groovy
implementation 'io.testerra:azure-devops-connector:1.2'
implementation 'io.testerra:azure-devops-connector:2.0'
````

Maven:
````xml
<dependency>
<groupId>io.testerra</groupId>
<artifactId>azure-devops-connector</artifactId>
<version>1.2</version>
<version>2.0</version>
</dependency>
````

Expand All @@ -65,7 +68,7 @@ Add the property file ``azuredevops.properties`` and add project specific settin
| azure.user | na. | User with permissions to execute test cases (create/update test runs, create test results) |
| azure.token | na. | Token must generated in Azure DevOps in Profile -> Security -> Personal Access Token |
| azure.sync.enabled | false | Flag, if test result sync is activated |
| azure.project.root | na. | Root of REST API of the project, e.g. `agile/<project>/_apis` |
| azure.api.root | na. | Root of REST API of the project, e.g. `agile/<project>/_apis` |
| azure.api.version | na. | Current API version of your Azure DevOps system, e.g. `5.1` |
| azure.api.version.get.points | azure.api.version | In some cases the endpoint for getting the test points differs from general API version, e.g. `5.1-preview.2` |
| azure.testplan.id | na. | Define the test plan where your test cases are added. |
Expand Down Expand Up @@ -95,10 +98,6 @@ Steps for sync
| 4 | Create a test result and add it to the run. | Request contains the test point. https://docs.microsoft.com/en-us/rest/api/azure/devops/test/results/add?view=azure-devops-rest-6.0 |
| 5 | Update the run | Set finisher date and close the run. https://docs.microsoft.com/en-us/rest/api/azure/devops/test/runs/update?view=azure-devops-rest-6.0 |

### Compatibility

- Tested with API version 5.0 at Azure DevOps Server 2020 Update 1.1 (5.1 and 6.0 are not working, cannot add result to run)

---

## Publication
Expand All @@ -107,15 +106,15 @@ This module is deployed and published to Maven Central. All JAR files are signed

The following properties have to be set via command line or ``~/.gradle/gradle.properties``

| Property | Description |
| ----------------------------- | --------------------------------------------------- |
| `moduleVersion` | Version of deployed module, default is `1-SNAPSHOT` |
| `deployUrl` | Maven repository URL |
| `deployUsername` | Maven repository username |
| `deployPassword` | Maven repository password |
| `signing.keyId` | GPG private key ID (short form) |
| `signing.password` | GPG private key password |
| `signing.secretKeyRingFile` | Path to GPG private key |
| Property | Description |
|-----------------------------|-----------------------------------------------------|
| `moduleVersion` | Version of deployed module, default is `1-SNAPSHOT` |
| `deployUrl` | Maven repository URL |
| `deployUsername` | Maven repository username |
| `deployPassword` | Maven repository password |
| `signing.keyId` | GPG private key ID (short form) |
| `signing.password` | GPG private key password |
| `signing.secretKeyRingFile` | Path to GPG private key |

If all properties are set, call the following to build, deploy and release this module:
````shell
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ apply plugin: 'io.codearte.nexus-staging'

ext {
// Minimum required Testerra version
testerraCompileVersion = '1.12'
testerraCompileVersion = '2.0'
// Unit tests use the latest Testerra version
testerraTestVersion = '[1.12,2-SNAPSHOT)'
testerraTestVersion = '[2,3-SNAPSHOT)'

// Default version
moduleVersion = '1-SNAPSHOT'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

package eu.tsystems.mms.tic.testerra.plugins.azuredevops.config;

import eu.tsystems.mms.tic.testframework.common.PropertyManager;
import eu.tsystems.mms.tic.testframework.common.IProperties;
import eu.tsystems.mms.tic.testframework.common.PropertyManagerProvider;
import eu.tsystems.mms.tic.testframework.logging.Loggable;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -36,45 +37,45 @@
*
* @author mgn
*/
public class AzureDevOpsConfig implements Loggable {

private static final String FILE_NAME = "azuredevops.properties";

private static AzureDevOpsConfig instance = null;

private String azureUrl;

private String azureUser;

private String azureUserToken;

private String azureAuthenticationString;

private String azureApiRoot;
public class AzureDevOpsConfig implements Loggable, PropertyManagerProvider {

public enum Properties implements IProperties {
AZURE_URL("azure.url", ""),
AZURE_USER("azure.user", ""),
AZURE_TOKEN("azure.token", ""),
AZURE_SYNC_ENABLED("azure.sync.enabled", false),
AZURE_API_ROOT("azure.api.root", ""),
AZURE_API_VERSION("azure.api.version", ""),
AZURE_API_VERSION_POINTS("azure.api.version.get.points", Properties.AZURE_API_VERSION.asString()),
AZURE_TESTPLAN_ID("azure.testplan.id", 0),
AZURE_RUN_NAME("azure.run.name", LocalDateTime.now().toString());

private final String property;
private final Object defaultValue;

Properties(String property, Object defaultValue) {
this.property = property;
this.defaultValue = defaultValue;
}

private String azureApiVersion;
@Override
public Object getDefault() {
return defaultValue;
}

private String azureApiVersionGetPoints;
@Override
public String toString() {
return property;
}
}

private static AzureDevOpsConfig instance = null;
private final String azureAuthenticationString;
private boolean azureSyncEnabled = false;

private int azureTestPlanId;

private String azureRunName;

private AzureDevOpsConfig() {
PropertyManager.loadProperties(FILE_NAME);

this.azureUrl = PropertyManager.getProperty("azure.url") + "/";
this.azureUser = PropertyManager.getProperty("azure.user");
this.azureUserToken = PropertyManager.getProperty("azure.token");
this.azureSyncEnabled = PropertyManager.getBooleanProperty("azure.sync.enabled", false);
this.azureApiRoot = PropertyManager.getProperty("azure.project.root") + "/";
this.azureApiVersion = PropertyManager.getProperty("azure.api.version");
this.azureApiVersionGetPoints = PropertyManager.getProperty("azure.api.version.get.points", this.azureApiVersion);

this.azureTestPlanId = PropertyManager.getIntProperty("azure.testplan.id", 0);
this.azureRunName = PropertyManager.getProperty("azure.run.name", LocalDateTime.now().toString());
PROPERTY_MANAGER.loadProperties("azuredevops.properties");
this.azureSyncEnabled = Properties.AZURE_SYNC_ENABLED.asBool();

// Store generated authorization string
this.azureAuthenticationString = generateAuthorizationString();
Expand All @@ -90,15 +91,15 @@ public static synchronized AzureDevOpsConfig getInstance() {
}

public String getAzureUrl() {
return this.azureUrl;
return Properties.AZURE_URL.asString() + "/";
}

public String getAzureUser() {
return this.azureUser;
return Properties.AZURE_USER.asString();
}

public String getAzureUserToken() {
return this.azureUserToken;
return Properties.AZURE_TOKEN.asString();
}

/**
Expand All @@ -118,27 +119,27 @@ public String getAzureAuthenticationString() {
}

public String getAzureApiRoot() {
return azureApiRoot;
return Properties.AZURE_API_ROOT.asString() + "/";
}

public String getAzureApiVersion() {
return azureApiVersion;
return Properties.AZURE_API_VERSION.asString();
}

public String getAzureApiVersionGetPoints() {
return azureApiVersionGetPoints;
public String getAzureApiVersionPoints() {
return Properties.AZURE_API_VERSION_POINTS.asString();
}

public boolean isAzureSyncEnabled() {
return this.azureSyncEnabled;
}

public int getAzureTestPlanId() {
return this.azureTestPlanId;
return Math.toIntExact(Properties.AZURE_TESTPLAN_ID.asLong());
}

public String getAzureRunName() {
return azureRunName;
return Properties.AZURE_RUN_NAME.asString();
}

public void deactivateResultSync() {
Expand All @@ -156,19 +157,19 @@ private void checkProperties() {
log().error("Azure DevOps URL is not valid.");
this.azureSyncEnabled = false;
}
if (StringUtils.isEmpty(this.azureUser)) {
if (StringUtils.isEmpty(Properties.AZURE_USER.asString())) {
log().error("Azure DevOps user is not defined.");
}
if (StringUtils.isEmpty(this.azureAuthenticationString)) {
log().error("Azure DevOps user token is not defined.");
}
if (StringUtils.isEmpty(this.azureApiRoot)) {
if (StringUtils.isEmpty(Properties.AZURE_API_ROOT.asString())) {
log().error("Azure DevOps API root is not defined.");
}
if (StringUtils.isEmpty(this.azureApiVersion)) {
if (StringUtils.isEmpty(Properties.AZURE_API_VERSION.asString())) {
log().error("Azure DevOps API version is not defined.");
}
if (this.azureTestPlanId == 0) {
if (Properties.AZURE_TESTPLAN_ID.asLong() == 0) {
log().error("Azure DevOps testplan ID is not defined.");
}
if (!this.azureSyncEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@

package eu.tsystems.mms.tic.testerra.plugins.azuredevops.hook;

import com.google.inject.AbstractModule;
import eu.tsystems.mms.tic.testerra.plugins.azuredevops.synchronize.AzureDevOpsResultSynchronizer;
import eu.tsystems.mms.tic.testframework.common.Testerra;
import eu.tsystems.mms.tic.testframework.hooks.ModuleHook;
import eu.tsystems.mms.tic.testframework.report.TesterraListener;

/**
* Created on 17.11.2020
*
* @author mgn
*/
public class AzureDevOpsConnectorHook implements ModuleHook {
public class AzureDevOpsConnectorHook extends AbstractModule implements ModuleHook {

private static AzureDevOpsResultSynchronizer synchronizer;

@Override
public void init() {
synchronizer = new AzureDevOpsResultSynchronizer();
TesterraListener.getEventBus().register(synchronizer);

Testerra.getEventBus().register(synchronizer);
}

@Override
public void terminate() {
synchronizer.shutdown();
TesterraListener.getEventBus().unregister(synchronizer);
Testerra.getEventBus().unregister(synchronizer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Points getPoints(PointsFilter filter) {
Points points = new Points();
points.setPointsFilter(filter);

Response response = this.getBuilder("test/points", this.getApiVersion(this.config.getAzureApiVersionGetPoints())).post(Entity.entity(points, MediaType.APPLICATION_JSON));
Response response = this.getBuilder("test/points", this.getApiVersion(this.config.getAzureApiVersionPoints())).post(Entity.entity(points, MediaType.APPLICATION_JSON));

if (response.getStatus() != HttpStatus.SC_OK) {
ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
Expand Down

0 comments on commit 8c0d575

Please sign in to comment.