/**
* Created by Administrator on 2017-04-06.
*/ @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@WebAppConfiguration public class UserControllerTest {
private MockMvc mvc;
@Autowired
protected WebApplicationContext wac; @BeforeClass
public static void setBeforeClass(){
System.out.println("======BeforeClass");
}
@Before
public void setBefore(){
System.out.println("======Before");
mvc= MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void login() throws Exception {
String responseString = mvc.perform(
post("/api/questionbank/login")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("LoginId","admin")
.param("Password","123456"))
.andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print())
.andExpect(jsonPath("loginId").exists())
.andExpect(jsonPath("loginId").value("admin"))
.andReturn().getResponse().getContentAsString(); System.out.println("===返回的json= "+responseString);
} //登录失败:用户名和密码均不存在
@Test
public void loginusrpwdfail() throws Exception {
String responseString = mvc.perform(
post("/api/questionbank/login")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("LoginId","abc")
.param("Password","12345678"))
.andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print())
.andExpect(jsonPath("errcode").exists())
.andExpect(jsonPath("errcode").value("0"))
.andExpect(jsonPath("errmsg").exists())
.andExpect(jsonPath("errmsg").value("用户名或密码错误"))
.andReturn().getResponse().getContentAsString(); System.out.println("===返回的json= "+responseString);
}
//登录失败:用户名正确,密码不正确
@Test
public void loginpwdfail() throws Exception {
String responseString = mvc.perform(
post("/api/questionbank/login")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("LoginId","admin")
.param("Password","12345678"))
.andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print())
.andExpect(jsonPath("errcode").exists())
.andExpect(jsonPath("errcode").value("0"))
.andExpect(jsonPath("errmsg").exists())
.andExpect(jsonPath("errmsg").value("用户名或密码错误"))
.andReturn().getResponse().getContentAsString(); System.out.println("===返回的json= "+responseString); } //登录失败:用户名不正确,密码正确
@Test
public void loginusrfail() throws Exception {
String responseString = mvc.perform(
post("/api/questionbank/login")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("LoginId","admin1")
.param("Password","123456"))
.andExpect(status().isOk())
.andDo(MockMvcResultHandlers.print())
.andExpect(jsonPath("errcode").exists())
.andExpect(jsonPath("errcode").value("0"))
.andExpect(jsonPath("errmsg").exists())
.andExpect(jsonPath("errmsg").value("用户名或密码错误"))
.andReturn().getResponse().getContentAsString(); System.out.println("===返回的json= "+responseString); }
@After
public void setAfter(){
System.out.println("======After");
} @AfterClass
public static void setAfterClass(){
System.out.println("======AfterClass");
} }

TDD - 登录成功和失败的更多相关文章

  1. Python模拟登录成功与失败处理方式(不涉及前端)

    任务说明: (1) 用户输入用户名,如不存在此用户不能登录: (2) 用户在输入密码时,如果连续输入三次错误,则该用户被锁定一段时间; (3) 用户被锁定一段时间后,可再次进行尝试登录: 程序使用库: ...

  2. Nodejs:npm run build之后,dist\index.html页面在火狐中可以正常显示登录页面并登录成功,在Chrome中可以正常显示登录页面,登录失败

    问题描述:Nodejs:npm run build之后,dist\index.html页面在火狐中可以正常显示登录页面并登录成功,在Chrome中可以正常显示登录页面,登录失败 解决方法:将打包后的d ...

  3. SpringSecurity系列之自定义登录验证成功与失败的结果处理

    一.需要自定义登录结果的场景 在我之前的文章中,做过登录验证流程的源码解析.其中比较重要的就是 当我们登录成功的时候,是由AuthenticationSuccessHandler进行登录结果处理,默认 ...

  4. 在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. 结合数据库登录注册模块,登录成功之后跳到WebView

    最近刚刚做了一个模块,在本地建立一个数据库,存储注册的账号,登录的时候取出,正确则登录,登录之后跳到一个webView网页. 直接上代码吧. LoginActivity.java package co ...

  6. 使用session和cookie实现用户登录:一个登录页面,一个servlet,一个登录成功页面

    文件目录 1.登录页面 <%@ page language="java" contentType="text/html; charset=utf-8" p ...

  7. shiro登录成功之后跳转原路径

    通过 WebUtils.getSavedRequest(request) 来获取shiro保存在session登录之前的url 1:java Controller代码 @PostMapping(&qu ...

  8. taotao用户登录(及登录成功后的回调url处理)

    后台Controller: package com.taotao.sso.controller; import org.springframework.stereotype.Controller; i ...

  9. 苹果手机Safari无痕浏览模式下系统登录成功但是页面不跳转

    昨天下午,测试提了一个bug,问题是:在苹果手机Safari无痕浏览模式下系统登录成功但是页面不跳转. 思前想后找了半天没思路,后来经过同事的点拨,说可能是禁用了cookie之类的,反正我也没思路就顺 ...

随机推荐

  1. 与前端对接 jsonp

    主要是回调的写法,前端人员接受的数据格式      参数 (jsonString);

  2. TCP连接异常断开检测(转)

    TCP是一种面向连接的协议,连接的建立和断开需要通过收发相应的分节来实现.某些时候,由于网络的故障或是一方主机的突然崩溃而另一方无法检测到,以致始终保持着不存在的连接.下面介绍一种方法来检测这种异常断 ...

  3. shell流程控制与循环结构

    shell脚本中的流程控制有if/else语句.case语句,循环结果包括for循环.while循环.until循环等内容. if语句 (1)最简单的if语句.使用格式有2种方式,分别如下 使用格式1 ...

  4. [Shell]一张图知道Shell(图)

  5. JSP报错Syntax error, insert ";" to complete Statement

    org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in ...

  6. Linux下MySQL5.7.18二进制包安装(手动添加配置文件my_default.cnf)

    本文出处:http://www.cnblogs.com/wy123/p/6815049.html 最新在学习MySQL,纯新手,对Linux了解的也不多,因为是下载的最新版的MySQL(MySQL5. ...

  7. hexo发表博文的方式

    本图片转自:简书:https://www.jianshu.com/p/a52b68794a6b 转自github:https://blog.minhow.com

  8. PowerDesigner 逆向工程

    原文地址:https://www.cnblogs.com/feilong3540717/archive/2011/11/18/2254040.html PowserDesigner 的打开路径:Fil ...

  9. 聚类分析K均值算法讲解

    聚类分析及K均值算法讲解 吴裕雄 当今信息大爆炸时代,公司企业.教育科学.医疗卫生.社会民生等领域每天都在产生大量的结构多样的数据.产生数据的方式更是多种多样,如各类的:摄像头.传感器.报表.海量网络 ...

  10. Spark之机器学习(Python版)(一)——聚类

    https://www.cnblogs.com/charlotte77/p/5437611.html