@${testType:newType(org.junit.Test)}
public void testFindById() throws Exception {
${DomainObject:localVar(org.fornax.cartridges.sculptor.framework.domain.AbstractDomainObject)} obj = ${service:field}.findById(getServiceContext(), 1L);
assertNotNull(obj);
}
@${testType:newType(org.junit.Test)}(expected=${DomainObject}NotFoundException.class)
public void testFindByIdWithNotFoundException() throws Exception {
${service}.findById(getServiceContext(), -1L);
}
@${testType:newType(org.junit.Test)}
public void testFindAll() throws Exception {
${listType:newType(java.util.List)}<${DomainObject}> found = ${service}.findAll(getServiceContext());
assertEquals(1, found.size());
}
@${testType:newType(org.junit.Test)}
public void testSave() throws Exception {
int countBefore = countRowsInTable(${DomainObject}.class);
${DomainObject} obj = new ${DomainObject}();
// TODO complete...
// obj.set${cursor}
${service}.save(getServiceContext(), obj);
assertEquals(countBefore + 1, countRowsInTable(${DomainObject}.class));
}
@${testType:newType(org.junit.Test)}
public void testDelete() throws Exception {
int countBefore = countRowsInTable(${DomainObject}.class);
${DomainObject} obj = ${service}.findById(getServiceContext(), 1L);
${service}.delete(getServiceContext(), obj);
assertEquals(countBefore - 1, countRowsInTable(${DomainObject}.class));
}
Add it in Eclipse > Preferences > Java > Editor > Templates
Name: testScaffold
Context: Java type members
Description: JUnit test methods for Sculptor CRUD operations
No comments:
Post a Comment