📄 testworkservice.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.WorkParams;import net.java.workeffort.service.domain.PageResult;import net.java.workeffort.service.domain.Work;import net.java.workeffort.service.domain.WorkQuery;import net.java.workeffort.service.support.OptimisticLockingException;import net.java.workeffort.service.support.UniqueConstraintException;/** * Test for Work service. * @author Antony Joseph */public class TestWorkService extends BaseServiceTestCase { private IWorkService service; private WorkParams params; public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(TestWorkService.class); List list = new ArrayList(); list.add(DataFileUtil.WORK); return new ServiceTestSetup(suite, list); } protected void setUp() throws Exception { super.setUp(); service = (IWorkService) ServiceTestSetup.getApplicationContext() .getBean("workService"); params = new WorkParams(); } public void testGetWorkPageResult() throws Exception { WorkQuery query = params.testGetPageResultWork(); PageResult result = service.getPageResultWork(query); assertNotNull("Should not return null object", result.getRows()); assertEquals("Should return 1 row", 1, ((List) result.getRows()).size()); } public void testGetWork() throws Exception { Long pk = params.testGetWork(); Work result = service.getWork(pk); assertNotNull("Should not return null object", result); } public void testInsertWork() throws Exception { Work input = params.testInsertWork(); service.insertWork(input); assertEquals("version should be set to 1.", new Integer(1), input .getVersion()); } public void testUpdateWork() throws Exception { Work input = params.testUpdateWork(); service.updateWork(input); assertEquals("version should be incremented to 2.", new Integer(2), input.getVersion()); } public void testDeleteWork() throws Exception { Work input = params.testDeleteWork(); service.deleteWork(input); Work result = service.getWork(input.getWorkId()); assertNull("Should return null object", result); } public void testUpdateWorkOptLck() throws Exception { Work input = params.testUpdateWorkOptLck(); try { service.updateWork(input); fail("An OptimisticLockingException should be raised"); } catch (OptimisticLockingException expected) { assertTrue(true); } } public void testGetWorkWithAssociation() throws Exception { Long pk = params.testGetWorkWithAssociation(); Work result = service.getWorkWithAssociation(pk); assertNotNull("Should not return null object", result); if (result.getWorkAssociation().size() == 0) { fail("property 'associations' should be an list with size > 0"); } } public void testSaveWorkWithAssociationInsert() throws Exception { Work input = params.testSaveWorkWithAssociationInsert(); service.saveWorkWithAssociation(input); Work result = service.getWorkWithAssociation(input.getWorkId()); assertNotNull("Should not return null object", result); if (result.getWorkAssociation().size() == 0) { fail("property 'associations' should be an list with size > 0"); } } public void testSaveWorkWithAssociationDelete() throws Exception { Work input = params.testSaveWorkWithAssociationDelete(); service.saveWorkWithAssociation(input); Work result = service.getWorkWithAssociation(input.getWorkId()); if (result.getWorkAssociation().size() > 0) { fail("property 'associations' should be an list with size 0"); } } public void testSaveWorkWithAssociationDupRec() throws Exception { Work input = params.testSaveWorkWithAssociationDupRec(); try { service.saveWorkWithAssociation(input); fail("A UniqueConstraintException should be raised"); } catch (UniqueConstraintException expected) { assertTrue(true); } } public void testGetWorkWithDeliverableProduced() throws Exception { Long pk = params.testGetWorkWithDeliverableProduced(); Work result = service.getWorkWithDeliverableProduced(pk); assertNotNull("Should not return null object", result); if (result.getWorkDeliverableProduced().size() == 0) { fail("property 'deliverableProduced' should be an list with size > 0"); } } public void testSaveWorkWithDeliverableProducedInsert() throws Exception { Work input = params.testSaveWorkWithDeliverableProducedInsert(); service.saveWorkWithDeliverableProduced(input); Work result = service.getWorkWithDeliverableProduced(input.getWorkId()); assertNotNull("Should not return null object", result); if (result.getWorkDeliverableProduced().size() == 0) { fail("property 'workDeliverableProduced' should be an list with size > 0"); } } public void testSaveWorkWithDeliverableProducedDelete() throws Exception { Work input = params.testSaveWorkWithDeliverableProducedDelete(); service.saveWorkWithDeliverableProduced(input); Work result = service.getWorkWithDeliverableProduced(input.getWorkId()); if (result.getWorkDeliverableProduced().size() > 0) { fail("property 'deliverableProduced' should be an list with size 0"); } } // ======================= FixedAssetAssignment========================== public void testGetWorkWithFixedAssetAssignment() throws Exception { Long pk = params.testGetWorkWithFixedAssetAssignment(); Work result = service.getWorkWithFixedAssetAssignment(pk); assertNotNull("Should not return null object", result); if (result.getWorkFixedAssetAssignment().size() == 0) { fail("property 'fixedAssetAssignments' should be an list with size > 0"); } } public void testSaveWorkWithFixedAssetAssignmentInsert() throws Exception { Work input = params.testSaveWorkWithFixedAssetAssignmentInsert(); service.saveWorkWithFixedAssetAssignment(input); Work result = service.getWorkWithFixedAssetAssignment(input.getWorkId()); assertNotNull("Should not return null object", result); if (result.getWorkFixedAssetAssignment().size() == 0) { fail("property 'fixedAssetAssignments' should be an list with size > 0"); } } public void testSaveWorkFixedAssetAssignmentDelete() throws Exception { Work input = params.testSaveWorkWithFixedAssetAssignmentDelete(); service.saveWorkWithFixedAssetAssignment(input); Work result = service.getWorkWithFixedAssetAssignment(input.getWorkId()); if (result.getWorkFixedAssetAssignment().size() > 0) { fail("property 'fixedAssetAssignments' should be an list with size 0"); } } //======================= inventory Assignment ========================= public void testGetWorkWithInventoryAssignment() throws Exception { Long pk= params.testGetWorkWithInventoryAssignment(); Work result = service.getWorkWithInventoryAssignment(pk); assertNotNull("Should not return null object", result); if (result.getWorkInventoryAssignment().size() == 0) { fail("property 'inventoryAssignments' should be an list with size > 0"); } } public void testSaveWorkWithInventoryAssignmentInsert() throws Exception { Work input = params.testSaveWorkWithInventoryAssignmentInsert(); service.saveWorkWithInventoryAssignment(input); Work result = service.getWorkWithInventoryAssignment(input.getWorkId()); assertNotNull("Should not return null object", result); if (result.getWorkInventoryAssignment().size() == 0) { fail("property 'inventoryAssignments' should be an list with size > 0"); } } public void testSaveWorkWithInventoryAssignmentDelete() throws Exception { Work input = params.testSaveWorkWithInventoryAssignmentDelete(); service.saveWorkWithInventoryAssignment(input); Work result = service.getWorkWithInventoryAssignment(input.getWorkId()); if (result.getWorkInventoryAssignment().size() > 0) { fail("property 'inventoryAssignments' should be an list with size 0"); } } // ======================= partyAssignment ========================= public void testGetWorkWithPartyAssignment() throws Exception { Long pk= params.testGetWorkWithPartyAssignment(); Work result = service.getWorkWithPartyAssignment(pk); assertNotNull("Should not return null object", result); if (result.getWorkPartyAssignment().size() == 0) { fail("property 'partyAssignments' should be an list with size > 0"); } } public void testSaveWorkWithPartyAssignmentInsert() throws Exception { Work input = params.testSaveWorkWithPartyAssignmentInsert(); service.saveWorkWithPartyAssignment(input); Work result = service.getWorkWithPartyAssignment(input.getWorkId()); assertNotNull("Should not return null object", result); if (result.getWorkPartyAssignment().size() == 0) { fail("property 'partyAssignments' should be an list with size > 0"); } } public void testSaveWorkWithPartyAssignmentDelete() throws Exception { Work input = params.testSaveWorkWithPartyAssignmentDelete(); service.saveWorkWithPartyAssignment(input); Work result = service.getWorkWithPartyAssignment(input.getWorkId()); if (result.getWorkPartyAssignment().size() > 0) { fail("property 'partyAssignments' should be an list with size 0"); } } // ======================= product produced ========================= public void testGetWorkWithProductProduced() throws Exception { Long pk = params.testGetWorkWithProductProduced(); Work result = service.getWorkWithProductProduced(pk); assertNotNull("Should not return null object", result); if (result.getWorkProductProduced().size() == 0) { fail("property 'productProduced' should be an list with size > 0"); } } public void testSaveWorkWithProductProducedInsert() throws Exception { Work input = params.testSaveWorkWithProductProducedInsert(); service.saveWorkWithProductProduced(input); Work result = service.getWorkWithProductProduced(input.getWorkId()); assertNotNull("Should not return null object", result); if (result.getWorkProductProduced().size() == 0) { fail("property 'productProduced' should be an list with size > 0"); } } public void testSaveWorkWithProductProducedDelete() throws Exception { Work input = params.testSaveWorkWithProductProducedDelete(); service.saveWorkWithProductProduced(input); Work result = service.getWorkWithProductProduced(input.getWorkId()); if (result.getWorkProductProduced().size() > 0) { fail("property 'productProduced' should be an list with size 0"); } } // ======================= workRequirement ========================= public void testGetWorkWithRequirement() throws Exception { Long pk= params.testGetWorkWithRequirement(); Work result = service.getWorkWithRequirement(pk); assertNotNull("Should not return null object", result); if (result.getWorkRequirement().size() == 0) { fail("property 'requirements' should be an list with size > 0"); } } public void testSaveWorkWithRequirementInsert() throws Exception { Work input = params.testSaveWorkWithRequirementInsert(); service.saveWorkWithRequirement(input); Work result = service.getWorkWithRequirement(input.getWorkId()); assertNotNull("Should not return null object", result); if (result.getWorkRequirement().size() == 0) { fail("property 'requirements' should be an list with size > 0"); } } public void testSaveWorkWithRequirementDelete() throws Exception { Work input = params.testSaveWorkWithRequirementDelete(); service.saveWorkWithRequirement(input); Work result = service.getWorkWithRequirement(input.getWorkId()); if (result.getWorkRequirement().size() > 0) { fail("property 'requirements' should be an list with size 0"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -