Package me.kafeitu.demo.activiti.web.user

Source Code of me.kafeitu.demo.activiti.web.user.UserControllerTest

package me.kafeitu.demo.activiti.web.user;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import me.kafeitu.demo.activiti.web.identify.UseController;
import me.kafeitu.modules.test.spring.SpringTransactionalTestCase;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.User;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.ContextConfiguration;

/**
* 测试用户控制器
*
* @author HenryYan
*/
@ContextConfiguration(locations = { "/applicationContext-test.xml" })
public class UserControllerTest extends SpringTransactionalTestCase {

  @Autowired
  private IdentityService identityService;

  /**
   * 正确的用户名、密码
   * @throws Exception
   */
  @Test
  public void testUserExistInDb() throws Exception {
    UseController c = new UseController();
    c.setIdentityService(identityService);
    MockHttpSession session = new MockHttpSession();
    String view = c.logon("kafeitu", "000000", session);
    assertEquals("redirect:/main/index", view);
    assertNotNull(session.getAttribute("user"));
    User user = (User) session.getAttribute("user");
    assertEquals("kafeitu", user.getId());
  }

  /**
   * 用户名不存在
   * @throws Exception
   */
  @Test
  public void testUserNotExistInDb() throws Exception {
    UseController c = new UseController();
    c.setIdentityService(identityService);
    MockHttpSession session = new MockHttpSession();
    String view = c.logon("nothisuser", "000000", session);
    assertEquals("redirect:/login?error=true", view);
  }

}
TOP

Related Classes of me.kafeitu.demo.activiti.web.user.UserControllerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.