[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Transactional Testing in Spring
|
The last sample was select sample. Below example actually inserts into the db
@Transactional
public void testAddControlRule() {
CodControlRulesB ctrB = new CodControlRulesB();
ctrB.setCode("code");
ctrB.setValidation("value.toUpper()==value");
Date today = new Date();
Long todayInLng = today.getTime();
Timestamp todayTS = new Timestamp(todayInLng);
ctrB.setCreatedBy(todayInLng);
ctrB.setLastUpdatedBy(todayInLng);
ctrB.setCreationDate(todayTS);
ctrB.setLastUpdatedDate(todayTS);
ctrB.setObjectVersionNumber(new Long(1));
ctrB.setLastUpdateLogin("test");
CodControlRulesTl ctrlTl = new CodControlRulesTl();
ctrlTl.setCodControlRulesB(ctrB);
ctrlTl.setDescr("test");
ctrlTl.setCreatedBy(todayInLng);
ctrlTl.setLastUpdatedBy(todayInLng);
ctrlTl.setCreationDate(todayTS);
ctrlTl.setLastUpdatedDate(todayTS);
ctrlTl.setObjectVersionNumber(new Long(1));
ctrlTl.setLastUpdateLogin("test");
List<CodControlRulesTl> list = new ArrayList<CodControlRulesTl>();
list.add(ctrlTl);
ctrB.setCodControlRulesTlList(list);
CrudService<CodControlRulesB> ctrService = service;
ctrB = ctrService.create(ctrB);
System.err.println("Control rule val " + ctrB.getId());
// Un- comment the lines if you want to commit the data into
db
//
// setComplete();
// endTransaction();
}
Gaurav Malhotra wrote:
>
> 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-tp19972379p19988592.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.