-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from passedbylove/1.18.0
1.18.0 a new feature, support stream-based cell mapping
- Loading branch information
Showing
11 changed files
with
455 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/poiji/exception/InvalidExcelStreamException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.poiji.exception; | ||
|
||
/** | ||
* Created by passedbylove on 2019-04-18. | ||
*/ | ||
public final class InvalidExcelStreamException extends PoijiException { | ||
|
||
public InvalidExcelStreamException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/com/poiji/deserialize/DeserializersByNameTagWithWhiteSpaceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.poiji.deserialize; | ||
|
||
|
||
import com.poiji.bind.Poiji; | ||
import com.poiji.deserialize.model.byid.Employee; | ||
import com.poiji.deserialize.model.byid.Employee2; | ||
import com.poiji.deserialize.model.byname.EmployeeByName; | ||
import com.poiji.deserialize.model.byname.EmployeeByName2; | ||
import com.poiji.option.PoijiOptions; | ||
import com.poiji.option.PoijiOptions.PoijiOptionsBuilder; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static com.poiji.util.Data.unmarshallingDeserialize; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.fail; | ||
|
||
/** | ||
* Created by passedbylove@gmail.com on 2018-11-15. | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class DeserializersByNameTagWithWhiteSpaceTest { | ||
|
||
private String path; | ||
|
||
public DeserializersByNameTagWithWhiteSpaceTest(String path) { | ||
this.path = path; | ||
|
||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: ({0})={1}") | ||
public static Iterable<Object[]> queries() { | ||
return Arrays.asList(new Object[][]{ | ||
{"src/test/resources/employees-tagwithwhitespace.xlsx"}, | ||
}); | ||
} | ||
|
||
@Test | ||
public void shouldMapExcelToJava() { | ||
PoijiOptions options = PoijiOptionsBuilder.settings().datePattern("dd/MM/yyyy","yyyy-MM-dd","yyyy/MM/dd","yyyy年MM月dd日","yyyy\\MM\\dd").trimCellValue(true).trimTagName(true).build(); | ||
try { | ||
List<EmployeeByName2> actualEmployees = Poiji.fromExcel(new FileInputStream(new File(path)), EmployeeByName2.class, options); | ||
assertThat(actualEmployees.size(),is(4)); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/test/java/com/poiji/deserialize/DeserializersSheetViaStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.poiji.deserialize; | ||
|
||
import com.poiji.bind.Poiji; | ||
import com.poiji.deserialize.model.byid.Sample; | ||
import com.poiji.option.PoijiOptions; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static com.poiji.util.Data.unmarshallingSamples; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsNull.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.fail; | ||
|
||
@RunWith(Parameterized.class) | ||
public class DeserializersSheetViaStreamTest { | ||
private String path; | ||
private boolean preferNullOverDefault; | ||
private List<Sample> expectedSamples; | ||
private Class<?> expectedException; | ||
|
||
public DeserializersSheetViaStreamTest(String path, | ||
List<Sample> expectedSamples, | ||
boolean preferNullOverDefault, | ||
Class<?> expectedException) { | ||
this.path = path; | ||
this.expectedSamples = expectedSamples; | ||
this.preferNullOverDefault = preferNullOverDefault; | ||
this.expectedException = expectedException; | ||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: ({0})={1}") | ||
public static Iterable<Object[]> queries() { | ||
return Arrays.asList(new Object[][]{ | ||
{"src/test/resources/sample.xlsx", unmarshallingSamples(), false, null}, | ||
{"src/test/resources/sample.xls", unmarshallingSamples(), true, null}, | ||
}); | ||
} | ||
|
||
@Test | ||
public void readeFromStream() { | ||
|
||
try { | ||
|
||
PoijiOptions poijiOptions = PoijiOptions.PoijiOptionsBuilder.settings().preferNullOverDefault(this.preferNullOverDefault).build(); | ||
InputStream is = new FileInputStream(new File(path)); | ||
List<Sample> samples = Poiji.fromExcel(is, Sample.class, poijiOptions); | ||
|
||
assertThat(samples, notNullValue()); | ||
assertThat(samples.size(), not(0)); | ||
assertThat(samples.size(), is(expectedSamples.size())); | ||
|
||
Sample actualSample1 = samples.get(0); | ||
Sample actualSample2 = samples.get(1); | ||
|
||
Sample expectedSample1 = expectedSamples.get(0); | ||
Sample expectedSample2 = expectedSamples.get(1); | ||
|
||
assertThat(actualSample1.toString(), is(expectedSample1.toString())); | ||
assertThat(actualSample2.toString(), is(expectedSample2.toString())); | ||
|
||
} catch (Exception e) { | ||
if (expectedException == null) { | ||
fail(e.getMessage()); | ||
} else { | ||
assertThat(e, instanceOf(expectedException)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.