I am using Spring 3.1.1, DBunit 2.4.9, JUnit 4.10, hibernate 4.1.4.
I am stuck with a problem building some tests. I have null-value for a reflexive composition in one of my class:
@Entity
public class UserStep {
private long id;
private long version;
private String code;
private int stepOrder;
private boolean activate;
@OneToOne
@JoinColumn(referencedColumnName="stepOrder")
private UserStep nextStep;
//setter & getter...
}
Simplest test pointing out the problem:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/testApplicationContext.xml")
//AbstractTest contains methods which setup the db
public class CommonUserStepServiceTest extends AbstractTest {
@Test
public void goToPreviousUserStep_firstInstallation_NotFirstUserStep() {
List<UserStep> findAll = userStepDAO.findAll();
//I have 7 occurrences with correct label
//but null value for each UserStep.nextStep
}
Simplest xml file used to load occurrences :
<userStep id="7" activate="true" version="0" stepOrder="210" label="na" />
<userStep id="6" activate="true" version="0" stepOrder="60" label="end" />
<userStep id="5" activate="true" version="0" stepOrder="50" label="5" nextStep_stepOrder="60"/>
<userStep id="4" activate="true" version="0" stepOrder="40" label="4" nextStep_stepOrder="50"/>
<userStep id="3" activate="true" version="0" stepOrder="30" label="3" nextStep_stepOrder="40"/>
<userStep id="2" activate="true" version="0" stepOrder="20" label="2" nextStep_stepOrder="30"/>
<userStep id="1" activate="true" version="0" stepOrder="10" label="begin" nextStep_stepOrder="20"/>
Loading some occurrences into my test works, there is no error during the process. When I try to access to the nextStep attribute, I got null value and I can't figure out why. Someone can help? I have other tests that use UserStep table among others and they work (but I don't try to access to the nextStep attribute in them)
Problem came from the organization of my occurrences in my xml file. The parser was missing nextStep_stepOrder attribute because it use the first occurrence it finds to determine all columns.
Solution was adding setColumnSensing(true)
to the FlatXmlDataSetBuilder in order to dynamically add all columns.