Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Re: Transactional Testing in Spring

After a cup of coffee I have figured this obvious problem out. The
flush command (duh).

Example for completeness:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="/applicationContext-test.xml")
@Transactional
public class EmployeeEntityTest extends TestCase{

	@Autowired
	protected SimpleDao dao;
	
	@Test
	public void testEmployeeCrud()
	{
		Employee hs = new Employee();
		dao.insert(hs);
		dao.getEntityManager().flush();
		assertNotNull(hs);
		
	}
}



./tch


On Tue, Oct 14, 2008 at 8:22 AM, Tim Hollosy <hollosyt@xxxxxxxxx> wrote:
> I'm having a problem doing some integration testing in spring with transactions.
>
> I've got my test case that injects a DAO. I want to verify that a
> unique constraint occurs on insert, well since eclipselink is smart
> enough to not bother sending the SQL until a commit happens my SQL is
> never executed.
>
> How are people working around this? Are you somehow loading a
> different persistence.xml that changes the caching behavior when
> testing?
>
> I would prefer to not have to do a commit and a delete to test an insert...
>
> Ideas?
>
> Thanks,
> Tim
>


Back to the top