TDD - 登录成功和失败
/**
* 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 - 登录成功和失败的更多相关文章
- Python模拟登录成功与失败处理方式(不涉及前端)
任务说明: (1) 用户输入用户名,如不存在此用户不能登录: (2) 用户在输入密码时,如果连续输入三次错误,则该用户被锁定一段时间; (3) 用户被锁定一段时间后,可再次进行尝试登录: 程序使用库: ...
- Nodejs:npm run build之后,dist\index.html页面在火狐中可以正常显示登录页面并登录成功,在Chrome中可以正常显示登录页面,登录失败
问题描述:Nodejs:npm run build之后,dist\index.html页面在火狐中可以正常显示登录页面并登录成功,在Chrome中可以正常显示登录页面,登录失败 解决方法:将打包后的d ...
- SpringSecurity系列之自定义登录验证成功与失败的结果处理
一.需要自定义登录结果的场景 在我之前的文章中,做过登录验证流程的源码解析.其中比较重要的就是 当我们登录成功的时候,是由AuthenticationSuccessHandler进行登录结果处理,默认 ...
- 在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 结合数据库登录注册模块,登录成功之后跳到WebView
最近刚刚做了一个模块,在本地建立一个数据库,存储注册的账号,登录的时候取出,正确则登录,登录之后跳到一个webView网页. 直接上代码吧. LoginActivity.java package co ...
- 使用session和cookie实现用户登录:一个登录页面,一个servlet,一个登录成功页面
文件目录 1.登录页面 <%@ page language="java" contentType="text/html; charset=utf-8" p ...
- shiro登录成功之后跳转原路径
通过 WebUtils.getSavedRequest(request) 来获取shiro保存在session登录之前的url 1:java Controller代码 @PostMapping(&qu ...
- taotao用户登录(及登录成功后的回调url处理)
后台Controller: package com.taotao.sso.controller; import org.springframework.stereotype.Controller; i ...
- 苹果手机Safari无痕浏览模式下系统登录成功但是页面不跳转
昨天下午,测试提了一个bug,问题是:在苹果手机Safari无痕浏览模式下系统登录成功但是页面不跳转. 思前想后找了半天没思路,后来经过同事的点拨,说可能是禁用了cookie之类的,反正我也没思路就顺 ...
随机推荐
- Oracle创建表及管理表
转自:https://www.linuxidc.com/Linux/2018-05/152566.htm 1. Oracle表的创建及管理 创建表包括三个要素,表名,列名,数据类型.每个表都有对应 ...
- VC开发中一些问题的解决
(1) MFC:在视频窗口上显示一个图片: 使用button显示图片的话,鼠标点击好图片(按钮)上,窗口无法响应. 应该使用一个static静态控件来显示,这样不会妨碍视频窗口对鼠标消息的响应. (2 ...
- hive理论
join操作: 这个 group by count()操作: 数据倾斜: 操作• Join on a.id=b.id• Group by• Count Distinct count(groupby)• ...
- python-玉米(小米)商城作业
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 24_ajax请求_使用axios
前置说明: 1.React本身只关注页面,并不包含发送ajax请求的代码 2.前端应用需要通过ajax请求与后台进行交互(json数据) 3.React应用中需要集成第三方ajax库(或自己进行封装) ...
- JVM 学习集合
内存回收要做的事: 确定哪些内存需要回收,确定什么时候需要执行GC,如何执行GC 以最简单的本地变量引用:Object obj = new Object()为例: Object obj表示一个本地引用 ...
- ubuntu交换Caps 和 ESC
https://askubuntu.com/questions/363346/how-to-permanently-switch-caps-lock-and-esc This will allow y ...
- 2339 3.1.1 Agri-Net 最短网络
Description 农民约翰被选为他们镇的镇长!他其中一个竞选承诺就是在镇上建立起互联网,并连接到所有的农场.当然,他需要你的帮助. 约翰已经给他的农场安排了一条高速的网络线路,他想把这条线路共享 ...
- Python基础-TypeError:takes 2 positional arguments but 3 were given
Error: 今天写一段简单类定义python代码所遇到报错问题:TypeError: drive() takes 2 positional arguments but 3 were given 代码 ...
- linux 再多的running也挡不住锁
再续<linux 3.10 一次softlock排查>,看运行态进程数量之多: crash> mach MACHINE TYPE: x86_64 MEMORY SIZE: GB CP ...