📄 testpartyservice.java
字号:
package net.java.workeffort.service;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.PartyParams;import net.java.workeffort.service.domain.PageResult;import net.java.workeffort.service.domain.Party;import net.java.workeffort.service.domain.PartyQuery;import net.java.workeffort.service.domain.PartyRate;import net.java.workeffort.service.domain.PartySkill;import net.java.workeffort.service.support.OptimisticLockingException;import net.java.workeffort.service.support.UniqueConstraintException;/** * Test for party service. * @author Antony Joseph */public class TestPartyService extends BaseServiceTestCase { private IPartyService service; private PartyParams params; public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(TestPartyService.class); List list = new ArrayList(); list.add(DataFileUtil.PARTY); return new ServiceTestSetup(suite, list); } protected void setUp() throws Exception { super.setUp(); service = (IPartyService) ServiceTestSetup.getApplicationContext() .getBean("partyService"); params = new PartyParams(); } public void testGetPartyPageResult() throws Exception { PartyQuery query = params.testGetPageResultParty(); PageResult result = service.getPageResultParty(query); assertNotNull("Should not return null object", result.getRows()); assertEquals("Should return 1 row", result.getRows().size(), 1); } public void testGetParty() throws Exception { String pk = params.testGetParty(); Party result = service.getParty(pk); assertNotNull("Should not return null object", result); } public void testInsertParty() throws Exception { Party input = params.testInsertParty(); service.insertParty(input); assertEquals("version should be set to 1.", new Integer(1), input .getVersion()); } public void testUpdateParty() throws Exception { Party input = params.testUpdateParty(); service.updateParty(input); assertEquals("version should be incremented to 2.", new Integer(2), input.getVersion()); } public void testDeleteParty() throws Exception { Party input = params.testDeleteParty(); service.deleteParty(input); Party result = service.getParty(input.getPartyCd()); assertNull("Should return null object", result); } public void testUpdatePartyOptLck() throws Exception { Party input = params.testUpdatePartyOptLck(); try { service.updateParty(input); fail("An OptimisticLockingException should be raised"); } catch (OptimisticLockingException expected) { assertTrue(true); } } // ========================= Party Rate =========================== public void testGetPartyRate() throws Exception { String pk = params.testGetPartyWithRate(); Party result = service.getPartyWithRate(pk); assertNotNull("Should not return null object", result); if (result.getPartyRate().size() == 0) { fail("property 'rates' should be an list with size > 0"); } } public void testSavePartyRateInsert() throws Exception { Party input = params.testSavePartyWithRateInsert(); service.savePartyWithRate(input); Party result = service.getPartyWithRate(input.getPartyCd()); if (result.getPartyRate().size() == 0) { fail("property 'rates' should be an array with size > 0"); } } public void testSavePartyRateUpdate() throws Exception { Party input = params.testSavePartyWithRateUpdate(); service.savePartyWithRate(input); PartyRate row = (PartyRate) input.getPartyRate().get(0); assertEquals("version should be incremented to 2.", new Integer(2), row .getVersion()); assertNotNull("thruDt cannot be null", row.getThruDt()); } public void testSavePartyRateDelete() throws Exception { Party input = params.testSavePartyWithRateDelete(); service.savePartyWithRate(input); Party result = service.getPartyWithRate(input.getPartyCd()); if (result.getPartyRate().size() > 0) { fail("property 'rates' should be an list with size 0"); } } public void testSavePartyRateDupRec() throws Exception { Party input = params.testSavePartyWithRateDupRec(); try { service.savePartyWithRate(input); fail("A UniqueConstraintException should be raised"); } catch (UniqueConstraintException expected) { assertTrue(true); } } //======================== party Skill ============================ public void testGetPartySkill() throws Exception { String pk = params.testGetPartyWithSkill(); Party result = service.getPartyWithSkill(pk); assertNotNull("Should not return null object", result); if (result.getPartySkill().size() == 0) { fail("property 'skills' should be an list with size > 0"); } } public void testSavePartySkillInsert() throws Exception { Party input = params.testSavePartyWithSkillInsert(); service.savePartyWithSkill(input); Party result = service.getPartyWithSkill(input.getPartyCd()); if (result.getPartySkill().size() == 0) { fail("property 'skills' should be an array with size > 0"); } } public void testSavePartySkillUpdate() throws Exception { Party input = params.testSavePartyWithSkillUpdate(); service.savePartyWithSkill(input); Party result = service.getPartyWithSkill(input.getPartyCd()); assertNotNull("Should not return null object", result); PartySkill row = (PartySkill) result.getPartySkill().get(0); assertEquals("version should be incremented to 2.", new Integer(2), row .getVersion()); } public void testSavePartySkillDelete() throws Exception { Party input = params.testSavePartyWithSkillDelete(); service.savePartyWithSkill(input); Party result = service.getPartyWithSkill(input.getPartyCd()); if (result.getPartySkill().size() > 0) { fail("property 'skills' should be an list with size 0"); } } public void testSavePartySkillDupRec() throws Exception { Party input = params.testSavePartyWithSkillDupRec(); try { service.savePartyWithSkill(input); fail("A UniqueConstraintException should be raised"); } catch (UniqueConstraintException expected) { assertTrue(true); } } //============Party role ================== public void testGetPartyWithRole() throws Exception { String pk = params.testGetPartyWithRole(); Party result = service.getPartyWithRole(pk); assertNotNull("Should not return null object", result); if (result.getPartyRole().size() == 0) { fail("property 'roles' should be an list with size > 0"); } } public void testGetPartyRolePermissionHierarchyList() throws Exception { String pk = params.testGetListPartyRolePermissionHierarchy(); List result = service.getListPartyRolePermissionHierarchy(pk); assertNotNull("Should not return null object", result); if (result.size() != 3) { fail("should be an list with size 3"); } } public void testSavePartyWithRoleInsert() throws Exception { Party input = params.testSavePartyWithRoleInsert(); service.savePartyWithRole(input); Party result = service.getPartyWithRole(input.getPartyCd()); if (result.getPartyRole().size() == 0) { fail("property 'roles' should be an array with size > 0"); } } public void testSavePartyWithRoleDelete() throws Exception { Party input = params.testSavePartyWithRoleDelete(); service.savePartyWithRole(input); Party result = service.getPartyWithRole(input.getPartyCd()); if (result.getPartyRole().size() > 0) { fail("property 'roles' should be an list with size 0"); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -