Skip to content

Commit 6898cec

Browse files
committed
GH-105: add initial excel files processing support
This update includes an initial experimental Excel files reader based on ZeroCell and Apache POI libraries. Fixes #105
1 parent c4a19bd commit 6898cec

File tree

15 files changed

+359
-132
lines changed

15 files changed

+359
-132
lines changed

README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ configurations {
174174
175175
dependencies {
176176
agent 'org.aspectj:aspectjweaver:1.9.7'
177-
implementation 'io.github.sskorol:test-data-supplier:1.9.5'
177+
implementation 'io.github.sskorol:test-data-supplier:1.9.7'
178178
}
179179
180180
test {
@@ -212,7 +212,7 @@ configurations {
212212
213213
dependencies {
214214
agent 'org.aspectj:aspectjweaver:1.9.7'
215-
implementation 'io.github.sskorol:test-data-supplier:1.9.5'
215+
implementation 'io.github.sskorol:test-data-supplier:1.9.7'
216216
}
217217
218218
compileJava {
@@ -301,9 +301,9 @@ public void supplyExternalData(final T data) {
301301

302302
Check **io.github.sskorol.testcases** package for more examples.
303303

304-
### JSON, CSV and YAML processors
304+
### JSON, CSV, YAML and XLSX processors
305305

306-
Test data supplier supports JSON, CSV and YML data retrieval. Assuming you have the following resources:
306+
Test data supplier supports JSON, CSV, YML and XLSX data retrieval. Assuming you have the following resources:
307307

308308
```csv
309309
username,password
@@ -341,6 +341,13 @@ username,password
341341
password: '123'
342342
```
343343
344+
```csv
345+
USERNAME PASSWORD
346+
admin admin
347+
sskorol password
348+
guest 123
349+
```
350+
344351
You can now map Java entities to these data sources using **@Source** annotation, which accepts either local file name
345352
or URL:
346353

@@ -375,12 +382,28 @@ public class User {
375382
}
376383
```
377384

385+
```java
386+
@Data
387+
@NoArgsConstructor
388+
@Source(path = "users.xlsx")
389+
public class User {
390+
@Column(name = "USERNAME", index = 0)
391+
private String username;
392+
393+
@Column(name = "PASSWORD", index = 1)
394+
private String password;
395+
}
396+
```
397+
378398
In case if some Java field's name differs from its data source representation, you can assign a valid name via
379399
**@FieldName** for CSV, **@SerializedName** for JSON and **@JsonProperty** for YML data type.
380400

381-
Note that local data sources must be located in a classpath.
401+
Excel support is experimental. [ZeroCell](https://github.com/creditdatamw/zerocell) library based on [Apache POI](https://github.com/apache/poi) is used here to simplify corresponding files processing.
402+
So feel free to check their API and supported annotations. However, in terms of fields' mapping, you can use **Column**.
403+
404+
Note that local data sources must be located in a classpath. You usually use **resources** folder for that.
382405

383-
Then in **DataSupplier** you can call special **TestDataReader** builder to retrieve data from CSV, JSON or YML data source.
406+
Then in **DataSupplier** you can call special **TestDataReader** builder to retrieve data from CSV, JSON, YML or XLSX data source.
384407
See javadocs to get more details.
385408

386409
```java
@@ -404,6 +427,13 @@ public StreamEx<User> getUsers() {
404427
}
405428
```
406429

430+
```java
431+
@DataSupplier
432+
public StreamEx<User> getUsers() {
433+
return use(XlsxReader.class).withTarget(User.class).read();
434+
}
435+
```
436+
407437
If you want to specify custom source in runtime, you can remove **@Source** annotation and use **withSource** builder
408438
method instead.
409439

@@ -503,7 +533,7 @@ Note that in case if you want to manage **DataProviderTransformer** manually, yo
503533

504534
```groovy
505535
dependencies {
506-
implementation 'io.github.sskorol:test-data-supplier:1.9.5:spi-off'
536+
implementation 'io.github.sskorol:test-data-supplier:1.9.7:spi-off'
507537
}
508538
```
509539

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dependencies {
4545
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
4646
api("org.jooq:joor:0.9.14")
4747
api("org.testng:testng:7.4.0")
48-
api('one.util:streamex:0.8.0')
48+
api('one.util:streamex:0.8.1')
4949
api("io.vavr:vavr:0.10.4")
5050
api("org.aspectj:aspectjrt:${aspectjVersion}")
5151
// Don't update to 0.9.12 due to bugs
@@ -54,6 +54,7 @@ dependencies {
5454
api("com.google.code.gson:gson:2.8.9")
5555
api("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}")
5656
api("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}")
57+
api("com.creditdatamw.labs:zerocell-core:0.5.1")
5758
testImplementation("org.assertj:assertj-core:3.11.1")
5859
}
5960

@@ -79,7 +80,7 @@ jacocoTestReport {
7980
}
8081

8182
tasks.named('wrapper') {
82-
gradleVersion = '7.2'
83+
gradleVersion = '7.3.3'
8384
}
8485

8586
compileJava {
@@ -125,6 +126,7 @@ test {
125126
'--add-opens', 'io.github.sskorol.testdatasupplier/io.github.sskorol.listeners=org.testng',
126127
'--add-opens', 'io.github.sskorol.testdatasupplier/io.github.sskorol.testcases=org.jooq.joor',
127128
'--add-opens', 'io.github.sskorol.testdatasupplier/io.github.sskorol.entities=org.jooq.joor',
129+
'--add-opens', 'io.github.sskorol.testdatasupplier/io.github.sskorol.entities=zerocell.core',
128130
'--add-opens', 'io.github.sskorol.testdatasupplier/io.github.sskorol.entities=com.fasterxml.jackson.databind',
129131
'--add-opens', 'io.github.sskorol.testdatasupplier/io.github.sskorol.datasuppliers=org.jooq.joor',
130132
'--add-opens', 'io.github.sskorol.testdatasupplier/io.github.sskorol.datasuppliers=org.testng',

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=1.9.6
1+
version=1.9.7
22
systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/jacoco.xml
33
systemProp.sonar.host.url=https://sonarcloud.io
44
systemProp.sonar.organization=sskorol-github

gradle/wrapper/gradle-wrapper.jar

841 Bytes
Binary file not shown.
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-7.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)