Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ bin
.DS_Store
.idea
*.iml
*.ipr
*.iws
*/*.iml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already covered by *.iml

Suggested change
*/*.iml

*/*.iws

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already covered by *.iws

Suggested change
*/*.iws

*/*.ipr

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already covered by *.ipr

Suggested change
*/*.ipr


Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.github.springtestdbunit.sample.entity.Person;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@ContextConfiguration({"classpath:com/github/springtestdbunit/sample/service/applicationContext.xml"})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the existing configuration need to be changed?

Suggested change
@ContextConfiguration({"classpath:com/github/springtestdbunit/sample/service/applicationContext.xml"})
@ContextConfiguration

@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DbUnitTestExecutionListener.class })
public class PersonServiceTest {

Expand Down
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"})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@ContextConfiguration({"classpath:com/github/springtestdbunit/sample/service/applicationContext.xml"})
@ContextConfiguration

@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());
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also test testRemove() to be consistent with the above test class.

}
Binary file not shown.
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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Created by yangjianzhou on 17-11-18.
* {@link com.github.springtestdbunit.dataset.DataSetLoader DataSetLoader} for Excel (.xls) files.
*
* Created by yangjianzhou on 17-11-18.

*/
public class XlsDataSetLoader extends AbstractDataSetLoader {

@Override
protected IDataSet createDataSet(Resource resource) throws Exception {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected IDataSet createDataSet(Resource resource) throws Exception {
protected IDataSet createDataSet(final Resource resource) throws Exception {

InputStream inputStream = resource.getInputStream();
try {
return new XlsDataSet(inputStream);
} finally {
inputStream.close();
}
}
}