Skip to content

Commit 5faea76

Browse files
committed
GH-197: added dynamic xlsx sheets support
If xlsx sheets have the same structure, it's now possible to retrieve data from multiple sources with `additionalSources` builder method.
1 parent f281962 commit 5faea76

File tree

19 files changed

+234
-77
lines changed

19 files changed

+234
-77
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ ToDo
3030

3131
### Environment
3232

33-
| Component | Version |
34-
|---------------------|-------------------|
35-
| Test Data Supplier | 2.2.0 |
36-
| TestNG | 7.7.1 |
37-
| Build tool | gradle@7.6.0 |
38-
| IDE | IntelliJ@2022.2.3 |
39-
| JDK | temurin-17.0.6 |
33+
| Component | Version |
34+
|---------------------|-----------------|
35+
| Test Data Supplier | 2.2.0 |
36+
| TestNG | 7.8.0 |
37+
| Build tool | gradle@8.2.1 |
38+
| IDE | IntelliJ@2023.2 |
39+
| JDK | temurin-17.0.8 |
4040

4141
### Can be reproduced via
4242

4343
- [ ] Bash
4444
- [ ] Maven
4545
- [ ] Gradle
46-
- [ ] Eclipse
4746
- [ ] IntelliJ
4847

4948
### Expected behavior

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ ToDo
3030

3131
### Environment
3232

33-
| Component | Version |
34-
|--------------------|-------------------|
35-
| Test Data Supplier | 2.2.0 |
36-
| TestNG | 7.7.1 |
37-
| Build tool | gradle@7.6.0 |
38-
| IDE | IntelliJ@2022.2.3 |
39-
| JDK | temurin-17.0.6 |
33+
| Component | Version |
34+
|--------------------|-----------------|
35+
| Test Data Supplier | 2.2.0 |
36+
| TestNG | 7.8.0 |
37+
| Build tool | gradle@8.2.1 |
38+
| IDE | IntelliJ@2023.2 |
39+
| JDK | temurin-17.0.8 |
4040

4141
### Can be reproduced via
4242

4343
- [ ] Bash
4444
- [ ] Maven
4545
- [ ] Gradle
46-
- [ ] Eclipse
4746
- [ ] IntelliJ
4847

4948
### Expected behavior

.github/pull_request_template.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ Closes #
99
### Checklist
1010
- [ ] Added unit / integration tests
1111
- [ ] Added documentation
12+
- [ ] Updated configuration
13+
- [ ] None of the above is required

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ jobs:
3131
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3232
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
3333
run: ./gradlew clean sonar
34-
- name: Built and Test on Depenabot PR
34+
- name: Built and Test on Dependabot PR
3535
if: ${{ github.actor == 'dependabot[bot]' }}
3636
run: ./gradlew clean test

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ dependencies {
416416
agent "org.aspectj:aspectjweaver:${aspectjVersion}"
417417
implementation(
418418
"org.aspectj:aspectjweaver:${aspectjVersion}",
419-
'org.testng:testng:7.7.1',
420-
'io.github.sskorol:test-data-supplier:2.2.0'
419+
'org.testng:testng:7.8.0',
420+
'io.github.sskorol:test-data-supplier:2.3.0'
421421
)
422422
}
423423
@@ -454,12 +454,12 @@ test {
454454
<dependency>
455455
<groupId>org.testng</groupId>
456456
<artifactId>testng</artifactId>
457-
<version>7.7.1</version>
457+
<version>7.8.0</version>
458458
</dependency>
459459
<dependency>
460460
<groupId>io.github.sskorol</groupId>
461461
<artifactId>test-data-supplier</artifactId>
462-
<version>2.2.0</version>
462+
<version>2.3.0</version>
463463
</dependency>
464464
</dependencies>
465465

@@ -629,6 +629,8 @@ Since 2.1.0, there's a custom implementation with similar approach, but minor im
629629

630630
In terms of fields' mapping, you can use custom `@Column` annotation (don't confuse with ZeroCell Column).
631631
You should also make sure you provided a sheet name via corresponding `@Sheet` annotation. Otherwise, the first one will be used.
632+
In case if you have a similar structure on multiple sheets, you can use a repeatable `@Sheets` annotation.
633+
Dynamic sheets' specification is also possible via `withAdditionalSources` builder method (see examples below).
632634

633635
Similarly to ZeroCell, you can use either default or custom fields' converters. Here's a list of defaults:
634636

@@ -694,8 +696,16 @@ public StreamEx<User> getUsers() {
694696
}
695697
```
696698

699+
```java
700+
@DataSupplier
701+
public StreamEx<User> getUsers() {
702+
return use(XlsxReader.class).withTarget(User.class).withAdditionalSources("Sheet1", "Sheet2").read();
703+
}
704+
```
705+
697706
If you want to specify a custom source in runtime, you can remove **@Source** annotation and use **withSource** builder
698707
method instead.
708+
`withAdditionalSources` builder method is experimental and implemented for `XlsxReader` as a dynamic sheets provider.
699709

700710
Note that in case of a data reading error or any kind of exception thrown in a `@DataSupplier` body,
701711
the corresponding test will be skipped. That's a default TestNG behaviour.
@@ -856,7 +866,7 @@ Note that in case if you want to manage **DataProviderTransformer** manually, yo
856866

857867
```groovy
858868
dependencies {
859-
implementation 'io.github.sskorol:test-data-supplier:2.2.0:spi-off'
869+
implementation 'io.github.sskorol:test-data-supplier:2.3.0:spi-off'
860870
}
861871
```
862872

build.gradle.kts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
jacoco
88
`maven-publish`
99
signing
10-
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
10+
id("io.github.gradle-nexus.publish-plugin") version "2.0.0-rc-1"
1111
id("org.sonarqube") version "4.3.0.3225"
1212
id("net.researchgate.release") version "3.0.2"
1313
id("com.github.ben-manes.versions") version "0.47.0"
@@ -22,9 +22,21 @@ val projectUrl by extra("https://github.com/sskorol/test-data-supplier")
2222
val moduleName by extra("io.github.sskorol.testdatasupplier")
2323

2424
val aspectjVersion by extra("1.9.19")
25-
val jacksonVersion by extra("2.14.2")
26-
val lombokVersion by extra("1.18.26")
25+
val jacksonVersion by extra("2.15.2")
26+
val lombokVersion by extra("1.18.28")
2727
val poiVersion by extra("5.2.3")
28+
val joorVersion by extra ("0.9.14")
29+
val testngVersion by extra("7.8.0")
30+
val streamexVersion by extra("0.8.1")
31+
// Don't update to the latest, as it's outdated
32+
val vavrVersion by extra("0.10.4")
33+
val reflectionsVersion by extra("0.10.2")
34+
val commonsCsvVersion by extra("1.10.0")
35+
val gsonVersion by extra("2.10.1")
36+
val assertjVersion by extra("3.24.2")
37+
val logbackVersion by extra("1.4.8")
38+
val log4jVersion by extra("2.20.0")
39+
val mockitoVersion by extra("5.4.0")
2840

2941
val agent: Configuration by configurations.creating
3042

@@ -63,24 +75,24 @@ dependencies {
6375
testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
6476
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
6577
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
66-
api("org.jooq:joor:0.9.14")
67-
api("org.testng:testng:7.8.0")
68-
api("one.util:streamex:0.8.1")
69-
api("io.vavr:vavr:0.10.4")
78+
api("org.jooq:joor:${joorVersion}")
79+
api("org.testng:testng:${testngVersion}")
80+
api("one.util:streamex:${streamexVersion}")
81+
api("io.vavr:vavr:${vavrVersion}")
7082
api("org.aspectj:aspectjrt:${aspectjVersion}")
71-
api("org.reflections:reflections:0.10.2")
72-
api("org.apache.commons:commons-csv:1.10.0")
73-
api("com.google.code.gson:gson:2.10.1")
83+
api("org.reflections:reflections:${reflectionsVersion}")
84+
api("org.apache.commons:commons-csv:${commonsCsvVersion}")
85+
api("com.google.code.gson:gson:${gsonVersion}")
7486
api("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}")
7587
api("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}")
7688
api("org.apache.poi:poi:${poiVersion}")
7789
api("org.apache.poi:poi-ooxml:${poiVersion}")
78-
api("org.assertj:assertj-core:3.24.2")
90+
api("org.assertj:assertj-core:${assertjVersion}")
7991
// Transitive dependency: <=1.33 version has vulnerabilities. Remove when updated by top-level packages.
8092
api("org.yaml:snakeyaml:2.0")
81-
testImplementation("ch.qos.logback:logback-classic:1.4.8")
82-
testImplementation("org.apache.logging.log4j:log4j-core:2.20.0")
83-
testImplementation("org.mockito:mockito-core:5.4.0")
93+
testImplementation("ch.qos.logback:logback-classic:${logbackVersion}")
94+
testImplementation("org.apache.logging.log4j:log4j-core:${log4jVersion}")
95+
testImplementation("org.mockito:mockito-core:${mockitoVersion}")
8496
}
8597

8698
jacoco.toolVersion = "0.8.8"
@@ -128,7 +140,7 @@ tasks.withType<JacocoReport> {
128140
}
129141

130142
tasks.withType(Wrapper::class) {
131-
gradleVersion = "8.0.1"
143+
gradleVersion = "8.2.1"
132144
}
133145

134146
tasks.compileJava {
@@ -231,7 +243,7 @@ publishing {
231243
developers {
232244
developer {
233245
id.set("sskorol")
234-
name.set("Sergey Korol")
246+
name.set("Serhii Korol")
235247
email.set("serhii.s.korol@gmail.com")
236248
}
237249
}
@@ -250,7 +262,7 @@ publishing {
250262
}
251263

252264
nexusPublishing {
253-
repositories {
265+
this.repositories {
254266
sonatype {
255267
val osshUsername = System.getenv("OSSH_USERNAME") ?: ""
256268
val osshPassword = System.getenv("OSSH_PASSWORD") ?: ""
@@ -295,6 +307,8 @@ tasks.jar {
295307
}
296308

297309
tasks.register<Jar>("sourceJar") {
310+
group = "sourceJar"
311+
description = "Build a jar from sources"
298312
dependsOn(tasks.classes)
299313
inputs.property("moduleName", moduleName)
300314
manifest {
@@ -315,6 +329,8 @@ tasks.register<Jar>("sourceJar") {
315329
}
316330

317331
tasks.register<Jar>("spiOffJar") {
332+
group = "spiOffJar"
333+
description = "Build a jar from sources excluding SPI"
318334
dependsOn(tasks.classes)
319335
inputs.property("moduleName", moduleName)
320336
manifest {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=2.2.1
1+
version=2.3.0
22
systemProp.sonar.host.url=https://sonarcloud.io
33
systemProp.sonar.projectKey=io.github.sskorol:test-data-supplier
44
systemProp.sonar.organization=sskorol-github
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/io/github/sskorol/data/DataReader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.IOException;
66
import java.net.URL;
7+
import java.util.List;
78

89
import static io.github.sskorol.utils.ReflectionUtils.getSourcePath;
910

@@ -15,6 +16,10 @@ public interface DataReader<T> {
1516

1617
String getPath();
1718

19+
default DataReader<T> additionalSources(final List<String> names) {
20+
return this;
21+
}
22+
1823
default URL getUrl() throws IOException {
1924
return getPath().isEmpty() ? getSourcePath(getEntityClass()) : getSourcePath(getPath());
2025
}

src/main/java/io/github/sskorol/data/Sheet.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package io.github.sskorol.data;
22

3-
import java.lang.annotation.ElementType;
4-
import java.lang.annotation.Retention;
5-
import java.lang.annotation.RetentionPolicy;
6-
import java.lang.annotation.Target;
3+
import java.lang.annotation.*;
74

85
/**
96
* Use this annotation to provide Excel sheet name. If none is specified hte first one is used.
107
*/
8+
@Repeatable(Sheets.class)
119
@Target(ElementType.TYPE)
1210
@Retention(RetentionPolicy.RUNTIME)
1311
public @interface Sheet {

0 commit comments

Comments
 (0)