-
Notifications
You must be signed in to change notification settings - Fork 234
add xlsDataSetLoader #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
add xlsDataSetLoader #148
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -7,3 +7,9 @@ bin | |||
| .DS_Store | ||||
| .idea | ||||
| *.iml | ||||
| *.ipr | ||||
| *.iws | ||||
| */*.iml | ||||
| */*.iws | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already covered by *.iws
Suggested change
|
||||
| */*.ipr | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already covered by *.ipr
Suggested change
|
||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |||||
| import com.github.springtestdbunit.sample.entity.Person; | ||||||
|
|
||||||
| @RunWith(SpringJUnit4ClassRunner.class) | ||||||
| @ContextConfiguration | ||||||
| @ContextConfiguration({"classpath:com/github/springtestdbunit/sample/service/applicationContext.xml"}) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the existing configuration need to be changed?
Suggested change
|
||||||
| @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DbUnitTestExecutionListener.class }) | ||||||
| public class PersonServiceTest { | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||
| package com.github.springtestdbunit.sample.service; | ||||||
|
|
||||||
| import com.github.springtestdbunit.DbUnitTestExecutionListener; | ||||||
| import com.github.springtestdbunit.annotation.DatabaseSetup; | ||||||
| import com.github.springtestdbunit.annotation.DbUnitConfiguration; | ||||||
| import com.github.springtestdbunit.dataset.XlsDataSetLoader; | ||||||
| import com.github.springtestdbunit.sample.entity.Person; | ||||||
| import org.junit.Test; | ||||||
| import org.junit.runner.RunWith; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.test.context.ContextConfiguration; | ||||||
| import org.springframework.test.context.TestExecutionListeners; | ||||||
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||||||
| import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; | ||||||
|
|
||||||
| import java.util.List; | ||||||
|
|
||||||
| import static org.junit.Assert.assertEquals; | ||||||
|
|
||||||
| @RunWith(SpringJUnit4ClassRunner.class) | ||||||
| @ContextConfiguration({"classpath:com/github/springtestdbunit/sample/service/applicationContext.xml"}) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| @DbUnitConfiguration(dataSetLoader= XlsDataSetLoader.class) | ||||||
| @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DbUnitTestExecutionListener.class }) | ||||||
| public class XlsDataLoaderTest { | ||||||
|
|
||||||
| @Autowired | ||||||
| private PersonService personService; | ||||||
|
|
||||||
| @Test | ||||||
| @DatabaseSetup("sampleData.xls") | ||||||
| public void testFind() throws Exception { | ||||||
| List<Person> personList = this.personService.find("wang"); | ||||||
| assertEquals(1, personList.size()); | ||||||
| assertEquals("wu", personList.get(0).getLastName()); | ||||||
| } | ||||||
|
|
||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also test testRemove() to be consistent with the above test class. |
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||||||
| package com.github.springtestdbunit.dataset; | ||||||||||
|
|
||||||||||
| import org.dbunit.dataset.IDataSet; | ||||||||||
| import org.dbunit.dataset.excel.XlsDataSet; | ||||||||||
| import org.springframework.core.io.Resource; | ||||||||||
|
|
||||||||||
| import java.io.InputStream; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Created by yangjianzhou on 17-11-18. | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| */ | ||||||||||
| public class XlsDataSetLoader extends AbstractDataSetLoader { | ||||||||||
|
|
||||||||||
| @Override | ||||||||||
| protected IDataSet createDataSet(Resource resource) throws Exception { | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| InputStream inputStream = resource.getInputStream(); | ||||||||||
| try { | ||||||||||
| return new XlsDataSet(inputStream); | ||||||||||
| } finally { | ||||||||||
| inputStream.close(); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already covered by *.iml