Skip to content

Commit

Permalink
GH-175: make it possible to supply collections w/o flat-mapping
Browse files Browse the repository at this point in the history
It was impossible to supply a collection as is into test method. It was automatically expanded. When we don't use `flatMap`, collections should always be injected in the original form w/o elements' extraction. This update adjust the collections processing behavior.

Apart from that, it covers dependency and template updates.
  • Loading branch information
sskorol committed Mar 3, 2023
1 parent 137ba46 commit 83fee51
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 94 deletions.
13 changes: 7 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ ToDo

### Environment

| Component | Version |
|--------------------|-----------------|
| Test Data Supplier | 2.0.0 |
| TestNG | 7.6.0 |
| Build tool | [email protected] |
| IDE | [email protected] |
| Component | Version |
|---------------------|-------------------|
| Test Data Supplier | 2.2.0 |
| TestNG | 7.7.1 |
| Build tool | [email protected] |
| IDE | [email protected] |
| JDK | temurin-17.0.6 |

### Can be reproduced via

Expand Down
13 changes: 7 additions & 6 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ ToDo

### Environment

| Component | Version |
|--------------------|-----------------|
| Test Data Supplier | 2.0.0 |
| TestNG | 7.6.0 |
| Build tool | [email protected] |
| IDE | [email protected] |
| Component | Version |
|--------------------|-------------------|
| Test Data Supplier | 2.2.0 |
| TestNG | 7.7.1 |
| Build tool | [email protected] |
| IDE | [email protected] |
| JDK | temurin-17.0.6 |

### Can be reproduced via

Expand Down
11 changes: 0 additions & 11 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
[//]: # (
. Thank you so much for sending us a pull request!
.
. Make sure you have a clear name for your pull request.
. To link the request with isses use the following notation: (fixes #123, fixes #321\)
.
. An example of good pull request names:
. - Factory annotation processing support (fixes #123\)
. - Add an ability to handle external data sources
)

### Context
[//]: # (
. Describe the problem or feature.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
distribution: 'temurin'
- name: Build and Test on manual PR
if: ${{ github.actor != 'dependabot[bot]' }}
env:
SONAR_URL: ${{ secrets.SONAR_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: ./gradlew clean sonarqube
run: ./gradlew clean sonar
- name: Built and Test on Depenabot PR
if: ${{ github.actor == 'dependabot[bot]' }}
run: ./gradlew clean test
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Test Data Supplier Changelog

## 2.2.0

**feat(collections): Supply collections in raw format**

* GH-175: made it possible to supply collections w/o auto flat-mapping by @sskorol
* Updated outdated deps and templates by @sskorol

## 2.1.0

**feat(excel): Implement custom excel files processor**

* GH-130: replaced ZeroCell with custom implementation by @sskorol in #132
* Automated dependency checks with dependabot by @sskorol

## 2.0.0
**feat(java): migrate to Java 17**

Expand Down
35 changes: 31 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,35 @@ clean build publishToMavenLocal --stacktrace
```

Note that you must set `SIGNING_KEY_ID`, `SIGNING_KEY` and `SIGNING_PASSWORD` environment variables to publish artifacts
to Maven local for external testing. You can get these values when you set up `GPG2`.
to Maven local for external testing. You can get these values when you set up `GPG2` key:

```shell
gpg2 --full-generate-key
```

Use 4096-bit RSA encoding. Ensure that email matches your GitHub profile. The passphrase == `SIGNING_PASSWORD`.

Use the following command to get your private `SIGNING_KEY`:

```shell
gpg2 --export-secret-keys --armor D028459F448C1F19 | cat
```

You should copy the main output block between newlines and paste it to your `SIGNING_KEY` env var.

`SIGNING_KEY_ID` can be obtained from the following output:

```shell
gpg2 --list-secret-keys --keyid-format LONG
```

You'll see something like:

```shell
sec rsa4096/XXXXXXXXXXXXXXXXX 2023-01-01 [SC]
```

Copy the last 8 characters of the key and paste it to `SIGNING_KEY_ID` env var.

### Test

Expand All @@ -48,8 +76,7 @@ that the default listening port should be changed to 5005.
When you start your [test](#test) configuration, you'll enter a "listening for remote connections" mode after
compilation.
Then you have to switch to a previously created `Remote JVM Debug` configuration and run it. It'll connect to a
specified
port and let you drill into debug mode.
specified port and let you drill into debug mode.

## Process

Expand All @@ -68,4 +95,4 @@ port and let you drill into debug mode.
- When testing is finished, you can push your changes and create a pull request based on proposed template.
- Code review usually takes some time and require potential changes.
- When you get an approval, make sure you squash your commits before merging.
- To merge your changes to the upstream, use a rebase strategy to keep Git history clean.
- To merge your changes to the upstream, use a rebase strategy to keep Git history clean.
85 changes: 59 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
## Table of Contents

- [Description](#description)
- [Supported Flags](#supported-flags)
- [Supported Return Types](#supported-return-types)
- [Usage](#usage)
- [Gradle - Java < 9](#gradle---java--9)
Expand All @@ -35,7 +36,7 @@

## Description

This repository contains TestNG **DataProvider** wrapper (the latest version is based on TestNG 7.6.0) which helps to supply test data in a more flexible way.
This repository contains TestNG **DataProvider** wrapper (the latest version is based on TestNG 7.7.1) which helps to supply test data in a more flexible way.

Common **DataProvider** forces using quite old and ugly syntax which expects one of the following types to be returned from DP method's body:

Expand All @@ -49,12 +50,14 @@ Just imagine if you could use the following syntax to supply some filtered and s
```java
@DataSupplier
public Stream<User> getData() {
return Stream.of(
new User("Petya", "password2"),
new User("Virus Petya", "password3"),
new User("Mark", "password1"))
.filter(u -> !u.getName().contains("Virus"))
.sorted(comparing(User::getPassword));
return Stream
.of(
new User("Max", "password2"),
new User("Black Fox", "password3"),
new User("Mark", "password1")
)
.filter(u -> !u.getName().contains("Fox"))
.sorted(comparing(User::getPassword));
}

@Test(dataProvider = "getData")
Expand All @@ -65,24 +68,40 @@ public void shouldSupplyStreamData(final User user) {

Much better and flexible than two-dimensional arrays or iterators, isn't it?

And what if we don't want to iterate the same test N times depending on collection size? What if we want to extract its values and inject into test's signature like the following?
And what if we don't want to iterate the same test N times depending on collection size? What if we want to inject it into test's signature like the following?

```java
@DataSupplier(transpose = true)
public List<User> getExtractedData() {
return StreamEx.of(
new User("username1", "password1"),
new User("username2", "password2"))
.toList();
public List<User> getTransposedData() {
return StreamEx
.of(
new User("username1", "password1"),
new User("username2", "password2")
)
.toList();
}

@Test(dataProvider = "getTransposedData")
public void shouldSupplyExtractedListData(final List<User> users) {
// ...
}
```

Or if you want to extract the values of your collection and inject into test's signature, you can combine `transpose` with a `flatMap`:

```java
@DataSupplier(transpose = true, flatMap = true)
public Set<User> getExtractedData() {
return StreamEx.of("product1", "product2", "product1").toSet();
}

@Test(dataProvider = "getExtractedData")
public void shouldSupplyExtractedListData(final User... users) {
public void shouldSupplyExtractedListData(final String... products) {
// ...
}
```

You can do even more if you want to perform a Java-like **flatMap** operation for each row:
Java-like **flatMap** operation can be applied even to more complicated structures like `Map` to extract values for each row:

```java
@DataSupplier(flatMap = true)
Expand All @@ -98,6 +117,17 @@ public void supplyInternallyExtractedMapData(final Integer key, final String val

[**Go top**](#test-data-supplier) :point_up:

## Supported flags

- **name**: sets a custom name for `DataSupplier` (method name is used by default)
- **transpose**: translates data column into a single row
- **flatMap**: behaves pretty much like a native Java Stream operation
- **runInParallel**: executes each data-driven test in parallel rather than sequentially
- **indices**: filters the underlying collection by given indices
- **propagateTestFailure**: fails the test in case of `DataSupplier` failure (skips by default)

[**Go top**](#test-data-supplier) :point_up:

## Supported return types

- Collection
Expand Down Expand Up @@ -359,7 +389,7 @@ module your.module.name {

### Gradle - Java 17+ w/o modules

Note that `test-data-supplier:2.0.0` has been compiled with java 17. It means you must use the same language level in your build file.
Note that `test-data-supplier:2.0.0+` has been compiled with java 17. It means you must use the same language level in your build file.

```groovy
plugins {
Expand All @@ -377,7 +407,7 @@ configurations {
}
ext {
aspectjVersion = '1.9.9.1'
aspectjVersion = '1.9.19'
}
[compileJava, compileTestJava]*.options*.compilerArgs = ['-parameters']
Expand All @@ -386,14 +416,17 @@ dependencies {
agent "org.aspectj:aspectjweaver:${aspectjVersion}"
implementation(
"org.aspectj:aspectjweaver:${aspectjVersion}",
'org.testng:testng:7.6.0',
'io.github.sskorol:test-data-supplier:2.0.0'
'org.testng:testng:7.7.1',
'io.github.sskorol:test-data-supplier:2.2.0'
)
}
test {
doFirst {
jvmArgs("-javaagent:${configurations.agent.singleFile}")
jvmArgs(
"-javaagent:${configurations.agent.singleFile}",
'--add-opens', 'java.base/java.lang=ALL-UNNAMED'
)
}
useTestNG()
Expand All @@ -406,10 +439,10 @@ test {

```xml
<properties>
<aspectj.version>1.9.9.1</aspectj.version>
<aspectj.version>1.9.19</aspectj.version>
<java.version>17</java.version>
<compiler.plugin.version>3.10.1</compiler.plugin.version>
<surefire.plugin.version>3.0.0-M6</surefire.plugin.version>
<compiler.plugin.version>3.11.0</compiler.plugin.version>
<surefire.plugin.version>3.0.0-M9</surefire.plugin.version>
</properties>

<dependencies>
Expand All @@ -421,12 +454,12 @@ test {
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.6.0</version>
<version>7.7.1</version>
</dependency>
<dependency>
<groupId>io.github.sskorol</groupId>
<artifactId>test-data-supplier</artifactId>
<version>2.0.0</version>
<version>2.2.0</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -823,7 +856,7 @@ Note that in case if you want to manage **DataProviderTransformer** manually, yo

```groovy
dependencies {
implementation 'io.github.sskorol:test-data-supplier:1.9.7:spi-off'
implementation 'io.github.sskorol:test-data-supplier:2.2.0:spi-off'
}
```

Expand Down
Loading

0 comments on commit 83fee51

Please sign in to comment.