⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usermanagertest.java

📁 springlive ch7
💻 JAVA
字号:
package org.appfuse.service;import junit.framework.TestCase;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.appfuse.dao.UserDAOTest;import org.appfuse.model.User;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.dao.DataAccessException;public class UserManagerTest extends TestCase {    private static Log log = LogFactory.getLog(UserManagerTest.class);    private ApplicationContext ctx;    private User user;    private UserManager mgr;    protected void setUp() throws Exception {        String[] paths = {"/WEB-INF/applicationContext*.xml"};        ctx = new ClassPathXmlApplicationContext(paths);        mgr = (UserManager) ctx.getBean("userManager");    }    protected void tearDown() throws Exception {        user = null;        mgr = null;    }    public void testAddAndRemoveUser() throws Exception {        user = new User();        user.setFirstName("Easter");        user.setLastName("Bunny");        user = mgr.saveUser(user);        assertTrue(user.getId() != null);        if (log.isDebugEnabled()) {            log.debug("removing user...");        }        String userId = user.getId().toString();        mgr.removeUser(userId);        try {            user = mgr.getUser(userId);            fail("User '" + userId + "' found in database");        } catch (DataAccessException dae) {            log.debug("Expected exception: " + dae.getMessage());            assertTrue(dae != null);        }    }    public void testWithValidationErrors() {        user = new User();        user.setFirstName("Bill");                try {            user = mgr.saveUser(user);            fail("Validation exception not thrown!");        } catch (Exception e) {            log.debug(e.getCause().getMessage());            assertNotNull(e.getCause());        }    }        public static void main(String[] args) {        junit.textui.TestRunner.run(UserDAOTest.class);    }}

⌨️ 快捷键说明

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