testproductservice.java

来自「一个很好的开源项目管理系统源代码」· Java 代码 · 共 91 行

JAVA
91
字号
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.ProductParams;import net.java.workeffort.service.domain.PageResult;import net.java.workeffort.service.domain.Product;import net.java.workeffort.service.domain.ProductQuery;import net.java.workeffort.service.support.OptimisticLockingException;/** * Test for product service. * @author Antony Joseph */public class TestProductService extends BaseServiceTestCase {    private IProductService service;    private ProductParams params;    public static Test suite() {        TestSuite suite = new TestSuite();        suite.addTestSuite(TestProductService.class);        List list = new ArrayList();        list.add(DataFileUtil.PRODUCT);        return new ServiceTestSetup(suite, list);    }    protected void setUp() throws Exception {        super.setUp();        service = (IProductService) ServiceTestSetup.getApplicationContext()                .getBean("productService");        params = new ProductParams();    }    public void testGetProductPageResult() throws Exception {        ProductQuery query = params.testGetPageResultProduct();        PageResult result = service.getPageResultProduct(query);        assertNotNull("Should not return null object", result.getRows());        assertEquals("Should return 1 row", 1, result.getRows().size());    }    public void testGetProduct() throws Exception {        String pk = params.testGetProduct();        Product result = service.getProduct(pk);        assertNotNull("Should not return null object", result);    }    public void testInsertProduct() throws Exception {        Product input = params.testInsertProduct();       service.insertProduct(input);        assertEquals("version should be set to 1.", new Integer(1), input                .getVersion());    }    public void testUpdateProduct() throws Exception {        Product input = params.testUpdateProduct();        service.updateProduct(input);        assertEquals("version should be incremented to 2.", new Integer(2),                input.getVersion());    }    public void testDeleteProduct() throws Exception {        Product input = params.testDeleteProduct();        service.deleteProduct(input);        Product result = service.getProduct(input.getProductCd());        assertNull("Should return null object", result);    }    public void testUpdateProductOptLck() throws Exception {        Product input = params.testUpdateProductOptLck();        try {             service.updateProduct(input);            fail("An OptimisticLockingException should be raised");        }        catch (OptimisticLockingException expected) {            assertTrue(true);        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?