Skip to content

Commit

Permalink
fix #39 ability to create folders in testrepo for imported cucumber t…
Browse files Browse the repository at this point in the history
…ests (#40)

Co-authored-by: Sergio Freire <[email protected]>
  • Loading branch information
bitcoder and Sergio Freire authored May 17, 2022
1 parent 529f181 commit 49e0ee1
Show file tree
Hide file tree
Showing 140 changed files with 1,838 additions and 76 deletions.
14 changes: 12 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Run maven as usual to get the dependencies and compile the code.

```bash
mvn clean compile
````
````<Xra>

### Testing

Expand All @@ -17,6 +17,16 @@ Each of the ITF tests runs a full maven build. The tests use WireMock to perform
mvn clean compile verify
```

To run just some integration tests (e.g., the ones under th "com.xblend.it.export_features.XrayDatacenterIT" class),

```bash
mvn "-Dit.test=com.xblend.it.export_features.XrayDatacenterIT.*" -DfailIfNoTests=false clean compile verify
```

More info [here](https://maven.apache.org/surefire/maven-failsafe-plugin/examples/single-test.html).

To debug the maven integration tests and see the maven stdout/stderr, we need to look under the folder `target/maven-it`. As an example, let's say that we run the maven IT test named "single_feature_by_issueKeys" contained in the com.xblend.it.XrayDatacenterIT class. In this case, we could analyze the logs and the project directory used by the maven instance inside the folder `target/maven-it/com/xblend/it/export_features/XrayDatacenterIT/single_feature_by_issueKeys/`.
### Deploying/Releasing
First, build, run the integration tests, and deploy.
Expand All @@ -33,6 +43,6 @@ Tag can be created at the moment of the creation of the release (easier) or it c
Example:

```bash
git tag -a "0.3.0" -m "v0.3.0"
git tag -a "0.5.0" -m "v0.5.0"
git push origin --tags
```
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [0.4.0] - 2022-05-17

### Added

- ability to organize the tests in Test Repository folders whenever importing tests from zipped Cucumber .feature files (Xray server/DC only)
- tests for importing/exporting Cucumber test scenarios

### Changed

### Fixed

## [0.3.0] - 2022-04-18

### Added
Expand Down Expand Up @@ -39,7 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

[unreleased]: https://github.com/Xray-App/xray-maven-plugin/compare/0.3.0...HEAD
[0.3.0]: https://github.com/Xray-App/xray-maven-plugin/compare/0.3.0...0.3.0
[unreleased]: https://github.com/Xray-App/xray-maven-plugin/compare/0.4.0...HEAD
[0.4.0]: https://github.com/Xray-App/xray-maven-plugin/compare/0.3.0...0.4.0
[0.3.0]: https://github.com/Xray-App/xray-maven-plugin/compare/0.2.0...0.3.0
[0.2.0]: https://github.com/Xray-App/xray-maven-plugin/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/Xray-App/xray-maven-plugin/releases/tag/0.1.0
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Add the following dependency to your pom.xml, where the `<configuration>` is opt
<dependency>
<groupId>com.xblend</groupId>
<artifactId>xray-maven-plugin</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
<scope>test</scope>
<configuration>
<clientId>215FFD69FE46447280000000000</clientId>
Expand Down Expand Up @@ -181,6 +181,7 @@ Note: how Xray relates the Scenarios/Background to the corresponding Test or Pre
| `testInfoJson` | `xray.testInfoJson` | path to a JSON file containing attributes to apply on the Test issues that may be created, following Jira issue update syntax | optional | - |
| `precondInfoJson` | `xray.precondInfoJson` | path to a JSON file containing attributes to apply on the Precondition issues that may be created, following Jira issue update syntax | optional | - |
| `inputFeatures` | `xray.inputFeatures` | either a .feature file, a directory containing .feature files, or a zipped file containing .feature files| mandatory | features/ |
| `updateRepository` | `xray.updateRepository` | create folder structure in Test Repository based on the folder structure in the .zip file containing the .feature files; default is false. Only supported on Xray server/DC. | optional | true |

#### Technical info of how it works (internal)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xblend</groupId>
<artifactId>xray-maven-plugin</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
<name>xray-maven-plugin</name>
<packaging>maven-plugin</packaging>
<url>https://raw.githubusercontent.com/Xray-App/xray-maven-plugin</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public class ImportFeaturesMojo extends AbstractMojo {
@Parameter(property = "xray.inputFeatures", required = false)
private String inputFeatures;

@Parameter(property = "xray.updateRepository", required = false)
private Boolean updateRepository;

@Parameter(property = "xray.abortOnError", required = false)
private Boolean abortOnError;

Expand All @@ -97,6 +100,8 @@ public class ImportFeaturesMojo extends AbstractMojo {

public void execute() throws MojoExecutionException, MojoFailureException {
XrayFeaturesImporter xrayFeaturesImporter;
JSONObject testInfo = null;
JSONObject precondInfo = null;
JSONArray response = null;

try {
Expand All @@ -105,6 +110,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().debug("projectId from config: " + projectId);
getLog().debug("source from config: " + source);
getLog().debug("inputFeatures from config: " + inputFeatures);
getLog().debug("updateRepository from config: " + updateRepository);

if (testInfoJson != null) {
testInfo = new JSONObject(new String(Files.readAllBytes(Paths.get(testInfoJson))));
}
if (precondInfoJson != null) {
precondInfo = new JSONObject(new String(Files.readAllBytes(Paths.get(precondInfoJson))));
}

if (cloud) {
xrayFeaturesImporter = new XrayFeaturesImporter.CloudBuilder(clientId, clientSecret)
Expand All @@ -115,25 +128,27 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.withProjectId(projectId)
.withSource(source)
.build();
response = xrayFeaturesImporter.importFrom(inputFeatures);
response = xrayFeaturesImporter.importFrom(inputFeatures, testInfo, precondInfo);
} else {
if (jiraToken != null) {
xrayFeaturesImporter = new XrayFeaturesImporter.ServerDCBuilder(jiraBaseUrl, jiraToken)
.withInternalTestProxy(useInternalTestProxy)
.withIgnoreSslErrors(ignoreSslErrors)
.withTimeout(timeout)
.withProjectKey(projectKey)
.withupdateRepository(updateRepository)
.build();
} else {
xrayFeaturesImporter = new XrayFeaturesImporter.ServerDCBuilder(jiraBaseUrl, jiraUsername, jiraPassword)
.withInternalTestProxy(useInternalTestProxy)
.withIgnoreSslErrors(ignoreSslErrors)
.withTimeout(timeout)
.withProjectKey(projectKey)
.withupdateRepository(updateRepository)
.build();
}

response = xrayFeaturesImporter.importFrom(inputFeatures);
response = xrayFeaturesImporter.importFrom(inputFeatures, testInfo, precondInfo);
}

getLog().info("response: " + response);
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/com/xblend/xray/XrayFeaturesImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class XrayFeaturesImporter {
private String projectKey;
private String projectId;
private String source;
private Boolean updateRepository = false;

private Boolean ignoreSslErrors = false;
private Boolean useInternalTestProxy = false;
Expand All @@ -58,6 +59,7 @@ private XrayFeaturesImporter(ServerDCBuilder builder) {
this.projectKey = builder.projectKey;
this.projectId = builder.projectId;
this.source = builder.source;
this.updateRepository = builder.updateRepository;

this.ignoreSslErrors = builder.ignoreSslErrors;
this.useInternalTestProxy = builder.useInternalTestProxy;
Expand Down Expand Up @@ -87,6 +89,7 @@ public static class ServerDCBuilder {
private String projectKey;
private String projectId; // unused
private String source; // unused
private Boolean updateRepository = false;

private Boolean ignoreSslErrors = false;
private Boolean useInternalTestProxy = false;
Expand Down Expand Up @@ -123,6 +126,11 @@ public ServerDCBuilder withProjectKey(String projectKey) {
return this;
}

public ServerDCBuilder withupdateRepository(Boolean updateRepository) {
this.updateRepository = updateRepository;
return this;
}

public XrayFeaturesImporter build() {
return new XrayFeaturesImporter(this);
}
Expand Down Expand Up @@ -187,27 +195,27 @@ public JSONArray importFrom(String inputPath) throws Exception {
if (clientId != null) {
return importCloud(inputPath, null, null);
} else {
return importServerDC(inputPath, null);
return importServerDC(inputPath, null, null);
}
}

public JSONArray importFrom(String inputPath, String testInfo) throws Exception {
public JSONArray importFrom(String inputPath, JSONObject testInfo) throws Exception {
if (clientId != null) {
return importCloud(inputPath, testInfo, null);
} else {
return importServerDC(inputPath, testInfo);
return importServerDC(inputPath, testInfo, null);
}
}

public JSONArray importFrom(String inputPath, String testInfo, String precondInfo) throws Exception {
public JSONArray importFrom(String inputPath, JSONObject testInfo, JSONObject precondInfo) throws Exception {
if (clientId != null) {
return importCloud(inputPath, testInfo, precondInfo);
} else {
return importServerDC(inputPath, testInfo);
return importServerDC(inputPath, testInfo, precondInfo);
}
}

public JSONArray importServerDC(String inputPath, String testInfo) throws Exception {
public JSONArray importServerDC(String inputPath, JSONObject testInfo, JSONObject precondInfo) throws Exception {
OkHttpClient client = CommonUtils.getHttpClient(this.useInternalTestProxy, this.ignoreSslErrors, this.timeout);

File inputFile = new File(inputPath);
Expand All @@ -227,6 +235,9 @@ public JSONArray importServerDC(String inputPath, String testInfo) throws Except
if (projectKey != null) {
builder.addQueryParameter("projectKey", this.projectKey);
}
if (updateRepository != null) {
builder.addQueryParameter("updateRepository", this.updateRepository.toString());
}

MediaType mediaType;
if (inputPath.toLowerCase().endsWith(".zip")) {
Expand All @@ -250,7 +261,10 @@ public JSONArray importServerDC(String inputPath, String testInfo) throws Except
.setType(MultipartBody.FORM)
.addFormDataPart(partName, inputFile.getName(), RequestBody.create(inputFile, mediaType));
if (testInfo != null) {
requestBodyBuilder = requestBodyBuilder.addFormDataPart("testInfo", "info.json", RequestBody.create(testInfo, MEDIA_TYPE_JSON));
requestBodyBuilder = requestBodyBuilder.addFormDataPart("testInfo", "testinfo.json", RequestBody.create(testInfo.toString(), MEDIA_TYPE_JSON));
}
if (precondInfo != null) {
requestBodyBuilder = requestBodyBuilder.addFormDataPart("preCondInfo", "precondinfo.json", RequestBody.create(precondInfo.toString(), MEDIA_TYPE_JSON));
}
requestBody = requestBodyBuilder.build();
} catch (Exception e1) {
Expand All @@ -275,7 +289,7 @@ public JSONArray importServerDC(String inputPath, String testInfo) throws Except
}
}

public JSONArray importCloud(String inputPath, String testInfo, String precondInfo) throws Exception {
public JSONArray importCloud(String inputPath, JSONObject testInfo, JSONObject precondInfo) throws Exception {
OkHttpClient client = CommonUtils.getHttpClient(this.useInternalTestProxy, this.ignoreSslErrors, this.timeout);

File inputFile = new File(inputPath);
Expand Down Expand Up @@ -335,10 +349,10 @@ public JSONArray importCloud(String inputPath, String testInfo, String precondIn
.setType(MultipartBody.FORM)
.addFormDataPart(partName, inputFile.getName(), RequestBody.create(inputFile, mediaType));
if (testInfo != null) {
requestBodyBuilder = requestBodyBuilder.addFormDataPart("testInfo", "testinfo.json", RequestBody.create(testInfo, MEDIA_TYPE_JSON));
requestBodyBuilder = requestBodyBuilder.addFormDataPart("testInfo", "testinfo.json", RequestBody.create(testInfo.toString(), MEDIA_TYPE_JSON));
}
if (precondInfo != null) {
requestBodyBuilder = requestBodyBuilder.addFormDataPart("precondInfo", "precondinfo.json", RequestBody.create(precondInfo, MEDIA_TYPE_JSON));
requestBodyBuilder = requestBodyBuilder.addFormDataPart("precondInfo", "precondinfo.json", RequestBody.create(precondInfo.toString(), MEDIA_TYPE_JSON));
}
requestBody = requestBodyBuilder.build();
} catch (Exception e1) {
Expand Down
23 changes: 20 additions & 3 deletions src/test/java/com/xblend/it/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@ public static String readFile(String path) throws IOException {
content = new String ( Files.readAllBytes( Paths.get(path) ) );
return content;
}

public static String readResourceFile(String path) throws IOException {

public static byte[] readRawResourceFile(String path) throws IOException {
return Files.readAllBytes( Paths.get("src/test/resources-its/com/xblend/it/" + path));

}

private static String readResourceFile(String path) throws IOException {
return readFile("src/test/resources-its/com/xblend/it/" + path);
}
}

public static String readResourceFileForImportResults(String path) throws IOException {
return readResourceFile("import_results/" + path);
}

public static String readResourceFileForImportFeatures(String path) throws IOException {
return readResourceFile("import_features/" + path);
}

public static String readResourceFileForExportFeatures(String path) throws IOException {
return readResourceFile("export_features/" + path);
}
}
Loading

0 comments on commit 49e0ee1

Please sign in to comment.