📄 testtimesheetservice.java
字号:
package net.java.workeffort.service;import java.math.BigDecimal;import java.util.ArrayList;import java.util.List;import junit.framework.Test;import junit.framework.TestSuite;import net.java.workeffort.data.DataFileUtil;import net.java.workeffort.params.TimesheetParams;import net.java.workeffort.service.domain.PageResult;import net.java.workeffort.service.domain.TimeEntry;import net.java.workeffort.service.domain.Timesheet;import net.java.workeffort.service.domain.TimesheetQuery;/** * Test for Timesheet service. * @author Antony Joseph */public class TestTimesheetService extends BaseServiceTestCase { private ITimesheetService service; private TimesheetParams params; public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(TestTimesheetService.class); List list = new ArrayList(); list.add(DataFileUtil.TIMESHEET); return new ServiceTestSetup(suite, list); } protected void setUp() throws Exception { super.setUp(); service = (ITimesheetService) ServiceTestSetup.getApplicationContext() .getBean("timesheetService"); params = new TimesheetParams(); } public void testGetTimesheetUser() throws Exception { TimesheetQuery query = params.testGetTimesheetUser(); //set the securityProfile party code. The partyCd of the user invoking // this method is used as a query parameter in sql mockSecurityProfile.setPartyCd("TMSPAR3001"); Timesheet result = service.getTimesheetUser(query); assertNotNull("Should not return null object", result); } public void testGetTimesheetSupervisor() throws Exception { TimesheetQuery query = params.testGetTimesheetSupervisor(); //set the securityProfile party code. The partyCd of the user invoking // this method is used as a query parameter in sql mockSecurityProfile.setPartyCd("TMSPARSUP3002"); Timesheet result = service.getTimesheetSupervisor(query); assertNotNull("Should not return null object", result); } public void testGetTimesheetManagement() throws Exception { TimesheetQuery query = params.testGetTimesheetManagement(); Timesheet result = service.getTimesheetManagement(query); assertNotNull("Should not return null object", result); } public void testGetTimesheetUserPageResult() throws Exception { TimesheetQuery query = params.testGetPageResultTimesheetUser(); mockSecurityProfile.setPartyCd("TMSPAR3001"); PageResult result = service.getPageResultTimesheetUser(query); if (result.getRows().size() == 0) { fail("property 'rows' should be an list with size > 0"); } } public void testGetTimesheetSupervisorPageResult() throws Exception { TimesheetQuery query = params.testGetPageResultTimesheetSupervisor(); mockSecurityProfile.setPartyCd("TMSPARSUP3002"); PageResult result = service.getPageResultTimesheetSupervisor(query); if (result.getRows().size() == 0) { fail("property 'rows' should be an list with size > 0"); } } public void testGetTimesheetManagementPageResult() throws Exception { TimesheetQuery query = params.testGetPageResultTimesheetManagement(); PageResult result = service.getPageResultTimesheetManagement(query); if (result.getRows().size() == 0) { fail("property 'rows' should be an list with size > 0"); } } public void testInsertTimesheetUser() throws Exception { Timesheet input = params.testInsertTimesheetUser(); mockSecurityProfile.setPartyCd("TMSPAR3006"); service.insertTimesheetUser(input); assertNotNull("timesheetId should have a value", input.getTimesheetId()); TimesheetQuery query = new TimesheetQuery(); query.setTimesheetId(input.getTimesheetId()); Timesheet result = service.getTimesheetUser(query); if (result.getTimeEntries().size() == 0) { fail("property 'timeEntries' should be an array with size > 0"); } } public void testUpdateTimesheetUserUpdateEntry() throws Exception { Timesheet input = params.testUpdateTimesheetUserUpdateEntry(); mockSecurityProfile.setPartyCd("TMSPAR3007"); BigDecimal day0 = ((TimeEntry) input.getTimeEntries().get(0)).getDay0(); service.updateTimesheetUser(input); TimesheetQuery query = new TimesheetQuery(); query.setTimesheetId(input.getTimesheetId()); Timesheet result = service.getTimesheetUser(query); List list = result.getTimeEntries(); boolean flag = false; for (int i = 0; i < list.size(); i++) { BigDecimal currentDay0 = (BigDecimal) ((TimeEntry) list.get(i)) .getDay0(); //System.out.println("currentDay0=" + currentDay0); if (day0.doubleValue() == currentDay0.doubleValue()) flag = true; } if (!flag) { fail("day0 not updated to " + day0); } } public void testUpdateTimesheetUserDeleteEntry() throws Exception { Timesheet input = params.testUpdateTimesheetUserDeleteEntry(); mockSecurityProfile.setPartyCd("TMSPAR3008"); service.updateTimesheetUser(input); TimesheetQuery query = new TimesheetQuery(); query.setTimesheetId(input.getTimesheetId()); Timesheet result = service.getTimesheetUser(query); if (result.getTimeEntries().size() > 0) { fail("property 'timeEntries' should be an list with size 0"); } } public void testUpdateTimesheetSupervisor() throws Exception { Timesheet input = params.testUpdateTimesheetSupervisor(); mockSecurityProfile.setPartyCd("TMSPARAPPR3009"); service.updateTimesheetSupervisor(input); assertEquals("version should be incremented to 2.", new Integer(2), input.getVersion()); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -