[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Transactional Testing in Spring
|
Spring provide one of most elegant way of handling transaction
(declaratively) using org.springframework.test.jpa.AbstractJpaTests;
Here is sample junit code
You can make an abstract class like
import org.springframework.test.jpa.AbstractJpaTests;
public abstract class AbstractJPAForOhiOrm extends AbstractJpaTests {
@Override
protected String[] getConfigLocations() {
String[] springConfig = {"classpath:META-INF/spring/Test-OhiORM.xml"};
return springConfig;
}
}
public class MyTestCases extends AbstractJPAForOhiOrm {
@Autowired // inject the service
CrudService service;
@Transactional
public void testOhiErros() {
CrudService<OhiErrorsB> cs = service;
OhiErrorsB err = cs.findFresh(OhiErrorsB.class, new Long(25));
System.err.println("Size " + err.getOhiErrorsTlList().size());
List<OhiErrorsTl> errList = err.getOhiErrorsTlList();
for (OhiErrorsTl ohiErrorsTl : errList) {
System.err.println(ohiErrorsTl.getMessage());
}
// setComplete(); // if you actually want to commit the data
into the database
// endTransaction();
}
}
Regards,
Gaurav Malhotra
Tim Hollosy 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
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>
--
View this message in context: http://www.nabble.com/Transactional-Testing-in-Spring-tp19972379p19988560.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.