切换到jackson #10
8
pom.xml
8
pom.xml
@@ -76,14 +76,6 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Json-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.sf.json-lib</groupId>
|
|
||||||
<artifactId>json-lib</artifactId>
|
|
||||||
<version>2.4</version>
|
|
||||||
<classifier>jdk15</classifier>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 七牛云SDK -->
|
<!-- 七牛云SDK -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.qiniu</groupId>
|
<groupId>com.qiniu</groupId>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import cn.celess.blog.entity.Response;
|
|||||||
import cn.celess.blog.service.UserService;
|
import cn.celess.blog.service.UserService;
|
||||||
import cn.celess.blog.util.JwtUtil;
|
import cn.celess.blog.util.JwtUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -84,7 +84,7 @@ public class AuthenticationFilter implements HandlerInterceptor {
|
|||||||
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
try {
|
try {
|
||||||
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
||||||
response.getWriter().println(JSONObject.fromObject(Response.response(e, null)));
|
response.getWriter().println(new ObjectMapper().writeValueAsString(Response.response(e, null)));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,15 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.ArticleModel;
|
import cn.celess.blog.entity.model.ArticleModel;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
|
||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.blog.entity.request.ArticleReq;
|
||||||
import cn.celess.blog.service.ArticleService;
|
import cn.celess.blog.service.ArticleService;
|
||||||
import cn.celess.blog.util.RedisUserUtil;
|
import cn.celess.blog.util.RedisUserUtil;
|
||||||
import cn.celess.blog.util.SitemapGenerateUtil;
|
import cn.celess.blog.util.SitemapGenerateUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -27,6 +25,8 @@ public class ArticleController {
|
|||||||
SitemapGenerateUtil sitemapGenerateUtil;
|
SitemapGenerateUtil sitemapGenerateUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
RedisUserUtil redisUserUtil;
|
RedisUserUtil redisUserUtil;
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String activeModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建一篇文章
|
* 新建一篇文章
|
||||||
@@ -37,7 +37,9 @@ public class ArticleController {
|
|||||||
@PostMapping("/admin/article/create")
|
@PostMapping("/admin/article/create")
|
||||||
public Response create(@RequestBody ArticleReq body) {
|
public Response create(@RequestBody ArticleReq body) {
|
||||||
ArticleModel articleModel = articleService.create(body);
|
ArticleModel articleModel = articleService.create(body);
|
||||||
sitemapGenerateUtil.createSitemap();
|
if ("prod".equals(activeModel)) {
|
||||||
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(articleModel);
|
return Response.success(articleModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +52,9 @@ public class ArticleController {
|
|||||||
@DeleteMapping("/admin/article/del")
|
@DeleteMapping("/admin/article/del")
|
||||||
public Response delete(@RequestParam("articleID") long articleId) {
|
public Response delete(@RequestParam("articleID") long articleId) {
|
||||||
boolean delete = articleService.delete(articleId);
|
boolean delete = articleService.delete(articleId);
|
||||||
sitemapGenerateUtil.createSitemap();
|
if ("prod".equals(activeModel)) {
|
||||||
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(delete);
|
return Response.success(delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +67,9 @@ public class ArticleController {
|
|||||||
@PutMapping("/admin/article/update")
|
@PutMapping("/admin/article/update")
|
||||||
public Response update(@RequestBody ArticleReq body) {
|
public Response update(@RequestBody ArticleReq body) {
|
||||||
ArticleModel update = articleService.update(body);
|
ArticleModel update = articleService.update(body);
|
||||||
sitemapGenerateUtil.createSitemap();
|
if ("prod".equals(activeModel)) {
|
||||||
|
sitemapGenerateUtil.createSitemap();
|
||||||
|
}
|
||||||
return Response.success(update);
|
return Response.success(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import cn.celess.blog.service.QiniuService;
|
|||||||
import cn.celess.blog.util.HttpUtil;
|
import cn.celess.blog.util.HttpUtil;
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.VeriCodeUtil;
|
import cn.celess.blog.util.VeriCodeUtil;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -138,7 +138,8 @@ public class CommonController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/imgUpload")
|
@PostMapping("/imgUpload")
|
||||||
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
|
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String uploadTimesStr = redisUtil.get(request.getRemoteAddr() + "-ImgUploadTimes");
|
String uploadTimesStr = redisUtil.get(request.getRemoteAddr() + "-ImgUploadTimes");
|
||||||
int uploadTimes = 0;
|
int uploadTimes = 0;
|
||||||
if (uploadTimesStr != null) {
|
if (uploadTimesStr != null) {
|
||||||
@@ -148,11 +149,11 @@ public class CommonController {
|
|||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||||
}
|
}
|
||||||
request.setCharacterEncoding("utf-8");
|
request.setCharacterEncoding("utf-8");
|
||||||
response.setContentType("text/html");
|
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
jsonObject.put("success", 0);
|
map.put("success", 0);
|
||||||
jsonObject.put("message", "上传失败,请选择文件");
|
map.put("message", "上传失败,请选择文件");
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
@@ -161,25 +162,28 @@ public class CommonController {
|
|||||||
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
||||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||||
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
||||||
jsonObject.put("success", 1);
|
map.put("success", 1);
|
||||||
jsonObject.put("message", "上传成功");
|
map.put("message", "上传成功");
|
||||||
jsonObject.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
map.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jsonObject.put("success", 0);
|
map.put("success", 0);
|
||||||
jsonObject.put("message", "上传失败,请上传图片文件");
|
map.put("message", "上传失败,请上传图片文件");
|
||||||
response.getWriter().println(jsonObject.toString());
|
response.getWriter().println(mapper.writeValueAsString(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/bingPic")
|
@GetMapping("/bingPic")
|
||||||
public Response bingPic() {
|
public Response bingPic() {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JSONObject imageObj;
|
JsonNode root;
|
||||||
imageObj = JSONObject.fromObject(HttpUtil.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
try {
|
||||||
JSONArray jsonArray = imageObj.getJSONArray("images");
|
root = mapper.readTree(HttpUtil.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
||||||
String imageName = jsonArray.getJSONObject(0).getString("url");
|
} catch (IOException e) {
|
||||||
return Response.success("https://cn.bing.com" + imageName);
|
return Response.failure(null);
|
||||||
|
}
|
||||||
|
JsonNode images = root.get("images").elements().next();
|
||||||
|
return Response.success("https://cn.bing.com" + images.get("url").asText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,18 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.request.LinkApplyReq;
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
|
||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.blog.service.MailService;
|
||||||
import cn.celess.blog.service.PartnerSiteService;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
import cn.celess.blog.entity.model.TagModel;
|
||||||
import cn.celess.blog.service.TagService;
|
import cn.celess.blog.service.TagService;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -44,13 +45,13 @@ public class TagController {
|
|||||||
|
|
||||||
@GetMapping("/tags/nac")
|
@GetMapping("/tags/nac")
|
||||||
public Response getTagNameAndCount() {
|
public Response getTagNameAndCount() {
|
||||||
List<JSONObject> nameAndCount = new ArrayList<>();
|
List<Map<String, Object>> nameAndCount = new ArrayList<>();
|
||||||
List<TagModel> all = tagService.findAll();
|
List<TagModel> all = tagService.findAll();
|
||||||
for (TagModel t : all) {
|
for (TagModel t : all) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>(2);
|
||||||
jsonObject.put("name", t.getName());
|
map.put("name", t.getName());
|
||||||
jsonObject.put("size", t.getArticles().size());
|
map.put("size", t.getArticles().size());
|
||||||
nameAndCount.add(jsonObject);
|
nameAndCount.add(map);
|
||||||
}
|
}
|
||||||
return Response.success(nameAndCount);
|
return Response.success(nameAndCount);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package cn.celess.blog.entity;
|
package cn.celess.blog.entity;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.sf.json.JSONObject;
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@@ -56,9 +57,9 @@ public class Response<T> implements Serializable {
|
|||||||
return new Response(r.getCode(), r.getMsg(), result);
|
return new Response(r.getCode(), r.getMsg(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(this);
|
return new ObjectMapper().writeValueAsString(this);
|
||||||
return jsonObject.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package cn.celess.blog.entity.request;
|
package cn.celess.blog.entity.request;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
* @date : 2019/06/01 22:47
|
* @date : 2019/06/01 22:47
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class LoginReq {
|
public class LoginReq {
|
||||||
private String email;
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package cn.celess.blog.service;
|
|||||||
|
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : xiaohai
|
* @author : xiaohai
|
||||||
@@ -59,5 +59,5 @@ public interface WebUpdateInfoService {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
JSONObject getLastestUpdateTime();
|
Map<String, Object> getLastestUpdateTime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.springframework.beans.BeanUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import sun.security.krb5.internal.PAData;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -10,14 +10,13 @@ import cn.celess.blog.mapper.PartnerMapper;
|
|||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.blog.service.MailService;
|
||||||
import cn.celess.blog.service.PartnerSiteService;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
import cn.celess.blog.util.HttpUtil;
|
import cn.celess.blog.util.HttpUtil;
|
||||||
import cn.celess.blog.util.JwtUtil;
|
|
||||||
import cn.celess.blog.util.RedisUtil;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import cn.celess.blog.util.RegexUtil;
|
import cn.celess.blog.util.RegexUtil;
|
||||||
|
import com.alibaba.druid.util.StringUtils;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ import cn.celess.blog.service.UserService;
|
|||||||
import cn.celess.blog.util.*;
|
import cn.celess.blog.util.*;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import net.sf.json.JSONArray;
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -28,9 +26,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.beans.Transient;
|
import java.beans.Transient;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -312,14 +308,14 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object deleteUser(Integer[] id) {
|
public Object deleteUser(Integer[] id) {
|
||||||
JSONArray status = new JSONArray();
|
List<Map<String, Object>> status = new ArrayList<>();
|
||||||
if (id == null || id.length == 0) {
|
if (id == null || id.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Integer integer : id) {
|
for (Integer integer : id) {
|
||||||
String role = userMapper.getRoleById(integer);
|
String role = userMapper.getRoleById(integer);
|
||||||
int deleteResult = 0;
|
int deleteResult = 0;
|
||||||
JSONObject deleteStatus = new JSONObject();
|
Map<String, Object> deleteStatus = new HashMap<>(3);
|
||||||
deleteStatus.put("id", integer);
|
deleteStatus.put("id", integer);
|
||||||
// 管理员账户不可删
|
// 管理员账户不可删
|
||||||
if ("admin".equals(role)) {
|
if ("admin".equals(role)) {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import eu.bitwalker.useragentutils.Browser;
|
|||||||
import eu.bitwalker.useragentutils.OperatingSystem;
|
import eu.bitwalker.useragentutils.OperatingSystem;
|
||||||
import eu.bitwalker.useragentutils.UserAgent;
|
import eu.bitwalker.useragentutils.UserAgent;
|
||||||
import eu.bitwalker.useragentutils.Version;
|
import eu.bitwalker.useragentutils.Version;
|
||||||
import org.apache.commons.lang.time.DateUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.json.JsonParserFactory;
|
import org.springframework.boot.json.JsonParserFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -26,6 +25,8 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -67,8 +68,9 @@ public class VisitorServiceImpl implements VisitorService {
|
|||||||
visitor.setUa(request.getHeader("User-Agent"));
|
visitor.setUa(request.getHeader("User-Agent"));
|
||||||
//记录当日的访问
|
//记录当日的访问
|
||||||
String dayVisitCount = redisUtil.get("dayVisitCount");
|
String dayVisitCount = redisUtil.get("dayVisitCount");
|
||||||
long secondsLeftToday = 86400 - DateUtils.getFragmentInSeconds(Calendar.getInstance(), Calendar.DATE);
|
|
||||||
Date date = new Date(Calendar.YEAR);
|
LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||||
|
long secondsLeftToday = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight);
|
||||||
if (dayVisitCount == null) {
|
if (dayVisitCount == null) {
|
||||||
redisUtil.setEx("dayVisitCount", "1", secondsLeftToday, TimeUnit.SECONDS);
|
redisUtil.setEx("dayVisitCount", "1", secondsLeftToday, TimeUnit.SECONDS);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,109 +1,115 @@
|
|||||||
package cn.celess.blog.service.serviceimpl;
|
package cn.celess.blog.service.serviceimpl;
|
||||||
|
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.WebUpdate;
|
import cn.celess.blog.entity.WebUpdate;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
||||||
import cn.celess.blog.service.WebUpdateInfoService;
|
import cn.celess.blog.service.WebUpdateInfoService;
|
||||||
import cn.celess.blog.util.DateFormatUtil;
|
import cn.celess.blog.util.DateFormatUtil;
|
||||||
import cn.celess.blog.util.HttpUtil;
|
import cn.celess.blog.util.HttpUtil;
|
||||||
import cn.celess.blog.util.ModalTrans;
|
import cn.celess.blog.util.ModalTrans;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.alibaba.druid.util.StringUtils;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import net.sf.json.JSONArray;
|
import com.github.pagehelper.PageHelper;
|
||||||
import net.sf.json.JSONObject;
|
import com.github.pagehelper.PageInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.time.Instant;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
/**
|
||||||
/**
|
* @author : xiaohai
|
||||||
* @author : xiaohai
|
* @date : 2019/05/12 11:43
|
||||||
* @date : 2019/05/12 11:43
|
*/
|
||||||
*/
|
@Service
|
||||||
@Service
|
@Slf4j
|
||||||
@Slf4j
|
public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
||||||
public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
@Autowired
|
||||||
@Autowired
|
WebUpdateInfoMapper webUpdateInfoMapper;
|
||||||
WebUpdateInfoMapper webUpdateInfoMapper;
|
|
||||||
|
|
||||||
|
@Override
|
||||||
@Override
|
public WebUpdateModel create(String info) {
|
||||||
public WebUpdateModel create(String info) {
|
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
||||||
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
}
|
||||||
}
|
WebUpdate webUpdate = new WebUpdate(info);
|
||||||
WebUpdate webUpdate = new WebUpdate(info);
|
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
||||||
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
throw new MyException(ResponseEnum.FAILURE);
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
}
|
||||||
}
|
return ModalTrans.webUpdate(webUpdateInfoMapper.findById(webUpdate.getId()));
|
||||||
return ModalTrans.webUpdate(webUpdateInfoMapper.findById(webUpdate.getId()));
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public Boolean del(long id) {
|
||||||
public Boolean del(long id) {
|
if (!webUpdateInfoMapper.existsById(id)) {
|
||||||
if (!webUpdateInfoMapper.existsById(id)) {
|
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
}
|
||||||
}
|
return webUpdateInfoMapper.delete(id) == 1;
|
||||||
return webUpdateInfoMapper.delete(id) == 1;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public WebUpdateModel update(long id, String info) {
|
||||||
public WebUpdateModel update(long id, String info) {
|
WebUpdate webUpdate = webUpdateInfoMapper.findById(id);
|
||||||
WebUpdate webUpdate = webUpdateInfoMapper.findById(id);
|
if (webUpdate == null) {
|
||||||
if (webUpdate == null) {
|
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
}
|
||||||
}
|
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
||||||
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
}
|
||||||
}
|
webUpdate.setUpdateInfo(info);
|
||||||
webUpdate.setUpdateInfo(info);
|
webUpdateInfoMapper.update(id, info);
|
||||||
webUpdateInfoMapper.update(id, info);
|
return ModalTrans.webUpdate(webUpdate);
|
||||||
return ModalTrans.webUpdate(webUpdate);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public PageData<WebUpdateModel> pages(int count, int page) {
|
||||||
public PageData<WebUpdateModel> pages(int count, int page) {
|
PageHelper.startPage(page, count);
|
||||||
PageHelper.startPage(page, count);
|
List<WebUpdate> updateList = webUpdateInfoMapper.findAll();
|
||||||
List<WebUpdate> updateList = webUpdateInfoMapper.findAll();
|
return new PageData<WebUpdateModel>(new PageInfo<WebUpdate>(updateList), list2List(updateList));
|
||||||
return new PageData<WebUpdateModel>(new PageInfo<WebUpdate>(updateList), list2List(updateList));
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public List<WebUpdateModel> findAll() {
|
||||||
public List<WebUpdateModel> findAll() {
|
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
||||||
List<WebUpdate> all = webUpdateInfoMapper.findAll();
|
return list2List(all);
|
||||||
return list2List(all);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
|
||||||
public JSONObject getLastestUpdateTime() {
|
public Map<String, Object> getLastestUpdateTime() {
|
||||||
JSONObject jsonObject = new JSONObject();
|
Map<String, Object> map = new HashMap<>();
|
||||||
jsonObject.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
map.put("lastUpdateTime", DateFormatUtil.get(webUpdateInfoMapper.getLastestOne().getUpdateTime()));
|
||||||
jsonObject.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
|
map.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
|
||||||
String str = HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1");
|
try {
|
||||||
if (!StringUtils.isEmpty(str)) {
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JSONArray array = JSONArray.fromObject(str);
|
String respStr = HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1");
|
||||||
JSONObject object = array.getJSONObject(0);
|
if (!StringUtils.isEmpty(respStr)) {
|
||||||
JSONObject commit = object.getJSONObject("commit");
|
JsonNode root = mapper.readTree(respStr);
|
||||||
jsonObject.put("lastCommit", commit.getString("message"));
|
Iterator<JsonNode> elements = root.elements();
|
||||||
jsonObject.put("committerAuthor", commit.getJSONObject("committer").getString("name"));
|
JsonNode next = elements.next();
|
||||||
Instant parse = Instant.parse(commit.getJSONObject("committer").getString("date"));
|
JsonNode commit = next.get("commit");
|
||||||
jsonObject.put("committerDate", DateFormatUtil.get(Date.from(parse)));
|
map.put("lastCommit", commit.get("message"));
|
||||||
jsonObject.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + object.getString("sha"));
|
map.put("committerAuthor", commit.get("committer").get("name"));
|
||||||
}
|
Instant parse = Instant.parse(commit.get("committer").get("date").asText());
|
||||||
return jsonObject;
|
map.put("committerDate", DateFormatUtil.get(Date.from(parse)));
|
||||||
}
|
map.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + next.get("sha").asText());
|
||||||
|
}
|
||||||
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
} catch (IOException e) {
|
||||||
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
log.info("网络请求失败{}", e.getMessage());
|
||||||
webUpdates.forEach(update -> webUpdateModels.add(ModalTrans.webUpdate(update)));
|
}
|
||||||
return webUpdateModels;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private List<WebUpdateModel> list2List(List<WebUpdate> webUpdates) {
|
||||||
|
List<WebUpdateModel> webUpdateModels = new ArrayList<>();
|
||||||
|
webUpdates.forEach(update -> webUpdateModels.add(ModalTrans.webUpdate(update)));
|
||||||
|
return webUpdateModels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package cn.celess.blog.util;
|
|||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.exception.MyException;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -31,24 +32,27 @@ public class RedisUserUtil {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User getWithOutExc() {
|
public User getWithOutExc() {
|
||||||
String token = request.getHeader("Authorization");
|
String token = request.getHeader("Authorization");
|
||||||
if (token == null || token.isEmpty()) {
|
if (token == null || token.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String email = jwtUtil.getUsernameFromToken(token);
|
String email = jwtUtil.getUsernameFromToken(token);
|
||||||
return (User) JSONObject.toBean(JSONObject.fromObject(redisUtil.get(email + "-login")), User.class);
|
return new ObjectMapper().readValue(redisUtil.get(email + "-login"), User.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User set(User user) {
|
public User set(User user) {
|
||||||
Long expire = redisUtil.getExpire(user.getEmail() + "-login");
|
Long expire = redisUtil.getExpire(user.getEmail() + "-login");
|
||||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
redisUtil.setEx(user.getEmail() + "-login", new ObjectMapper().writeValueAsString(user),
|
||||||
expire > 0 ? expire : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
expire > 0 ? expire : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public User set(User user, boolean isRemember) {
|
public User set(User user, boolean isRemember) {
|
||||||
redisUtil.setEx(user.getEmail() + "-login", JSONObject.fromObject(user).toString(),
|
redisUtil.setEx(user.getEmail() + "-login", new ObjectMapper().writeValueAsString(user),
|
||||||
isRemember ? JwtUtil.EXPIRATION_LONG_TIME : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
isRemember ? JwtUtil.EXPIRATION_LONG_TIME : JwtUtil.EXPIRATION_SHORT_TIME, TimeUnit.MILLISECONDS);
|
||||||
request.getSession().setAttribute("email", user.getEmail());
|
request.getSession().setAttribute("email", user.getEmail());
|
||||||
return user;
|
return user;
|
||||||
|
|||||||
@@ -1,344 +1,347 @@
|
|||||||
package cn.celess.blog;
|
package cn.celess.blog;
|
||||||
|
|
||||||
|
|
||||||
import cn.celess.blog.entity.Response;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.QiniuResponse;
|
import cn.celess.blog.entity.model.QiniuResponse;
|
||||||
import cn.celess.blog.entity.model.UserModel;
|
import cn.celess.blog.entity.model.UserModel;
|
||||||
import cn.celess.blog.entity.request.LoginReq;
|
import cn.celess.blog.entity.request.LoginReq;
|
||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.blog.service.MailService;
|
||||||
import cn.celess.blog.service.QiniuService;
|
import cn.celess.blog.service.QiniuService;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.qiniu.storage.model.FileInfo;
|
import com.qiniu.storage.model.FileInfo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.IOException;
|
import java.io.InputStream;
|
||||||
import java.io.InputStream;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Field;
|
import java.util.Map;
|
||||||
import java.util.Map;
|
import java.util.UUID;
|
||||||
import java.util.UUID;
|
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
|
/**
|
||||||
/**
|
* @Author: 小海
|
||||||
* @Author: 小海
|
* @Date: 2019/08/22 12:46
|
||||||
* @Date: 2019/08/22 12:46
|
* @Description: 测试基类
|
||||||
* @Description: 测试基类
|
*/
|
||||||
*/
|
@SpringBootTest
|
||||||
@SpringBootTest
|
@RunWith(SpringRunner.class)
|
||||||
@RunWith(SpringRunner.class)
|
@WebAppConfiguration
|
||||||
@WebAppConfiguration
|
@ActiveProfiles("test")
|
||||||
@ActiveProfiles("test")
|
public class BaseTest {
|
||||||
public class BaseTest {
|
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
||||||
|
protected MockMvc mockMvc;
|
||||||
protected MockMvc mockMvc;
|
protected final static String Code = "code";
|
||||||
protected final static String Code = "code";
|
protected final static String Result = "result";
|
||||||
protected final static String Result = "result";
|
protected final static String USERE_MAIL = "zh56462271@qq.com";
|
||||||
/**
|
protected final static String ADMIN_EMAIL = "a@celess.cn";
|
||||||
* jackson 序列化/反序列化Json
|
|
||||||
*/
|
/**
|
||||||
protected final ObjectMapper mapper = new ObjectMapper();
|
* jackson 序列化/反序列化Json
|
||||||
protected static final TypeReference<?> BOOLEAN_TYPE = new TypeReference<Response<Boolean>>() {
|
*/
|
||||||
};
|
protected final ObjectMapper mapper = new ObjectMapper();
|
||||||
protected static final TypeReference<?> STRING_TYPE = new TypeReference<Response<String>>() {
|
protected static final TypeReference<?> BOOLEAN_TYPE = new TypeReference<Response<Boolean>>() {
|
||||||
};
|
};
|
||||||
protected static final TypeReference<?> OBJECT_TYPE = new TypeReference<Response<Object>>() {
|
protected static final TypeReference<?> STRING_TYPE = new TypeReference<Response<String>>() {
|
||||||
};
|
};
|
||||||
protected static final TypeReference<?> MAP_OBJECT_TYPE = new TypeReference<Response<Map<String, Object>>>() {
|
protected static final TypeReference<?> OBJECT_TYPE = new TypeReference<Response<Object>>() {
|
||||||
};
|
};
|
||||||
@Autowired
|
protected static final TypeReference<?> MAP_OBJECT_TYPE = new TypeReference<Response<Map<String, Object>>>() {
|
||||||
private WebApplicationContext wac;
|
};
|
||||||
protected MockHttpSession session;
|
|
||||||
|
@Autowired
|
||||||
@Before
|
private WebApplicationContext wac;
|
||||||
public void before() {
|
protected MockHttpSession session;
|
||||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
|
||||||
session = new MockHttpSession();
|
@Before
|
||||||
System.out.println("==========> 开始测试 <=========");
|
public void before() {
|
||||||
}
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
||||||
|
session = new MockHttpSession();
|
||||||
@After
|
System.out.println("==========> 开始测试 <=========");
|
||||||
public void after() {
|
}
|
||||||
System.out.println("==========> 测试结束 <=========");
|
|
||||||
}
|
@After
|
||||||
|
public void after() {
|
||||||
/**
|
System.out.println("==========> 测试结束 <=========");
|
||||||
* admin 权限用户登录
|
}
|
||||||
*
|
|
||||||
* @return token
|
/**
|
||||||
*/
|
* admin 权限用户登录
|
||||||
protected String adminLogin() {
|
*
|
||||||
LoginReq req = new LoginReq();
|
* @return token
|
||||||
req.setEmail("a@celess.cn");
|
*/
|
||||||
req.setPassword("123456789");
|
protected String adminLogin() {
|
||||||
req.setIsRememberMe(true);
|
LoginReq req = new LoginReq();
|
||||||
String token = login(req);
|
req.setEmail(ADMIN_EMAIL);
|
||||||
assertNotNull(token);
|
req.setPassword("123456789");
|
||||||
return token;
|
req.setIsRememberMe(true);
|
||||||
}
|
String token = login(req);
|
||||||
|
assertNotNull(token);
|
||||||
/**
|
return token;
|
||||||
* user 权限用户登录
|
}
|
||||||
*
|
|
||||||
* @return token
|
/**
|
||||||
*/
|
* user 权限用户登录
|
||||||
protected String userLogin() {
|
*
|
||||||
LoginReq req = new LoginReq();
|
* @return token
|
||||||
req.setEmail("zh56462271@qq.com");
|
*/
|
||||||
req.setPassword("123456789");
|
protected String userLogin() {
|
||||||
req.setIsRememberMe(true);
|
LoginReq req = new LoginReq();
|
||||||
String token = login(req);
|
req.setEmail(USERE_MAIL);
|
||||||
assertNotNull(token);
|
req.setPassword("123456789");
|
||||||
return token;
|
req.setIsRememberMe(true);
|
||||||
}
|
String token = login(req);
|
||||||
|
assertNotNull(token);
|
||||||
/**
|
return token;
|
||||||
* 登录逻辑
|
}
|
||||||
*
|
|
||||||
* @param req 用户信息
|
/**
|
||||||
* @return token | null
|
* 登录逻辑
|
||||||
*/
|
*
|
||||||
private String login(LoginReq req) {
|
* @param req 用户信息
|
||||||
String str = null;
|
* @return token | null
|
||||||
try {
|
*/
|
||||||
str = getMockData(post("/login"), null, req)
|
protected String login(LoginReq req) {
|
||||||
.andReturn().getResponse().getContentAsString();
|
String str = null;
|
||||||
Response<UserModel> response = mapper.readValue(str, new TypeReference<Response<UserModel>>() {
|
try {
|
||||||
});
|
str = getMockData(post("/login"), null, req)
|
||||||
assertEquals(SUCCESS.getCode(), response.getCode());
|
.andReturn().getResponse().getContentAsString();
|
||||||
String token = response.getResult().getToken();
|
Response<UserModel> response = mapper.readValue(str, new TypeReference<Response<UserModel>>() {
|
||||||
assertNotNull(token);
|
});
|
||||||
return token;
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
} catch (Exception e) {
|
String token = response.getResult().getToken();
|
||||||
logger.error("测试登录错误");
|
assertNotNull(token);
|
||||||
e.printStackTrace();
|
return token;
|
||||||
}
|
} catch (Exception e) {
|
||||||
assertNotNull(str);
|
logger.error("测试登录错误");
|
||||||
return null;
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
assertNotNull(str);
|
||||||
@Test
|
return null;
|
||||||
public void test() {
|
}
|
||||||
// 测试登录
|
|
||||||
assertNotNull(userLogin());
|
@Test
|
||||||
assertNotNull(adminLogin());
|
public void test() {
|
||||||
assertNotEquals(userLogin(), adminLogin());
|
// 测试登录
|
||||||
try {
|
assertNotNull(userLogin());
|
||||||
// 测试getMockData方法
|
assertNotNull(adminLogin());
|
||||||
assertNotNull(getMockData(get("/headerInfo")));
|
assertNotEquals(userLogin(), adminLogin());
|
||||||
getMockData((get("/headerInfo"))).andDo(result -> assertNotNull(getResponse(result, OBJECT_TYPE)));
|
try {
|
||||||
} catch (Exception e) {
|
// 测试getMockData方法
|
||||||
e.printStackTrace();
|
assertNotNull(getMockData(get("/headerInfo")));
|
||||||
}
|
getMockData((get("/headerInfo"))).andDo(result -> assertNotNull(getResponse(result, OBJECT_TYPE)));
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
/**
|
}
|
||||||
* 产生指定长度的随机字符
|
}
|
||||||
*
|
|
||||||
* @param len len
|
/**
|
||||||
* @return str
|
* 产生指定长度的随机字符
|
||||||
*/
|
*
|
||||||
protected String randomStr(int len) {
|
* @param len len
|
||||||
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, len);
|
* @return str
|
||||||
}
|
*/
|
||||||
|
protected String randomStr(int len) {
|
||||||
/**
|
return UUID.randomUUID().toString().replaceAll("-", "").substring(0, len);
|
||||||
* 产生指定长度的随机字符
|
}
|
||||||
*
|
|
||||||
* @return str
|
/**
|
||||||
*/
|
* 产生指定长度的随机字符
|
||||||
protected String randomStr() {
|
*
|
||||||
return UUID.randomUUID().toString();
|
* @return str
|
||||||
}
|
*/
|
||||||
|
protected String randomStr() {
|
||||||
/**
|
return UUID.randomUUID().toString();
|
||||||
* 抽离的mock请求方法
|
}
|
||||||
*
|
|
||||||
* @param builder MockHttpServletRequestBuilder :get(...) post(...) ....
|
/**
|
||||||
* @return 返回 ResultActions
|
* 抽离的mock请求方法
|
||||||
* @throws Exception exc
|
*
|
||||||
*/
|
* @param builder MockHttpServletRequestBuilder :get(...) post(...) ....
|
||||||
protected ResultActions getMockData(MockHttpServletRequestBuilder builder) throws Exception {
|
* @return 返回 ResultActions
|
||||||
return getMockData(builder, null, null);
|
* @throws Exception exc
|
||||||
}
|
*/
|
||||||
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder) throws Exception {
|
||||||
/**
|
return getMockData(builder, null, null);
|
||||||
* 抽离的mock请求方法 重载
|
}
|
||||||
*
|
|
||||||
* @param builder ..
|
/**
|
||||||
* @param token 用户登录的token
|
* 抽离的mock请求方法 重载
|
||||||
* @return ..
|
*
|
||||||
* @throws Exception ..
|
* @param builder ..
|
||||||
*/
|
* @param token 用户登录的token
|
||||||
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token) throws Exception {
|
* @return ..
|
||||||
return getMockData(builder, token, null);
|
* @throws Exception ..
|
||||||
}
|
*/
|
||||||
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token) throws Exception {
|
||||||
/**
|
return getMockData(builder, token, null);
|
||||||
* 抽离的mock请求方法 重载
|
}
|
||||||
*
|
|
||||||
* @param builder ..
|
/**
|
||||||
* @param token ..
|
* 抽离的mock请求方法 重载
|
||||||
* @param content http中发送的APPLICATION_JSON的json数据
|
*
|
||||||
* @return ..
|
* @param builder ..
|
||||||
* @throws Exception ..
|
* @param token ..
|
||||||
*/
|
* @param content http中发送的APPLICATION_JSON的json数据
|
||||||
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token, Object content) throws Exception {
|
* @return ..
|
||||||
// MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get(url);
|
* @throws Exception ..
|
||||||
if (token != null) {
|
*/
|
||||||
builder.header("Authorization", token);
|
protected ResultActions getMockData(MockHttpServletRequestBuilder builder, String token, Object content) throws Exception {
|
||||||
}
|
// MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get(url);
|
||||||
if (content != null) {
|
if (token != null) {
|
||||||
builder.content(mapper.writeValueAsString(content)).contentType(MediaType.APPLICATION_JSON);
|
builder.header("Authorization", token);
|
||||||
}
|
}
|
||||||
return mockMvc.perform(builder).andExpect(status().isOk());
|
if (content != null) {
|
||||||
}
|
builder.content(mapper.writeValueAsString(content)).contentType(MediaType.APPLICATION_JSON);
|
||||||
|
logger.debug("param::json->{}", mapper.writeValueAsString(content));
|
||||||
|
}
|
||||||
protected <T> Response<T> getResponse(String json) {
|
return mockMvc.perform(builder).andExpect(status().isOk());
|
||||||
return getResponse(json, OBJECT_TYPE);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected <T> Response<T> getResponse(MvcResult result) {
|
protected <T> Response<T> getResponse(String json) {
|
||||||
return getResponse(result, OBJECT_TYPE);
|
return getResponse(json, OBJECT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected <T> Response<T> getResponse(MvcResult result) {
|
||||||
* 根据json 信息反序列化成Response对象
|
return getResponse(result, OBJECT_TYPE);
|
||||||
*
|
}
|
||||||
* @param json json
|
|
||||||
* @param <T> 泛型
|
/**
|
||||||
* @return Response对象
|
* 根据json 信息反序列化成Response对象
|
||||||
*/
|
*
|
||||||
protected <T> Response<T> getResponse(String json, TypeReference<?> responseType) {
|
* @param json json
|
||||||
Response<T> response = null;
|
* @param <T> 泛型
|
||||||
System.out.println(responseType.getType());
|
* @return Response对象
|
||||||
try {
|
*/
|
||||||
response = mapper.readValue(json, responseType);
|
protected <T> Response<T> getResponse(String json, TypeReference<?> responseType) {
|
||||||
} catch (IOException e) {
|
Response<T> response = null;
|
||||||
logger.error("解析json Response对象错误,json:[{}]", json);
|
try {
|
||||||
e.printStackTrace();
|
response = mapper.readValue(json, responseType);
|
||||||
}
|
} catch (IOException e) {
|
||||||
assertNotNull(response);
|
logger.error("解析json Response对象错误,json:[{}]", json);
|
||||||
return response;
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
assertNotNull(response);
|
||||||
/**
|
return response;
|
||||||
* 根据json 信息反序列化成Response对象
|
}
|
||||||
*
|
|
||||||
* @param result MvcResult
|
/**
|
||||||
* @param <T> 泛型
|
* 根据json 信息反序列化成Response对象
|
||||||
* @return Response对象
|
*
|
||||||
*/
|
* @param result MvcResult
|
||||||
protected <T> Response<T> getResponse(MvcResult result, TypeReference<?> responseType) {
|
* @param <T> 泛型
|
||||||
try {
|
* @return Response对象
|
||||||
return getResponse(result.getResponse().getContentAsString(), responseType);
|
*/
|
||||||
} catch (UnsupportedEncodingException e) {
|
protected <T> Response<T> getResponse(MvcResult result, TypeReference<?> responseType) {
|
||||||
logger.error("解析json Response对象错误,result:[{}]", result);
|
try {
|
||||||
e.printStackTrace();
|
return getResponse(result.getResponse().getContentAsString(), responseType);
|
||||||
}
|
} catch (UnsupportedEncodingException e) {
|
||||||
return null;
|
logger.error("解析json Response对象错误,result:[{}]", result);
|
||||||
}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
/**
|
}
|
||||||
* 修改 mailService 的实现类
|
|
||||||
*
|
|
||||||
* @param service service 类
|
/**
|
||||||
* @param mailFiledName service 中自动注入的mailService字段名
|
* 修改 mailService 的实现类
|
||||||
*/
|
*
|
||||||
protected void mockInjectInstance(Object service, String mailFiledName, Object impl) {
|
* @param service service 类
|
||||||
Field field;
|
* @param mailFiledName service 中自动注入的mailService字段名
|
||||||
try {
|
*/
|
||||||
field = service.getClass().getDeclaredField(mailFiledName);
|
protected void mockInjectInstance(Object service, String mailFiledName, Object impl) {
|
||||||
field.setAccessible(true);
|
Field field;
|
||||||
field.set(service, impl);
|
try {
|
||||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
assertNotNull(service);
|
||||||
e.printStackTrace();
|
field = service.getClass().getDeclaredField(mailFiledName);
|
||||||
}
|
field.setAccessible(true);
|
||||||
}
|
field.set(service, impl);
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
@Slf4j
|
}
|
||||||
public static class TestMailServiceImpl implements MailService {
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean AsyncSend(SimpleMailMessage message) {
|
@Slf4j
|
||||||
log.debug("异步邮件请求,SimpleMailMessage:[{}]", getJson(message));
|
public static class TestMailServiceImpl implements MailService {
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
|
public Boolean AsyncSend(SimpleMailMessage message) {
|
||||||
@Override
|
log.debug("异步邮件请求,SimpleMailMessage:[{}]", getJson(message));
|
||||||
public Boolean send(SimpleMailMessage message) {
|
return true;
|
||||||
log.debug("邮件请求,SimpleMailMessage:[{}]", getJson(message));
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
|
public Boolean send(SimpleMailMessage message) {
|
||||||
/**
|
log.debug("邮件请求,SimpleMailMessage:[{}]", getJson(message));
|
||||||
* 转json
|
return true;
|
||||||
*
|
}
|
||||||
* @param o
|
|
||||||
* @return
|
/**
|
||||||
*/
|
* 转json
|
||||||
private String getJson(Object o) {
|
*
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
* @param o
|
||||||
try {
|
* @return
|
||||||
return mapper.writeValueAsString(o);
|
*/
|
||||||
} catch (JsonProcessingException e) {
|
private String getJson(Object o) {
|
||||||
return null;
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
}
|
try {
|
||||||
}
|
return mapper.writeValueAsString(o);
|
||||||
}
|
} catch (JsonProcessingException e) {
|
||||||
|
return null;
|
||||||
@Slf4j
|
}
|
||||||
public static class TestQiNiuServiceImpl implements QiniuService {
|
}
|
||||||
@Override
|
}
|
||||||
public QiniuResponse uploadFile(InputStream is, String fileName) {
|
|
||||||
QiniuResponse response = new QiniuResponse();
|
@Slf4j
|
||||||
log.debug("上传文件请求,[fileName:{}]", fileName);
|
public static class TestQiNiuServiceImpl implements QiniuService {
|
||||||
|
@Override
|
||||||
response.key = "key";
|
public QiniuResponse uploadFile(InputStream is, String fileName) {
|
||||||
response.bucket = "bucket";
|
QiniuResponse response = new QiniuResponse();
|
||||||
response.hash = "hash";
|
log.debug("上传文件请求,[fileName:{}]", fileName);
|
||||||
response.fsize = 1;
|
|
||||||
return response;
|
response.key = "key";
|
||||||
}
|
response.bucket = "bucket";
|
||||||
|
response.hash = "hash";
|
||||||
@Override
|
response.fsize = 1;
|
||||||
public FileInfo[] getFileList() {
|
return response;
|
||||||
log.debug("获取文件列表请求");
|
}
|
||||||
return new FileInfo[0];
|
|
||||||
}
|
@Override
|
||||||
}
|
public FileInfo[] getFileList() {
|
||||||
|
log.debug("获取文件列表请求");
|
||||||
}
|
return new FileInfo[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package cn.celess.blog;
|
package cn.celess.blog;
|
||||||
|
|
||||||
import redis.embedded.RedisServer;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import redis.embedded.RedisServer;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|||||||
@@ -9,29 +9,30 @@ import cn.celess.blog.entity.model.PageData;
|
|||||||
import cn.celess.blog.entity.request.ArticleReq;
|
import cn.celess.blog.entity.request.ArticleReq;
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import java.util.*;
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
|
||||||
|
|
||||||
public class ArticleControllerTest extends BaseTest {
|
public class ArticleControllerTest extends BaseTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
ArticleMapper articleMapper;
|
ArticleMapper articleMapper;
|
||||||
|
private static final TypeReference<?> ARTICLE_MODEL_TYPE = new TypeReference<Response<ArticleModel>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> ARTICLE_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<ArticleModel>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() {
|
public void create() {
|
||||||
ArticleReq articleReq = new ArticleReq();
|
ArticleReq articleReq = new ArticleReq();
|
||||||
// 应该正常通过
|
// 应该正常通过
|
||||||
articleReq.setTitle("test-" + UUID.randomUUID().toString());
|
articleReq.setTitle("test-" + randomStr());
|
||||||
articleReq.setMdContent("# test title");
|
articleReq.setMdContent("# test title");
|
||||||
articleReq.setCategory("随笔");
|
articleReq.setCategory("随笔");
|
||||||
String[] tagList = {"tag", "category"};
|
String[] tagList = {"tag", "category"};
|
||||||
@@ -39,58 +40,29 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
articleReq.setOpen(true);
|
articleReq.setOpen(true);
|
||||||
articleReq.setType(true);
|
articleReq.setType(true);
|
||||||
articleReq.setUrl("http://xxxx.com");
|
articleReq.setUrl("http://xxxx.com");
|
||||||
JSONObject jsonObject = JSONObject.fromObject(articleReq);
|
MockHttpServletRequestBuilder post = post("/admin/article/create");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 未登录
|
getMockData(post, adminLogin(), articleReq).andDo(result -> {
|
||||||
mockMvc.perform(post("/admin/article/create")
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
.content(jsonObject.toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.contentType("application/json"))
|
assertNotNull(response.getResult());
|
||||||
.andExpect(status().isOk())
|
ArticleModel articleModel = response.getResult();
|
||||||
.andDo(result -> {
|
assertNotNull(articleModel.getId());
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(),
|
assertNotNull(articleModel.getTitle());
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
assertNotNull(articleModel.getSummary());
|
||||||
);
|
assertNotNull(articleModel.getOriginal());
|
||||||
});
|
assertNotNull(articleModel.getTags());
|
||||||
// User权限
|
assertNotNull(articleModel.getCategory());
|
||||||
String token = userLogin();
|
assertNotNull(articleModel.getPublishDateFormat());
|
||||||
mockMvc.perform(post("/admin/article/create")
|
assertNotNull(articleModel.getMdContent());
|
||||||
.content(jsonObject.toString())
|
assertNotNull(articleModel.getPreArticle());
|
||||||
.contentType("application/json")
|
assertNull(articleModel.getNextArticle());
|
||||||
.header("Authorization", token))
|
assertNotNull(articleModel.getOpen());
|
||||||
.andExpect(status().isOk())
|
assertNotNull(articleModel.getReadingNumber());
|
||||||
.andDo(result -> {
|
assertNotNull(articleModel.getAuthor());
|
||||||
assertEquals(PERMISSION_ERROR.getCode(),
|
assertNotNull(articleModel.getUrl());
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
});
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Admin权限
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(post("/admin/article/create")
|
|
||||||
.content(jsonObject.toString())
|
|
||||||
.contentType("application/json")
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
ArticleModel articleModel = (ArticleModel) JSONObject.toBean(object.getJSONObject(Result), ArticleModel.class);
|
|
||||||
assertNotNull(articleModel.getId());
|
|
||||||
assertNotNull(articleModel.getTitle());
|
|
||||||
assertNotNull(articleModel.getSummary());
|
|
||||||
assertNotNull(articleModel.getOriginal());
|
|
||||||
assertNotNull(articleModel.getTags());
|
|
||||||
assertNotNull(articleModel.getCategory());
|
|
||||||
assertNotNull(articleModel.getPublishDateFormat());
|
|
||||||
assertNotNull(articleModel.getMdContent());
|
|
||||||
assertNotNull(articleModel.getPreArticle());
|
|
||||||
assertNull(articleModel.getNextArticle());
|
|
||||||
assertNotNull(articleModel.getOpen());
|
|
||||||
assertNotNull(articleModel.getReadingNumber());
|
|
||||||
assertNotNull(articleModel.getAuthor());
|
|
||||||
assertNotNull(articleModel.getUrl());
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -98,33 +70,22 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void delete() {
|
public void delete() {
|
||||||
Article article = articleMapper.getLastestArticle();
|
Article article;
|
||||||
|
do {
|
||||||
|
article = articleMapper.getLastestArticle();
|
||||||
|
create();
|
||||||
|
} while (article.isDeleted());
|
||||||
|
assertFalse(article.isDeleted());
|
||||||
|
MockHttpServletRequestBuilder delete = MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId());
|
||||||
try {
|
try {
|
||||||
// 未登录删除文章
|
Article finalArticle = article;
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
getMockData(delete, adminLogin()).andDo(result -> {
|
||||||
).andDo(result -> {
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(),
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)
|
// 断言删除成功
|
||||||
);
|
assertTrue(response.getResult());
|
||||||
|
assertTrue(articleMapper.isDeletedById(finalArticle.getId()));
|
||||||
});
|
});
|
||||||
// user 权限删除文章
|
|
||||||
String token = userLogin();
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(),
|
|
||||||
JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
|
||||||
);
|
|
||||||
// admin 权限删除文章
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/article/del?articleID=" + article.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
// 断言删除成功
|
|
||||||
assertTrue(object.getBoolean(Result));
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -146,27 +107,21 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
articleReq.setTags(tagList);
|
articleReq.setTags(tagList);
|
||||||
articleReq.setTitle("test-" + article.getTitle());
|
articleReq.setTitle("test-" + article.getTitle());
|
||||||
try {
|
try {
|
||||||
// Admin 权限
|
getMockData(put("/admin/article/update"), adminLogin(), articleReq).andDo(result -> {
|
||||||
mockMvc.perform(put("/admin/article/update")
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(articleReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.contentType("application/json")
|
ArticleModel a = response.getResult();
|
||||||
.header("Authorization", adminLogin()))
|
assertEquals(articleReq.getCategory(), a.getCategory());
|
||||||
.andExpect(status().isOk())
|
assertEquals(articleReq.getUrl(), a.getUrl());
|
||||||
.andDo(result -> {
|
assertEquals(articleReq.getMdContent(), a.getMdContent());
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(articleReq.getTitle(), a.getTitle());
|
||||||
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
assertEquals(articleReq.getType(), a.getOriginal());
|
||||||
ArticleModel a = (ArticleModel) JSONObject.toBean(jsonObject.getJSONObject(Result), ArticleModel.class);
|
// Tag
|
||||||
assertEquals(articleReq.getCategory(), a.getCategory());
|
List<Tag> asList = a.getTags();
|
||||||
assertEquals(articleReq.getUrl(), a.getUrl());
|
assertEquals(3, asList.size());
|
||||||
assertEquals(articleReq.getMdContent(), a.getMdContent());
|
assertEquals(articleReq.getOpen(), a.getOpen());
|
||||||
assertEquals(articleReq.getTitle(), a.getTitle());
|
assertEquals(articleReq.getId(), a.getId());
|
||||||
assertEquals(articleReq.getType(), a.getOriginal());
|
});
|
||||||
// Tag
|
|
||||||
List<Tag> asList = a.getTags();
|
|
||||||
assertEquals(3, asList.size());
|
|
||||||
assertEquals(articleReq.getOpen(), a.getOpen());
|
|
||||||
assertEquals(articleReq.getId(), a.getId());
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -176,43 +131,35 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
public void retrieveOneById() {
|
public void retrieveOneById() {
|
||||||
try {
|
try {
|
||||||
long articleID = 3;
|
long articleID = 3;
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/article/articleID/" + articleID))
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID));
|
||||||
.andExpect(status().is(200));
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=true"));
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=true"))
|
|
||||||
.andExpect(status().is(200));
|
|
||||||
|
|
||||||
// 文章不存在
|
// 文章不存在
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/article/articleID/-1"))
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/-1"))
|
||||||
.andExpect(status().is(200))
|
.andDo(result -> assertEquals(ARTICLE_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(ARTICLE_NOT_EXIST.getCode(), jsonObject.getInt(Code));
|
|
||||||
});
|
|
||||||
|
|
||||||
// 正常情况
|
// 正常情况
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=false"))
|
getMockData(MockMvcRequestBuilders.get("/article/articleID/" + articleID + "?update=false")).andDo(result -> {
|
||||||
.andExpect(status().is(200))
|
Response<ArticleModel> response = getResponse(result, ARTICLE_MODEL_TYPE);
|
||||||
.andDo(result -> {
|
// 断言获取数据成功
|
||||||
JSONObject articleJson = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
// 断言获取数据成功
|
assertNotNull(response.getResult());
|
||||||
assertEquals(SUCCESS.getCode(), articleJson.getInt(Code));
|
|
||||||
assertNotNull(articleJson.getJSONObject(Result));
|
|
||||||
|
|
||||||
ArticleModel a = (ArticleModel) JSONObject.toBean(articleJson.getJSONObject(Result), ArticleModel.class);
|
ArticleModel a = response.getResult();
|
||||||
assertNotNull(a.getTitle());
|
assertNotNull(a.getTitle());
|
||||||
assertNotNull(a.getId());
|
assertNotNull(a.getId());
|
||||||
assertNotNull(a.getSummary());
|
assertNotNull(a.getSummary());
|
||||||
assertNotNull(a.getMdContent());
|
assertNotNull(a.getMdContent());
|
||||||
assertNotNull(a.getUrl());
|
assertNotNull(a.getUrl());
|
||||||
assertNotNull(a.getUpdateDateFormat());
|
assertNotNull(a.getUpdateDateFormat());
|
||||||
assertTrue(a.getPreArticle() != null || a.getNextArticle() != null);
|
assertTrue(a.getPreArticle() != null || a.getNextArticle() != null);
|
||||||
assertNotNull(a.getReadingNumber());
|
assertNotNull(a.getReadingNumber());
|
||||||
assertNotNull(a.getOriginal());
|
assertNotNull(a.getOriginal());
|
||||||
assertNotNull(a.getPublishDateFormat());
|
assertNotNull(a.getPublishDateFormat());
|
||||||
assertNotNull(a.getCategory());
|
assertNotNull(a.getCategory());
|
||||||
assertNotNull(a.getTags());
|
assertNotNull(a.getTags());
|
||||||
assertNotNull(a.getAuthor());
|
assertNotNull(a.getAuthor());
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -222,39 +169,32 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
public void articles() {
|
public void articles() {
|
||||||
try {
|
try {
|
||||||
// 测试不带参数访问
|
// 测试不带参数访问
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles"))
|
getMockData(MockMvcRequestBuilders.get("/articles"));
|
||||||
.andExpect(status().is(200));
|
getMockData(MockMvcRequestBuilders.get("/articles?page=1&count=5")).andDo(result -> {
|
||||||
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles?page=1&count=5"))
|
// 断言获取数据成功
|
||||||
.andExpect(status().is(200))
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.andDo(result -> {
|
// 结果集非空
|
||||||
JSONObject articlesJSON = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertNotNull(response.getResult());
|
||||||
Response response = (Response) JSONObject.toBean(articlesJSON, Response.class);
|
// 判断pageInfo是否包装完全
|
||||||
// 断言获取数据成功
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
assertEquals(SUCCESS.getCode(), response.getCode());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
// 结果集非空
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotNull(response.getResult());
|
assertEquals(5, pageData.getPageSize());
|
||||||
// 判断pageInfo是否包装完全
|
// 内容完整
|
||||||
JSONObject resultJson = JSONObject.fromObject(response.getResult());
|
for (ArticleModel a : pageData.getList()) {
|
||||||
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(resultJson, PageData.class);
|
assertNotNull(a.getTitle());
|
||||||
assertNotEquals(0, pageData.getTotal());
|
assertNotNull(a.getId());
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertNotNull(a.getSummary());
|
||||||
assertEquals(5, pageData.getPageSize());
|
assertNotNull(a.getOriginal());
|
||||||
// 内容完整
|
assertNotNull(a.getPublishDateFormat());
|
||||||
for (Object arc : pageData.getList()) {
|
assertNotNull(a.getCategory());
|
||||||
ArticleModel a = (ArticleModel) JSONObject.toBean(JSONObject.fromObject(arc), ArticleModel.class);
|
assertNotNull(a.getTags());
|
||||||
assertNotNull(a.getTitle());
|
assertNotNull(a.getAuthor());
|
||||||
assertNotNull(a.getId());
|
assertNull(a.getOpen());
|
||||||
assertNotNull(a.getSummary());
|
assertNull(a.getMdContent());
|
||||||
assertNotNull(a.getOriginal());
|
}
|
||||||
assertNotNull(a.getPublishDateFormat());
|
});
|
||||||
assertNotNull(a.getCategory());
|
|
||||||
assertNotNull(a.getTags());
|
|
||||||
assertNotNull(a.getAuthor());
|
|
||||||
assertNull(a.getOpen());
|
|
||||||
assertNull(a.getMdContent());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -264,19 +204,18 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
public void adminArticles() {
|
public void adminArticles() {
|
||||||
try {
|
try {
|
||||||
getMockData(get("/admin/articles?page=1&count=10")).andExpect(result ->
|
getMockData(get("/admin/articles?page=1&count=10")).andExpect(result ->
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), mapper.readValue(result.getResponse().getContentAsString(), Response.class).getCode())
|
assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result, STRING_TYPE).getCode())
|
||||||
);
|
);
|
||||||
|
|
||||||
// User权限登陆
|
// User权限登陆
|
||||||
getMockData(get("/admin/articles?page=1&count=10"), userLogin()).andDo(result ->
|
getMockData(get("/admin/articles?page=1&count=10"), userLogin()).andDo(result ->
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), mapper.readValue(result.getResponse().getContentAsString(), Response.class).getCode())
|
assertEquals(PERMISSION_ERROR.getCode(), getResponse(result, STRING_TYPE).getCode())
|
||||||
);
|
);
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
// admin权限登陆
|
// admin权限登陆
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
getMockData(get("/admin/articles?page=1&count=10&deleted=" + (i == 1)), adminLogin()).andDo(result -> {
|
getMockData(get("/admin/articles?page=1&count=10&deleted=" + (i == 1)), adminLogin()).andDo(result -> {
|
||||||
Response<PageData<ArticleModel>> response = mapper.readValue(result.getResponse().getContentAsString(), new TypeReference<Response<PageData<ArticleModel>>>() {
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
});
|
|
||||||
assertEquals(SUCCESS.getCode(), response.getCode());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(response.getResult());
|
assertNotNull(response.getResult());
|
||||||
// 判断pageInfo是否包装完全
|
// 判断pageInfo是否包装完全
|
||||||
@@ -309,27 +248,22 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
try {
|
try {
|
||||||
// 分类不存在
|
// 分类不存在
|
||||||
String categoryName = "NoSuchCategory";
|
String categoryName = "NoSuchCategory";
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
getMockData(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
||||||
.andExpect(status().is(200))
|
.andDo(result -> assertEquals(CATEGORY_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(CATEGORY_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// 正常查询
|
// 正常查询
|
||||||
categoryName = "linux";
|
categoryName = "linux";
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
getMockData(MockMvcRequestBuilders.get("/articles/category/" + categoryName + "?page=1&count=10"))
|
||||||
.andExpect(status().is(200))
|
|
||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(jsonObject.getJSONObject(Result), PageData.class);
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
assertNotEquals(0, pageData.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertEquals(10, pageData.getPageSize());
|
assertEquals(10, pageData.getPageSize());
|
||||||
for (Object arc : pageData.getList()) {
|
for (ArticleModel arc : pageData.getList()) {
|
||||||
JSONObject jsonObject1 = JSONObject.fromObject(arc);
|
assertNotEquals(0, arc.getId().longValue());
|
||||||
assertNotEquals(0, jsonObject1.getInt("id"));
|
assertNotNull(arc.getTitle());
|
||||||
assertNotNull(jsonObject1.getString("title"));
|
assertNotNull(arc.getSummary());
|
||||||
assertNotNull(jsonObject1.getString("summary"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -342,28 +276,23 @@ public class ArticleControllerTest extends BaseTest {
|
|||||||
try {
|
try {
|
||||||
// 分类不存在
|
// 分类不存在
|
||||||
String tagName = "NoSuchTag";
|
String tagName = "NoSuchTag";
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
getMockData(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
||||||
.andExpect(status().is(200))
|
.andDo(result -> assertEquals(TAG_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(TAG_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// 正常查询
|
// 正常查询
|
||||||
tagName = "linux";
|
tagName = "linux";
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
getMockData(MockMvcRequestBuilders.get("/articles/tag/" + tagName + "?page=1&count=10"))
|
||||||
.andExpect(status().is(200))
|
|
||||||
.andDo(result -> {
|
.andDo(result -> {
|
||||||
JSONObject jsonObject = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<PageData<ArticleModel>> response = getResponse(result, ARTICLE_MODEL_PAGE_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), jsonObject.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
PageData<ArticleModel> pageData = (PageData<ArticleModel>) JSONObject.toBean(jsonObject.getJSONObject(Result), PageData.class);
|
PageData<ArticleModel> pageData = response.getResult();
|
||||||
assertNotEquals(0, pageData.getTotal());
|
assertNotEquals(0, pageData.getTotal());
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertEquals(10, pageData.getPageSize());
|
assertEquals(10, pageData.getPageSize());
|
||||||
|
|
||||||
for (Object arc : pageData.getList()) {
|
for (ArticleModel arc : pageData.getList()) {
|
||||||
JSONObject jsonObject1 = JSONObject.fromObject(arc);
|
assertNotEquals(0, arc.getId().longValue());
|
||||||
assertNotEquals(0, jsonObject1.getInt("id"));
|
assertNotNull(arc.getTitle());
|
||||||
assertNotNull(jsonObject1.getString("title"));
|
assertNotNull(arc.getSummary());
|
||||||
assertNotNull(jsonObject1.getString("summary"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -2,132 +2,77 @@ package cn.celess.blog.controller;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.Category;
|
import cn.celess.blog.entity.Category;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.CategoryModel;
|
import cn.celess.blog.entity.model.CategoryModel;
|
||||||
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.mapper.CategoryMapper;
|
import cn.celess.blog.mapper.CategoryMapper;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.UUID;
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
|
||||||
|
|
||||||
public class CategoryControllerTest extends BaseTest {
|
public class CategoryControllerTest extends BaseTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CategoryMapper categoryMapper;
|
CategoryMapper categoryMapper;
|
||||||
|
private static final TypeReference<?> CATEGORY_MODEL_TYPE = new TypeReference<Response<CategoryModel>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> CATEGORY_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<CategoryModel>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
String categoryName = randomStr(4);
|
String categoryName = randomStr(4);
|
||||||
System.out.println("categoryName: ==> " + categoryName);
|
getMockData(post("/admin/category/create?name=" + categoryName), adminLogin()).andDo(result -> {
|
||||||
// 未登录
|
Response<CategoryModel> response = getResponse(result, CATEGORY_MODEL_TYPE);
|
||||||
mockMvc.perform(post("/admin/category/create?name=" + categoryName)).andExpect(status().isOk())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.andDo(result -> {
|
CategoryModel category = response.getResult();
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
assertEquals(categoryName, category.getName());
|
||||||
});
|
assertNotNull(category.getId());
|
||||||
// User权限
|
assertNotEquals(0, category.getArticles());
|
||||||
String token = userLogin();
|
});
|
||||||
mockMvc.perform(post("/admin/category/create?name=" + categoryName)
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// Admin权限
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(post("/admin/category/create?name=" + categoryName)
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CategoryModel category = (CategoryModel) JSONObject.toBean(object.getJSONObject(Result), CategoryModel.class);
|
|
||||||
assertEquals(categoryName, category.getName());
|
|
||||||
assertNotNull(category.getId());
|
|
||||||
assertNotEquals(0, category.getArticles());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteOne() throws Exception {
|
public void deleteOne() throws Exception {
|
||||||
Category category = categoryMapper.getLastestCategory();
|
Category category = categoryMapper.getLastestCategory();
|
||||||
// 未登录
|
getMockData(delete("/admin/category/del?id=" + category.getId()), adminLogin()).andDo(result -> {
|
||||||
mockMvc.perform(delete("/admin/category/del?id=" + category.getId())).andExpect(status().isOk())
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
.andDo(result -> {
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
assertTrue(response.getResult());
|
||||||
});
|
});
|
||||||
// User权限
|
|
||||||
String token = userLogin();
|
|
||||||
mockMvc.perform(delete("/admin/category/del?id=" + category.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// Admin权限
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(delete("/admin/category/del?id=" + category.getId())
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
assertTrue(object.getBoolean(Result));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateOne() throws Exception {
|
public void updateOne() throws Exception {
|
||||||
Category category = categoryMapper.getLastestCategory();
|
Category category = categoryMapper.getLastestCategory();
|
||||||
String name = randomStr(4);
|
String name = randomStr(4);
|
||||||
// 未登录
|
getMockData(put("/admin/category/update?id=" + category.getId() + "&name=" + name), adminLogin()).andDo(result -> {
|
||||||
mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)).andExpect(status().isOk())
|
// Response<CategoryModel> response = mapper.readValue(result.getResponse().getContentAsString(), new ResponseType<Response<CategoryModel>>());
|
||||||
.andDo(result -> {
|
Response<CategoryModel> response = getResponse(result, CATEGORY_MODEL_TYPE);
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
});
|
CategoryModel c = response.getResult();
|
||||||
// User权限
|
assertEquals(name, c.getName());
|
||||||
String token = userLogin();
|
assertNotEquals(0, c.getArticles());
|
||||||
mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)
|
assertNotNull(c.getId());
|
||||||
.header("Authorization", token))
|
});
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
|
||||||
});
|
|
||||||
// Admin权限
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)
|
|
||||||
.header("Authorization", token))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CategoryModel c = (CategoryModel) JSONObject.toBean(object.getJSONObject(Result), CategoryModel.class);
|
|
||||||
assertEquals(name, c.getName());
|
|
||||||
assertNotEquals(0, c.getArticles());
|
|
||||||
assertNotNull(c.getId());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPage() throws Exception {
|
public void getPage() throws Exception {
|
||||||
mockMvc.perform(get("/categories")).andExpect(status().isOk())
|
getMockData(get("/categories")).andDo(result -> {
|
||||||
.andDo(result -> {
|
Response<PageData<CategoryModel>> response = getResponse(result, CATEGORY_MODEL_PAGE_TYPE);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertNotNull(response.getResult());
|
||||||
JSONArray jsonArray = object.getJSONObject(Result).getJSONArray("list");
|
response.getResult().getList().forEach(c -> {
|
||||||
assertNotNull(jsonArray);
|
assertNotNull(c.getName());
|
||||||
jsonArray.forEach(o -> {
|
assertNotNull(c.getId());
|
||||||
CategoryModel c = (CategoryModel) JSONObject.toBean(JSONObject.fromObject(o), CategoryModel.class);
|
assertNotEquals(0, c.getArticles());
|
||||||
assertNotNull(c.getName());
|
});
|
||||||
assertNotNull(c.getId());
|
});
|
||||||
assertNotEquals(0, c.getArticles());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,21 +3,22 @@ package cn.celess.blog.controller;
|
|||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.Article;
|
import cn.celess.blog.entity.Article;
|
||||||
import cn.celess.blog.entity.Comment;
|
import cn.celess.blog.entity.Comment;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.entity.model.CommentModel;
|
import cn.celess.blog.entity.model.CommentModel;
|
||||||
import cn.celess.blog.entity.request.CommentReq;
|
import cn.celess.blog.entity.request.CommentReq;
|
||||||
import cn.celess.blog.mapper.ArticleMapper;
|
import cn.celess.blog.mapper.ArticleMapper;
|
||||||
import cn.celess.blog.mapper.CommentMapper;
|
import cn.celess.blog.mapper.CommentMapper;
|
||||||
import cn.celess.blog.mapper.UserMapper;
|
import cn.celess.blog.mapper.UserMapper;
|
||||||
import net.sf.json.JSONObject;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.DATA_IS_DELETED;
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
public class CommentControllerTest extends BaseTest {
|
public class CommentControllerTest extends BaseTest {
|
||||||
@@ -27,46 +28,40 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
UserMapper userMapper;
|
UserMapper userMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
CommentMapper commentMapper;
|
CommentMapper commentMapper;
|
||||||
|
private static final TypeReference<?> COMMENT_MODEL_TYPE = new TypeReference<Response<CommentModel>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
Article article = articleMapper.getLastestArticle();
|
Article article = articleMapper.getLastestArticle();
|
||||||
CommentReq commentReq = new CommentReq();
|
CommentReq commentReq = new CommentReq();
|
||||||
commentReq.setPagePath("/article/" + article.getId());
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(randomStr());
|
||||||
commentReq.setPid(-1L);
|
List<User> all = userMapper.findAll();
|
||||||
commentReq.setToUserId(-1L);
|
commentReq.setPid(1L);
|
||||||
String token = userLogin();
|
commentReq.setToUserId(2l);
|
||||||
mockMvc.perform(post("/user/comment/create")
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", token)
|
CommentModel model = response.getResult();
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
||||||
assertEquals(-1, model.getPid().longValue());
|
assertEquals(1, model.getPid().longValue());
|
||||||
assertEquals(commentReq.getContent(), model.getContent());
|
assertEquals(commentReq.getContent(), model.getContent());
|
||||||
assertNotNull(model.getDate());
|
assertNotNull(model.getDate());
|
||||||
assertNotNull(model.getFromUser());
|
assertNotNull(model.getFromUser());
|
||||||
assertNull(model.getToUser());
|
assertNotNull(model.getToUser());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
commentReq.setPagePath("/article/" + article.getId());
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(randomStr());
|
||||||
commentReq.setPid(-1L);
|
commentReq.setPid(-1L);
|
||||||
commentReq.setToUserId(2);
|
commentReq.setToUserId(2);
|
||||||
mockMvc.perform(post("/user/comment/create")
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", token)
|
CommentModel model = response.getResult();
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
|
||||||
// 响应数据的完整性
|
// 响应数据的完整性
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
assertEquals(commentReq.getPid(), model.getPid().longValue());
|
||||||
@@ -79,20 +74,16 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 测试二级回复
|
// 测试二级回复
|
||||||
Comment lastestComment = commentMapper.getLastestComment();
|
Comment latestComment = commentMapper.getLastestComment();
|
||||||
commentReq.setPagePath("/article/" + article.getId());
|
commentReq.setPagePath("/article/" + article.getId());
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(randomStr());
|
||||||
commentReq.setPid(lastestComment.getId());
|
commentReq.setPid(latestComment.getId());
|
||||||
mockMvc.perform(post("/user/comment/create")
|
getMockData(post("/user/comment/create"), userLogin(), commentReq).andDo(result -> {
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", token)
|
CommentModel model = response.getResult();
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CommentModel model = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
|
||||||
// 重新获取父评论信息
|
// 重新获取父评论信息
|
||||||
Comment pCommon = commentMapper.findCommentById(lastestComment.getId());
|
Comment pCommon = commentMapper.findCommentById(latestComment.getId());
|
||||||
assertEquals(pCommon.getId(), model.getPid());
|
assertEquals(pCommon.getId(), model.getPid());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -116,16 +107,13 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
// 接口测试
|
// 接口测试
|
||||||
long id = comment.getId();
|
long id = comment.getId();
|
||||||
assertNotEquals(0, id);
|
assertNotEquals(0, id);
|
||||||
String token = userLogin();
|
getMockData(delete("/user/comment/del?id=" + id), userLogin()).andDo(result -> {
|
||||||
mockMvc.perform(delete("/user/comment/del?id=" + id).header("Authorization", token)).andDo(result -> {
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertTrue(response.getResult());
|
||||||
assertTrue(object.getBoolean(Result));
|
|
||||||
});
|
|
||||||
mockMvc.perform(delete("/user/comment/del?id=" + id).header("Authorization", token)).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(DATA_IS_DELETED.getCode(), object.getInt(Code));
|
|
||||||
});
|
});
|
||||||
|
getMockData(delete("/user/comment/del?id=" + id), userLogin())
|
||||||
|
.andDo(result -> assertEquals(DATA_IS_DELETED.getCode(), getResponse(result, COMMENT_MODEL_TYPE).getCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -133,16 +121,12 @@ public class CommentControllerTest extends BaseTest {
|
|||||||
Comment comment = commentMapper.getLastestComment();
|
Comment comment = commentMapper.getLastestComment();
|
||||||
CommentReq commentReq = new CommentReq();
|
CommentReq commentReq = new CommentReq();
|
||||||
commentReq.setId(comment.getId());
|
commentReq.setId(comment.getId());
|
||||||
commentReq.setContent(UUID.randomUUID().toString());
|
commentReq.setContent(randomStr());
|
||||||
// 不合法数据 setResponseId
|
// 不合法数据 setResponseId
|
||||||
mockMvc.perform(put("/user/comment/update")
|
getMockData(put("/user/comment/update"), userLogin(), commentReq).andDo(result -> {
|
||||||
.content(JSONObject.fromObject(commentReq).toString())
|
Response<CommentModel> response = getResponse(result, COMMENT_MODEL_TYPE);
|
||||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", userLogin())
|
CommentModel c = response.getResult();
|
||||||
).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
CommentModel c = (CommentModel) JSONObject.toBean(object.getJSONObject(Result), CommentModel.class);
|
|
||||||
assertEquals(commentReq.getContent(), c.getContent());
|
assertEquals(commentReq.getContent(), c.getContent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,262 +1,238 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.PartnerSite;
|
import cn.celess.blog.entity.PartnerSite;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.request.LinkApplyReq;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.request.LinkReq;
|
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||||
import cn.celess.blog.exception.MyException;
|
import cn.celess.blog.entity.request.LinkReq;
|
||||||
import cn.celess.blog.mapper.PartnerMapper;
|
import cn.celess.blog.exception.MyException;
|
||||||
import cn.celess.blog.service.MailService;
|
import cn.celess.blog.mapper.PartnerMapper;
|
||||||
import cn.celess.blog.service.PartnerSiteService;
|
import cn.celess.blog.service.PartnerSiteService;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import org.junit.Test;
|
||||||
import net.sf.json.JSONObject;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import java.util.List;
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import java.lang.reflect.Field;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import java.util.UUID;
|
|
||||||
|
@Slf4j
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
public class LinksControllerTest extends BaseTest {
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
@Autowired
|
||||||
|
PartnerMapper mapper;
|
||||||
@Slf4j
|
private static final TypeReference<?> LINK_MODEL_TYPE = new TypeReference<Response<PartnerSite>>() {
|
||||||
public class LinksControllerTest extends BaseTest {
|
};
|
||||||
|
private static final TypeReference<?> LINK_MODEL_LIST_TYPE = new TypeReference<Response<List<PartnerSite>>>() {
|
||||||
@Autowired
|
};
|
||||||
PartnerMapper mapper;
|
private static final TypeReference<?> LINK_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<PartnerSite>>>() {
|
||||||
@Autowired
|
};
|
||||||
PartnerSiteService partnerSiteService;
|
@Autowired
|
||||||
|
PartnerSiteService partnerSiteService;
|
||||||
|
|
||||||
@Test
|
|
||||||
public void create() throws Exception {
|
@Test
|
||||||
LinkReq linkReq = new LinkReq();
|
public void create() throws Exception {
|
||||||
linkReq.setName(UUID.randomUUID().toString().substring(0, 4));
|
LinkReq linkReq = new LinkReq();
|
||||||
linkReq.setOpen(false);
|
linkReq.setName(randomStr(4));
|
||||||
linkReq.setUrl("https://" + randomStr(4) + "celess.cn");
|
linkReq.setOpen(false);
|
||||||
String token = adminLogin();
|
linkReq.setUrl("https://" + randomStr(4) + "example.com");
|
||||||
mockMvc.perform(
|
getMockData(post("/admin/links/create"), adminLogin(), linkReq).andDo(result -> {
|
||||||
post("/admin/links/create")
|
Response<PartnerSite> response = getResponse(result, LINK_MODEL_TYPE);
|
||||||
.content(JSONObject.fromObject(linkReq).toString())
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.header("Authorization", token)
|
PartnerSite site = response.getResult();
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
assertNotNull(site.getId());
|
||||||
).andDo(result -> {
|
assertEquals(linkReq.getName(), site.getName());
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(linkReq.getUrl(), site.getUrl());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(linkReq.isOpen(), site.getOpen());
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(object.getJSONObject(Result), PartnerSite.class);
|
});
|
||||||
assertNotNull(site.getId());
|
|
||||||
assertEquals(linkReq.getName(), site.getName());
|
// https/http
|
||||||
assertEquals(linkReq.getUrl(), site.getUrl());
|
linkReq.setName(randomStr(4));
|
||||||
assertEquals(linkReq.isOpen(), site.getOpen());
|
linkReq.setOpen(false);
|
||||||
});
|
linkReq.setUrl(randomStr(4) + ".example.com");
|
||||||
|
getMockData(post("/admin/links/create"), adminLogin(), linkReq).andDo(result -> {
|
||||||
// https/http
|
Response<PartnerSite> response = getResponse(result, LINK_MODEL_TYPE);
|
||||||
linkReq.setName(UUID.randomUUID().toString().substring(0, 4));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
linkReq.setOpen(false);
|
PartnerSite site = response.getResult();
|
||||||
String url = randomStr(4) + ".celess.cn";
|
assertEquals("http://" + linkReq.getUrl(), site.getUrl());
|
||||||
linkReq.setUrl(url);
|
});
|
||||||
mockMvc.perform(
|
|
||||||
post("/admin/links/create")
|
// 测试已存在的数据
|
||||||
.content(JSONObject.fromObject(linkReq).toString())
|
getMockData(post("/admin/links/create"), adminLogin(), linkReq).andDo(result ->
|
||||||
.header("Authorization", token)
|
assertEquals(DATA_HAS_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode())
|
||||||
.contentType("application/json")
|
);
|
||||||
).andDo(result -> {
|
}
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
@Test
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(object.getJSONObject(Result), PartnerSite.class);
|
public void del() throws Exception {
|
||||||
assertEquals("http://" + url, site.getUrl());
|
PartnerSite partnerSite = new PartnerSite();
|
||||||
});
|
partnerSite.setName(randomStr(4));
|
||||||
|
partnerSite.setOpen(true);
|
||||||
// 测试已存在的数据
|
partnerSite.setDesc("");
|
||||||
mockMvc.perform(
|
partnerSite.setIconPath("");
|
||||||
post("/admin/links/create")
|
partnerSite.setUrl("https://" + randomStr(4) + ".celess.cn");
|
||||||
.content(JSONObject.fromObject(linkReq).toString())
|
mapper.insert(partnerSite);
|
||||||
.header("Authorization", token)
|
PartnerSite latest = mapper.getLastest();
|
||||||
.contentType("application/json")
|
assertNotNull(latest.getId());
|
||||||
).andDo(result -> assertEquals(DATA_HAS_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
getMockData(delete("/admin/links/del/" + latest.getId()), adminLogin()).andDo(result -> {
|
||||||
}
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
@Test
|
assertTrue(response.getResult());
|
||||||
public void del() throws Exception {
|
});
|
||||||
PartnerSite partnerSite = new PartnerSite();
|
long id = latest.getId();
|
||||||
partnerSite.setName(UUID.randomUUID().toString().substring(0, 4));
|
do {
|
||||||
partnerSite.setOpen(true);
|
id += 1;
|
||||||
partnerSite.setDesc("");
|
} while (mapper.existsById(id));
|
||||||
partnerSite.setIconPath("");
|
System.out.println("删除ID=" + id + "的数据");
|
||||||
partnerSite.setUrl("https://" + randomStr(4) + ".celess.cn");
|
getMockData(delete("/admin/links/del/" + id), adminLogin()).andDo(result ->
|
||||||
mapper.insert(partnerSite);
|
assertEquals(DATA_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode())
|
||||||
PartnerSite lastest = mapper.getLastest();
|
);
|
||||||
assertNotNull(lastest.getId());
|
}
|
||||||
String token = adminLogin();
|
|
||||||
mockMvc.perform(delete("/admin/links/del/" + lastest.getId()).header("Authorization", token)).andDo(result -> {
|
@Test
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
public void update() throws Exception {
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
// 增数据
|
||||||
assertTrue(object.getBoolean(Result));
|
PartnerSite partnerSite = new PartnerSite();
|
||||||
});
|
partnerSite.setName(randomStr(4));
|
||||||
long id = lastest.getId();
|
partnerSite.setOpen(true);
|
||||||
do {
|
partnerSite.setDesc("");
|
||||||
id += 1;
|
partnerSite.setIconPath("");
|
||||||
} while (mapper.existsById(id));
|
partnerSite.setDelete(false);
|
||||||
System.out.println("删除ID=" + id + "的数据");
|
partnerSite.setUrl("https://" + randomStr(5) + ".celess.cn");
|
||||||
mockMvc.perform(delete("/admin/links/del/" + id).header("Authorization", token)).andDo(result ->
|
mapper.insert(partnerSite);
|
||||||
assertEquals(DATA_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
// 查数据
|
||||||
);
|
PartnerSite latest = mapper.getLastest();
|
||||||
}
|
assertNotNull(latest.getId());
|
||||||
|
// 构建请求
|
||||||
@Test
|
LinkReq linkReq = new LinkReq();
|
||||||
public void update() throws Exception {
|
linkReq.setUrl(latest.getUrl());
|
||||||
// 增数据
|
linkReq.setOpen(!latest.getOpen());
|
||||||
PartnerSite partnerSite = new PartnerSite();
|
linkReq.setName(randomStr(4));
|
||||||
partnerSite.setName(UUID.randomUUID().toString().substring(0, 4));
|
linkReq.setId(latest.getId());
|
||||||
partnerSite.setOpen(true);
|
|
||||||
partnerSite.setDesc("");
|
getMockData(put("/admin/links/update"), adminLogin(), linkReq).andDo(result -> {
|
||||||
partnerSite.setIconPath("");
|
Response<PartnerSite> response = getResponse(result, LINK_MODEL_TYPE);
|
||||||
partnerSite.setDelete(false);
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
partnerSite.setUrl("https://" + randomStr(4) + ".celess.cn");
|
PartnerSite site = response.getResult();
|
||||||
mapper.insert(partnerSite);
|
assertNotNull(site.getId());
|
||||||
// 查数据
|
assertEquals(linkReq.getId(), site.getId().longValue());
|
||||||
PartnerSite lastest = mapper.getLastest();
|
assertEquals(linkReq.getUrl(), site.getUrl());
|
||||||
assertNotNull(lastest.getId());
|
assertEquals(linkReq.getName(), site.getName());
|
||||||
String token = adminLogin();
|
assertEquals(linkReq.isOpen(), site.getOpen());
|
||||||
// 构建请求
|
});
|
||||||
LinkReq linkReq = new LinkReq();
|
}
|
||||||
linkReq.setUrl(lastest.getUrl());
|
|
||||||
linkReq.setOpen(!lastest.getOpen());
|
@Test
|
||||||
linkReq.setName(UUID.randomUUID().toString().substring(0, 4));
|
public void allForOpen() throws Exception {
|
||||||
linkReq.setId(lastest.getId());
|
getMockData(get("/links")).andDo(result -> {
|
||||||
mockMvc.perform(
|
Response<List<PartnerSite>> response = getResponse(result, LINK_MODEL_LIST_TYPE);
|
||||||
put("/admin/links/update")
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
.content(JSONObject.fromObject(linkReq).toString())
|
response.getResult().forEach(site -> {
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
assertNotNull(site.getUrl());
|
||||||
.header("Authorization", token)
|
assertNull(site.getOpen());
|
||||||
).andDo(result -> {
|
assertNotNull(site.getName());
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
});
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
});
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(object.getJSONObject(Result), PartnerSite.class);
|
}
|
||||||
assertNotNull(site.getId());
|
|
||||||
assertEquals(linkReq.getId(), site.getId().longValue());
|
@Test
|
||||||
assertEquals(linkReq.getUrl(), site.getUrl());
|
public void all() throws Exception {
|
||||||
assertEquals(linkReq.getName(), site.getName());
|
getMockData(get("/admin/links?page=1&count=10"), adminLogin()).andDo(result -> {
|
||||||
assertEquals(linkReq.isOpen(), site.getOpen());
|
Response<PageData<PartnerSite>> response = getResponse(result, LINK_MODEL_PAGE_TYPE);
|
||||||
});
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
}
|
PageData<PartnerSite> pageData = response.getResult();
|
||||||
|
assertEquals(1, pageData.getPageNum());
|
||||||
@Test
|
assertEquals(10, pageData.getPageSize());
|
||||||
public void allForOpen() throws Exception {
|
for (PartnerSite site : pageData.getList()) {
|
||||||
mockMvc.perform(get("/links")).andDo(result -> {
|
assertNotNull(site.getUrl());
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertNotNull(site.getName());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertNotNull(site.getOpen());
|
||||||
object.getJSONArray(Result).forEach(o -> {
|
}
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(JSONObject.fromObject(o), PartnerSite.class);
|
});
|
||||||
assertNotNull(site.getUrl());
|
}
|
||||||
assertNull(site.getOpen());
|
|
||||||
assertNotNull(site.getName());
|
@Test
|
||||||
});
|
public void apply() {
|
||||||
});
|
// 做service 层的测试
|
||||||
}
|
// mockEmailServiceInstance(partnerSiteService, "mailService");
|
||||||
|
mockInjectInstance(partnerSiteService, "mailService", new TestMailServiceImpl());
|
||||||
@Test
|
LinkApplyReq req = new LinkApplyReq();
|
||||||
public void all() throws Exception {
|
req.setName(randomStr(4));
|
||||||
mockMvc.perform(get("/admin/links?page=1&count=10").header("Authorization", adminLogin())).andDo(result -> {
|
req.setUrl("https://" + randomStr(4) + ".celess.cn");
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
req.setIconPath("https://www.celess.cn/example.png");
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
req.setDesc("desc :" + randomStr());
|
||||||
PageData<PartnerSite> pageData = (PageData<PartnerSite>) JSONObject.toBean(object.getJSONObject(Result), PageData.class);
|
req.setEmail(randomStr(4) + "@celess.cn");
|
||||||
assertEquals(1, pageData.getPageNum());
|
req.setLinkUrl(req.getUrl() + "/links");
|
||||||
assertEquals(10, pageData.getPageSize());
|
try {
|
||||||
for (Object o : pageData.getList()) {
|
// 抓取不到数据的链接
|
||||||
PartnerSite site = (PartnerSite) JSONObject.toBean(JSONObject.fromObject(o), PartnerSite.class);
|
partnerSiteService.apply(req);
|
||||||
assertNotNull(site.getUrl());
|
} catch (MyException e) {
|
||||||
assertNotNull(site.getName());
|
log.debug("测试抓取不到数据");
|
||||||
assertNotNull(site.getOpen());
|
assertEquals(CANNOT_GET_DATA.getCode(), e.getCode());
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
req.setLinkUrl("https://bing.com");
|
||||||
|
req.setUrl(req.getLinkUrl());
|
||||||
// 手动测试
|
try {
|
||||||
@Test
|
partnerSiteService.apply(req);
|
||||||
public void apply() {
|
} catch (MyException e) {
|
||||||
// 做service 层的测试
|
log.debug("测试未添加本站链接的友链申请");
|
||||||
// mockEmailServiceInstance(partnerSiteService, "mailService");
|
assertEquals(APPLY_LINK_NO_ADD_THIS_SITE.getCode(), e.getCode());
|
||||||
mockInjectInstance(partnerSiteService, "mailService", new TestMailServiceImpl());
|
assertNotNull(e.getResult());
|
||||||
LinkApplyReq req = new LinkApplyReq();
|
try {
|
||||||
req.setName(randomStr(4));
|
// 测试uuid一致性
|
||||||
req.setUrl("https://" + randomStr(4) + ".celess.cn");
|
log.debug("测试uuid一致性");
|
||||||
req.setIconPath("https://www.celess.cn/example.png");
|
partnerSiteService.apply(req);
|
||||||
req.setDesc("desc :" + randomStr());
|
} catch (MyException e2) {
|
||||||
req.setEmail(randomStr(4) + "@celess.cn");
|
assertEquals(e.getResult(), e2.getResult());
|
||||||
req.setLinkUrl(req.getUrl() + "/links");
|
}
|
||||||
try {
|
}
|
||||||
// 抓取不到数据的链接
|
log.debug("测试正常申请");
|
||||||
partnerSiteService.apply(req);
|
req.setLinkUrl("https://www.celess.cn");
|
||||||
} catch (MyException e) {
|
req.setUrl(req.getLinkUrl());
|
||||||
log.debug("测试抓取不到数据");
|
PartnerSite apply = partnerSiteService.apply(req);
|
||||||
assertEquals(CANNOT_GET_DATA.getCode(), e.getCode());
|
assertNotNull(apply);
|
||||||
}
|
assertNotNull(apply.getId());
|
||||||
|
}
|
||||||
req.setLinkUrl("https://bing.com");
|
|
||||||
req.setUrl(req.getLinkUrl());
|
@Test
|
||||||
try {
|
public void reapply() {
|
||||||
partnerSiteService.apply(req);
|
//mockEmailServiceInstance(partnerSiteService, "mailService");
|
||||||
} catch (MyException e) {
|
try {
|
||||||
log.debug("测试未添加本站链接的友链申请");
|
partnerSiteService.reapply(randomStr());
|
||||||
assertEquals(APPLY_LINK_NO_ADD_THIS_SITE.getCode(), e.getCode());
|
throw new AssertionError();
|
||||||
assertNotNull(e.getResult());
|
} catch (MyException e) {
|
||||||
try {
|
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
||||||
// 测试uuid一致性
|
}
|
||||||
log.debug("测试uuid一致性");
|
|
||||||
partnerSiteService.apply(req);
|
LinkApplyReq req = new LinkApplyReq();
|
||||||
} catch (MyException e2) {
|
req.setName(randomStr(4));
|
||||||
assertEquals(e.getResult(), e2.getResult());
|
req.setIconPath("https://www.celess.cn/example.png");
|
||||||
}
|
req.setDesc("desc :" + randomStr());
|
||||||
}
|
req.setEmail(randomStr(4) + "@celess.cn");
|
||||||
log.debug("测试正常申请");
|
req.setLinkUrl("https://bing.com");
|
||||||
req.setLinkUrl("https://www.celess.cn");
|
req.setUrl(req.getLinkUrl());
|
||||||
req.setUrl(req.getLinkUrl());
|
String uuid;
|
||||||
PartnerSite apply = partnerSiteService.apply(req);
|
try {
|
||||||
assertNotNull(apply);
|
partnerSiteService.apply(req);
|
||||||
assertNotNull(apply.getId());
|
// err here
|
||||||
}
|
throw new AssertionError();
|
||||||
|
} catch (MyException e) {
|
||||||
@Test
|
uuid = (String) e.getResult();
|
||||||
public void reapply() {
|
String reapply = partnerSiteService.reapply(uuid);
|
||||||
//mockEmailServiceInstance(partnerSiteService, "mailService");
|
assertEquals(reapply, "success");
|
||||||
try {
|
}
|
||||||
partnerSiteService.reapply(randomStr());
|
|
||||||
throw new AssertionError();
|
try {
|
||||||
} catch (MyException e) {
|
partnerSiteService.reapply(uuid);
|
||||||
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
throw new AssertionError();
|
||||||
}
|
} catch (MyException e) {
|
||||||
|
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
||||||
LinkApplyReq req = new LinkApplyReq();
|
}
|
||||||
req.setName(randomStr(4));
|
}
|
||||||
req.setIconPath("https://www.celess.cn/example.png");
|
|
||||||
req.setDesc("desc :" + randomStr());
|
|
||||||
req.setEmail(randomStr(4) + "@celess.cn");
|
|
||||||
req.setLinkUrl("https://bing.com");
|
|
||||||
req.setUrl(req.getLinkUrl());
|
|
||||||
String uuid = null;
|
|
||||||
try {
|
|
||||||
partnerSiteService.apply(req);
|
|
||||||
// err here
|
|
||||||
throw new AssertionError();
|
|
||||||
} catch (MyException e) {
|
|
||||||
uuid = (String) e.getResult();
|
|
||||||
String reapply = partnerSiteService.reapply(uuid);
|
|
||||||
assertEquals(reapply, "success");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
partnerSiteService.reapply(uuid);
|
|
||||||
throw new AssertionError();
|
|
||||||
} catch (MyException e) {
|
|
||||||
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,42 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.Tag;
|
import cn.celess.blog.entity.Tag;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.TagModel;
|
import cn.celess.blog.entity.model.TagModel;
|
||||||
import cn.celess.blog.mapper.TagMapper;
|
import cn.celess.blog.mapper.TagMapper;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
|
||||||
|
|
||||||
public class TagControllerTest extends BaseTest {
|
public class TagControllerTest extends BaseTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
TagMapper tagMapper;
|
TagMapper tagMapper;
|
||||||
|
private static final TypeReference<?> TAG_MODEL_TYPE = new TypeReference<Response<TagModel>>() {
|
||||||
|
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> TAG_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<TagModel>>>() {
|
||||||
|
};
|
||||||
|
private static final TypeReference<?> TAG_NAC_LIST_TYPE = new TypeReference<Response<List<Map<String, Object>>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOne() throws Exception {
|
public void addOne() throws Exception {
|
||||||
String name = randomStr(4);
|
String name = randomStr(4);
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
getMockData(post("/admin/tag/create?name=" + name)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name).header("authorization", userLogin())).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
getMockData(post("/admin/tag/create?name=" + name), userLogin()).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
mockMvc.perform(post("/admin/tag/create?name=" + name).header("authorization", adminLogin())).andDo(result -> {
|
getMockData(post("/admin/tag/create?name=" + name), adminLogin()).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<TagModel> response = getResponse(result, TAG_MODEL_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONObject resJson = object.getJSONObject(Result);
|
TagModel tag = response.getResult();
|
||||||
TagModel tag = (TagModel) JSONObject.toBean(resJson, TagModel.class);
|
|
||||||
assertNotNull(tag.getId());
|
assertNotNull(tag.getId());
|
||||||
assertEquals(name, tag.getName());
|
assertEquals(name, tag.getName());
|
||||||
});
|
});
|
||||||
@@ -42,16 +48,14 @@ public class TagControllerTest extends BaseTest {
|
|||||||
public void delOne() throws Exception {
|
public void delOne() throws Exception {
|
||||||
Tag lastestTag = tagMapper.getLastestTag();
|
Tag lastestTag = tagMapper.getLastestTag();
|
||||||
assertNotNull(lastestTag.getId());
|
assertNotNull(lastestTag.getId());
|
||||||
String token = adminLogin();
|
getMockData(delete("/admin/tag/del?id=" + lastestTag.getId()), adminLogin()).andDo(result -> {
|
||||||
mockMvc.perform(delete("/admin/tag/del?id=" + lastestTag.getId()).header("Authorization", token)).andDo(result -> {
|
Response<Boolean> response = getResponse(result, BOOLEAN_TYPE);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertTrue(response.getResult());
|
||||||
assertTrue(object.getBoolean(Result));
|
|
||||||
});
|
});
|
||||||
long id = lastestTag.getId() * 2;
|
long id = lastestTag.getId() * 2;
|
||||||
mockMvc.perform(delete("/admin/tag/del?id=" + id).header("Authorization", token)).andDo(result ->
|
getMockData(delete("/admin/tag/del?id=" + id), adminLogin())
|
||||||
assertEquals(TAG_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
.andDo(result -> assertEquals(TAG_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,12 +63,12 @@ public class TagControllerTest extends BaseTest {
|
|||||||
public void updateOne() throws Exception {
|
public void updateOne() throws Exception {
|
||||||
Tag tag = tagMapper.getLastestTag();
|
Tag tag = tagMapper.getLastestTag();
|
||||||
assertNotNull(tag.getId());
|
assertNotNull(tag.getId());
|
||||||
String name = UUID.randomUUID().toString().substring(0, 4);
|
String name = randomStr(4);
|
||||||
mockMvc.perform(put("/admin/tag/update?id=" + tag.getId() + "&name=" + name).header("Authorization", adminLogin())).andDo(result -> {
|
getMockData(put("/admin/tag/update?id=" + tag.getId() + "&name=" + name), adminLogin()).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<TagModel> response = getResponse(result, TAG_MODEL_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(object.getJSONObject(Result));
|
assertNotNull(response.getResult());
|
||||||
TagModel t = (TagModel) JSONObject.toBean(object.getJSONObject(Result), TagModel.class);
|
TagModel t = response.getResult();
|
||||||
assertEquals(name, t.getName());
|
assertEquals(name, t.getName());
|
||||||
assertEquals(tag.getId(), t.getId());
|
assertEquals(tag.getId(), t.getId());
|
||||||
});
|
});
|
||||||
@@ -73,40 +77,33 @@ public class TagControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPage() throws Exception {
|
public void getPage() throws Exception {
|
||||||
mockMvc.perform(get("/tags?page=1&count=5"))
|
getMockData(get("/tags?page=1&count=5")).andDo(result -> {
|
||||||
.andExpect(status().is(200))
|
Response<PageData<TagModel>> response = getResponse(result, TAG_MODEL_PAGE_TYPE);
|
||||||
.andDo(result -> {
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONObject articlesJSON = JSONObject.fromObject(result.getResponse().getContentAsString());
|
// 结果集非空
|
||||||
// 断言获取数据成功
|
assertNotNull(response.getResult());
|
||||||
assertEquals(SUCCESS.getCode(), articlesJSON.getInt(Code));
|
// 判断pageInfo是否包装完全
|
||||||
// 结果集非空
|
PageData<TagModel> pageData = response.getResult();
|
||||||
assertNotNull(articlesJSON.getJSONObject(Result));
|
assertNotEquals(0, pageData.getTotal());
|
||||||
// 判断pageInfo是否包装完全
|
assertEquals(1, pageData.getPageNum());
|
||||||
JSONObject resultJson = JSONObject.fromObject(articlesJSON.getJSONObject(Result));
|
assertEquals(5, pageData.getPageSize());
|
||||||
PageData<TagModel> pageData = (PageData<TagModel>) JSONObject.toBean(resultJson, PageData.class);
|
// 内容完整
|
||||||
assertNotEquals(0, pageData.getTotal());
|
for (TagModel t : pageData.getList()) {
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertNotNull(t.getId());
|
||||||
assertEquals(5, pageData.getPageSize());
|
assertNotNull(t.getName());
|
||||||
// 内容完整
|
}
|
||||||
for (Object tag : pageData.getList()) {
|
});
|
||||||
TagModel t = (TagModel) JSONObject.toBean(JSONObject.fromObject(tag), TagModel.class);
|
|
||||||
assertNotNull(t.getId());
|
|
||||||
assertNotNull(t.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTagNameAndCount() throws Exception {
|
public void getTagNameAndCount() throws Exception {
|
||||||
mockMvc.perform(get("/tags/nac")).andDo(result -> {
|
getMockData(get("/tags/nac")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<List<Map<String, Object>>> response = getResponse(result, TAG_NAC_LIST_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONArray jsonArray = object.getJSONArray(Result);
|
assertNotNull(response.getResult());
|
||||||
assertNotNull(jsonArray);
|
response.getResult().forEach(o -> {
|
||||||
jsonArray.forEach(o -> {
|
assertNotNull(o.get("name"));
|
||||||
JSONObject json = JSONObject.fromObject(o);
|
assertNotNull(o.get("size"));
|
||||||
assertTrue(json.containsKey("size"));
|
|
||||||
assertTrue(json.containsKey("name"));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,282 +1,277 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.entity.User;
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.User;
|
||||||
import cn.celess.blog.entity.model.UserModel;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.request.LoginReq;
|
import cn.celess.blog.entity.model.UserModel;
|
||||||
import cn.celess.blog.entity.request.UserReq;
|
import cn.celess.blog.entity.request.LoginReq;
|
||||||
import cn.celess.blog.mapper.UserMapper;
|
import cn.celess.blog.entity.request.UserReq;
|
||||||
import cn.celess.blog.service.UserService;
|
import cn.celess.blog.mapper.UserMapper;
|
||||||
import cn.celess.blog.util.MD5Util;
|
import cn.celess.blog.service.UserService;
|
||||||
import net.sf.json.JSONArray;
|
import cn.celess.blog.util.MD5Util;
|
||||||
import net.sf.json.JSONObject;
|
import cn.celess.blog.util.RedisUtil;
|
||||||
import org.junit.Test;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.junit.Test;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import java.io.InputStream;
|
import org.springframework.util.MultiValueMap;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import static org.junit.Assert.*;
|
import java.util.ArrayList;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import java.util.List;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
public class UserControllerTest extends BaseTest {
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
@Autowired
|
|
||||||
UserMapper userMapper;
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
@Autowired
|
import static org.junit.Assert.*;
|
||||||
UserService userService;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
@Test
|
|
||||||
public void login() throws Exception {
|
public class UserControllerTest extends BaseTest {
|
||||||
assertNotNull(userLogin());
|
|
||||||
assertNotNull(adminLogin());
|
@Autowired
|
||||||
// 用户不存在
|
UserMapper userMapper;
|
||||||
LoginReq req = new LoginReq();
|
@Autowired
|
||||||
req.setEmail("zh@celess.cn");
|
|
||||||
req.setPassword("123456789");
|
RedisUtil redisUtil;
|
||||||
req.setIsRememberMe(false);
|
private static final TypeReference<?> USER_MODEL_TYPE = new TypeReference<Response<UserModel>>() {
|
||||||
JSONObject loginReq = JSONObject.fromObject(req);
|
};
|
||||||
mockMvc.perform(post("/login").content(loginReq.toString()).contentType("application/json"))
|
private static final TypeReference<?> USER_MODEL_PAGE_TYPE = new TypeReference<Response<PageData<UserModel>>>() {
|
||||||
.andDo(result ->
|
};
|
||||||
assertEquals(USER_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
private static final TypeReference<?> USER_MODEL_LIST_TYPE = new TypeReference<Response<List<Map<String, Object>>>>() {
|
||||||
);
|
};
|
||||||
}
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
@Test
|
|
||||||
public void registration() {
|
|
||||||
// ignore
|
@Test
|
||||||
}
|
public void login() throws Exception {
|
||||||
|
assertNotNull(userLogin());
|
||||||
@Test
|
assertNotNull(adminLogin());
|
||||||
public void logout() throws Exception {
|
// 用户不存在
|
||||||
mockMvc.perform(get("/logout")).andDo(result -> assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
LoginReq req = new LoginReq();
|
||||||
mockMvc.perform(get("/logout").header("Authorization", userLogin())).andDo(result -> assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
req.setEmail("zh@celess.cn");
|
||||||
}
|
req.setPassword("123456789");
|
||||||
|
req.setIsRememberMe(false);
|
||||||
@Test
|
getMockData(post("/login"), null, req).andDo(result -> assertEquals(USER_NOT_EXIST.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
public void updateInfo() throws Exception {
|
}
|
||||||
String desc = UUID.randomUUID().toString().substring(0, 4);
|
|
||||||
String disPlayName = UUID.randomUUID().toString().substring(0, 4);
|
@Test
|
||||||
mockMvc.perform(put("/user/userInfo/update?desc=" + desc + "&displayName=" + disPlayName).header("Authorization", userLogin()))
|
public void registration() {
|
||||||
.andDo(result -> {
|
// ignore
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
}
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
UserModel u = (UserModel) JSONObject.toBean(object.getJSONObject(Result), UserModel.class);
|
@Test
|
||||||
assertEquals(desc, u.getDesc());
|
public void logout() throws Exception {
|
||||||
assertEquals(disPlayName, u.getDisplayName());
|
getMockData(get("/logout")).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result, STRING_TYPE).getCode()));
|
||||||
assertNotNull(u.getId());
|
getMockData(get("/logout"), adminLogin()).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
public void updateInfo() throws Exception {
|
||||||
public void getUserInfo() throws Exception {
|
String desc = randomStr(4);
|
||||||
mockMvc.perform(get("/user/userInfo").header("Authorization", userLogin()))
|
String disPlayName = randomStr(4);
|
||||||
.andDo(result -> {
|
getMockData(put("/user/userInfo/update?desc=" + desc + "&displayName=" + disPlayName), userLogin()).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<UserModel> response = getResponse(result, USER_MODEL_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
UserModel u = (UserModel) JSONObject.toBean(object.getJSONObject(Result), UserModel.class);
|
UserModel u = response.getResult();
|
||||||
assertNotNull(u.getId());
|
assertEquals(desc, u.getDesc());
|
||||||
assertNotNull(u.getEmail());
|
assertEquals(disPlayName, u.getDisplayName());
|
||||||
assertNotNull(u.getDisplayName());
|
assertNotNull(u.getId());
|
||||||
assertNotNull(u.getEmailStatus());
|
});
|
||||||
assertNotNull(u.getAvatarImgUrl());
|
}
|
||||||
assertNotNull(u.getDesc());
|
|
||||||
assertNotNull(u.getRecentlyLandedDate());
|
@Test
|
||||||
assertNotNull(u.getRole());
|
public void getUserInfo() throws Exception {
|
||||||
});
|
getMockData(get("/user/userInfo"), adminLogin()).andDo(result -> {
|
||||||
}
|
Response<UserModel> response = getResponse(result, USER_MODEL_TYPE);
|
||||||
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
@Test
|
UserModel u = response.getResult();
|
||||||
public void upload() throws Exception {
|
assertNotNull(u.getId());
|
||||||
URL url = new URL("https://56462271.oss-cn-beijing.aliyuncs.com/web/logo.png");
|
assertNotNull(u.getEmail());
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
assertNotNull(u.getDisplayName());
|
||||||
connection.setRequestMethod("GET");
|
assertNotNull(u.getEmailStatus());
|
||||||
InputStream inputStream = connection.getInputStream();
|
assertNotNull(u.getAvatarImgUrl());
|
||||||
assertNotNull(inputStream);
|
assertNotNull(u.getDesc());
|
||||||
|
assertNotNull(u.getRecentlyLandedDate());
|
||||||
// mock 实现类
|
assertNotNull(u.getRole());
|
||||||
mockInjectInstance(userService, "qiniuService", new TestQiNiuServiceImpl());
|
});
|
||||||
|
}
|
||||||
MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, inputStream);
|
|
||||||
mockMvc.perform(multipart("/user/imgUpload").file(file)).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
@Test
|
||||||
mockMvc.perform(multipart("/user/imgUpload").file(file).header("Authorization", userLogin())).andDo(result -> {
|
public void upload() throws Exception {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
URL url = new URL("https://56462271.oss-cn-beijing.aliyuncs.com/web/logo.png");
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
assertNotNull(object.getString(Result));
|
connection.setRequestMethod("GET");
|
||||||
});
|
InputStream inputStream = connection.getInputStream();
|
||||||
}
|
assertNotNull(inputStream);
|
||||||
|
|
||||||
@Test
|
// mock 实现类
|
||||||
public void sendResetPwdEmail() {
|
mockInjectInstance(userService, "qiniuService", new TestQiNiuServiceImpl());
|
||||||
// ignore
|
|
||||||
}
|
MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, inputStream);
|
||||||
|
getMockData(multipart("/user/imgUpload").file(file), userLogin()).andDo(result -> {
|
||||||
@Test
|
Response<Object> response = getResponse(result, OBJECT_TYPE);
|
||||||
public void sendVerifyEmail() {
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
// ignore
|
assertNotNull(response.getResult());
|
||||||
}
|
});
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void emailVerify() {
|
@Test
|
||||||
// ignore
|
public void sendResetPwdEmail() {
|
||||||
}
|
// ignore
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void resetPwd() {
|
@Test
|
||||||
// ignore
|
public void sendVerifyEmail() {
|
||||||
}
|
// ignore
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void multipleDelete() throws Exception {
|
@Test
|
||||||
List<User> userList = new ArrayList<>();
|
public void emailVerify() throws Exception {
|
||||||
for (int i = 0; i < 10; i++) {
|
String email = randomStr(4) + "@celess.cn";
|
||||||
String s = UUID.randomUUID().toString();
|
String pwd = MD5Util.getMD5("123456789");
|
||||||
String email = s.substring(s.length() - 4) + "@celess.cn";
|
userMapper.addUser(new User(email, pwd));
|
||||||
String pwd = MD5Util.getMD5("123456789");
|
String verifyId = randomStr();
|
||||||
User user = new User(email, pwd);
|
LoginReq req = new LoginReq(email, "123456789", true);
|
||||||
int i1 = userMapper.addUser(user);
|
redisUtil.setEx(email + "-verify", verifyId, 2, TimeUnit.DAYS);
|
||||||
if (i1 == 0) {
|
getMockData(post("/emailVerify").param("verifyId", verifyId).param("email", email), login(req)).andDo(result ->
|
||||||
continue;
|
assertEquals(SUCCESS.getCode(), getResponse(result, OBJECT_TYPE).getCode())
|
||||||
}
|
);
|
||||||
userList.add(userMapper.findByEmail(email));
|
}
|
||||||
if (i == 9) {
|
|
||||||
//设置一个管理员
|
@Test
|
||||||
userMapper.setUserRole(userMapper.findByEmail(email).getId(), "admin");
|
public void resetPwd() throws Exception {
|
||||||
}
|
String email = randomStr(4) + "@celess.cn";
|
||||||
}
|
String pwd = MD5Util.getMD5("1234567890");
|
||||||
List<Long> idList = new ArrayList<>();
|
userMapper.addUser(new User(email, pwd));
|
||||||
userList.forEach(user -> idList.add(user.getId()));
|
LoginReq req = new LoginReq(email, "1234567890", true);
|
||||||
System.out.println("id :: == > " + idList.toString());
|
String verifyId = randomStr();
|
||||||
mockMvc.perform(delete("/admin/user/delete").content(idList.toString()).contentType("application/json"))
|
// 设置验证id
|
||||||
.andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
redisUtil.setEx(email + "-resetPwd", verifyId, 2, TimeUnit.DAYS);
|
||||||
mockMvc.perform(delete("/admin/user/delete").content(idList.toString()).contentType("application/json").header("Authorization", userLogin()))
|
MockHttpServletRequestBuilder resetPwd = post("/resetPwd").param("verifyId", verifyId).param("email", email).param("pwd", "123456789");
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
// 未验证
|
||||||
mockMvc.perform(delete("/admin/user/delete").content(idList.toString()).contentType("application/json").header("Authorization", adminLogin()))
|
getMockData(resetPwd, login(req)).andDo(result -> assertEquals(USEREMAIL_NOT_VERIFY.getCode(), getResponse(result, OBJECT_TYPE).getCode()));
|
||||||
.andDo(result -> {
|
// 设置未验证
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
userMapper.updateEmailStatus(email, true);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
// 正常
|
||||||
JSONArray jsonArray = object.getJSONArray(Result);
|
getMockData(resetPwd, login(req)).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result, OBJECT_TYPE).getCode()));
|
||||||
jsonArray.forEach(o -> {
|
}
|
||||||
JSONObject json = JSONObject.fromObject(o);
|
|
||||||
// 判断响应数据中是否包含输入的id
|
@Test
|
||||||
assertTrue(idList.contains((long) json.getInt("id")));
|
public void multipleDelete() throws Exception {
|
||||||
// 判断处理状态
|
List<User> userList = new ArrayList<>();
|
||||||
boolean status = json.getBoolean("status");
|
for (int i = 0; i < 10; i++) {
|
||||||
if (json.containsKey("msg"))
|
String s = randomStr();
|
||||||
assertFalse(status);
|
String email = s.substring(s.length() - 4) + "@celess.cn";
|
||||||
else
|
String pwd = MD5Util.getMD5("123456789");
|
||||||
assertTrue(status);
|
User user = new User(email, pwd);
|
||||||
});
|
int i1 = userMapper.addUser(user);
|
||||||
});
|
if (i1 == 0) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
userList.add(userMapper.findByEmail(email));
|
||||||
@Test
|
if (i == 9) {
|
||||||
public void updateInfoByAdmin() throws Exception {
|
//设置一个管理员
|
||||||
UserReq userReq = new UserReq();
|
userMapper.setUserRole(userMapper.findByEmail(email).getId(), "admin");
|
||||||
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
}
|
||||||
User user = new User(email, MD5Util.getMD5("123456789"));
|
}
|
||||||
userMapper.addUser(user);
|
List<Integer> idList = userList.stream().map(user -> user.getId().intValue()).collect(Collectors.toList());
|
||||||
User userByDb = userMapper.findByEmail(email);
|
getMockData(delete("/admin/user/delete"), adminLogin(), idList).andDo(result -> {
|
||||||
userReq.setId(userByDb.getId());
|
Response<List<Map<String, Object>>> response = getResponse(result, USER_MODEL_LIST_TYPE);
|
||||||
userReq.setPwd(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 10));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
userReq.setDesc(UUID.randomUUID().toString());
|
response.getResult().forEach(o -> {
|
||||||
userReq.setEmailStatus(new Random().nextBoolean());
|
// 判断响应数据中是否包含输入的id
|
||||||
userReq.setRole("admin");
|
assertTrue(idList.contains((int) o.get("id")));
|
||||||
userReq.setDisplayName(UUID.randomUUID().toString().substring(0, 4));
|
// 判断处理状态
|
||||||
userReq.setEmail(UUID.randomUUID().toString().substring(0, 5) + "@celess.cn");
|
boolean status = (boolean) o.get("status");
|
||||||
mockMvc.perform(put("/admin/user").contentType("application/json").content(JSONObject.fromObject(userReq).toString()))
|
if (o.containsKey("msg"))
|
||||||
.andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
assertFalse(status);
|
||||||
mockMvc.perform(put("/admin/user").contentType("application/json").header("Authorization", userLogin()).content(JSONObject.fromObject(userReq).toString()))
|
else
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
assertTrue(status);
|
||||||
mockMvc.perform(put("/admin/user").contentType("application/json").header("Authorization", adminLogin()).content(JSONObject.fromObject(userReq).toString()))
|
});
|
||||||
.andDo(result -> {
|
});
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
}
|
||||||
UserModel userModel = (UserModel) JSONObject.toBean(object.getJSONObject(Result), UserModel.class);
|
|
||||||
assertEquals(userReq.getId(), userModel.getId());
|
@Test
|
||||||
assertEquals(userReq.getRole(), userModel.getRole());
|
public void updateInfoByAdmin() throws Exception {
|
||||||
assertEquals(userReq.getEmail(), userModel.getEmail());
|
UserReq userReq = new UserReq();
|
||||||
assertEquals(userReq.getDesc(), userModel.getDesc());
|
String email = randomStr(4) + "@celess.cn";
|
||||||
assertEquals(userReq.getDisplayName(), userModel.getDisplayName());
|
User user = new User(email, MD5Util.getMD5("123456789"));
|
||||||
});
|
userMapper.addUser(user);
|
||||||
}
|
User userByDb = userMapper.findByEmail(email);
|
||||||
|
userReq.setId(userByDb.getId());
|
||||||
@Test
|
userReq.setPwd(randomStr().substring(0, 10));
|
||||||
public void getAllUser() throws Exception {
|
userReq.setDesc(randomStr());
|
||||||
mockMvc.perform(get("/admin/users?page=1&count=10"))
|
userReq.setEmailStatus(new Random().nextBoolean());
|
||||||
.andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
userReq.setRole("admin");
|
||||||
mockMvc.perform(get("/admin/users?page=1&count=10").header("authorization", userLogin()))
|
userReq.setDisplayName(randomStr(4));
|
||||||
.andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
userReq.setEmail(randomStr(5) + "@celess.cn");
|
||||||
mockMvc.perform(get("/admin/users?page=1&count=10").header("Authorization", adminLogin()))
|
getMockData(put("/admin/user"), adminLogin(), userReq).andDo(result -> {
|
||||||
.andDo(result -> {
|
Response<UserModel> response = getResponse(result, USER_MODEL_TYPE);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
UserModel userModel = response.getResult();
|
||||||
// 结果集非空
|
assertEquals(userReq.getId(), userModel.getId());
|
||||||
assertNotNull(object.getJSONObject(Result));
|
assertEquals(userReq.getRole(), userModel.getRole());
|
||||||
// 判断pageInfo是否包装完全
|
assertEquals(userReq.getEmail(), userModel.getEmail());
|
||||||
JSONObject resultJson = JSONObject.fromObject(object.getJSONObject(Result));
|
assertEquals(userReq.getDesc(), userModel.getDesc());
|
||||||
PageData<UserModel> pageData = (PageData<UserModel>) JSONObject.toBean(resultJson, PageData.class);
|
assertEquals(userReq.getDisplayName(), userModel.getDisplayName());
|
||||||
assertNotEquals(0, pageData.getTotal());
|
});
|
||||||
assertEquals(1, pageData.getPageNum());
|
}
|
||||||
assertEquals(10, pageData.getPageSize());
|
|
||||||
// 内容完整
|
@Test
|
||||||
for (Object user : pageData.getList()) {
|
public void getAllUser() throws Exception {
|
||||||
UserModel u = (UserModel) JSONObject.toBean(JSONObject.fromObject(user), UserModel.class);
|
getMockData(get("/admin/users?page=1&count=10"), adminLogin()).andDo(result -> {
|
||||||
assertNotNull(u.getId());
|
Response<PageData<UserModel>> response = getResponse(result, USER_MODEL_PAGE_TYPE);
|
||||||
assertNotNull(u.getEmail());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(u.getRole());
|
// 结果集非空
|
||||||
assertNotNull(u.getEmailStatus());
|
assertNotNull(response.getResult());
|
||||||
assertNotNull(u.getDisplayName());
|
// 判断pageInfo是否包装完全
|
||||||
}
|
PageData<UserModel> pageData = response.getResult();
|
||||||
});
|
assertNotEquals(0, pageData.getTotal());
|
||||||
}
|
assertEquals(1, pageData.getPageNum());
|
||||||
|
assertEquals(10, pageData.getPageSize());
|
||||||
@Test
|
// 内容完整
|
||||||
public void getEmailStatus() throws Exception {
|
for (UserModel u : pageData.getList()) {
|
||||||
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
assertNotNull(u.getId());
|
||||||
mockMvc.perform(get("/emailStatus/" + email)).andDo(result -> {
|
assertNotNull(u.getEmail());
|
||||||
String content = result.getResponse().getContentAsString();
|
assertNotNull(u.getRole());
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(content).getInt(Code));
|
assertNotNull(u.getEmailStatus());
|
||||||
assertFalse(JSONObject.fromObject(content).getBoolean(Result));
|
assertNotNull(u.getDisplayName());
|
||||||
});
|
}
|
||||||
email = "a@celess.cn";
|
});
|
||||||
mockMvc.perform(get("/emailStatus/" + email)).andDo(result -> {
|
}
|
||||||
String content = result.getResponse().getContentAsString();
|
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(content).getInt(Code));
|
@Test
|
||||||
assertTrue(JSONObject.fromObject(content).getBoolean(Result));
|
public void getEmailStatus() throws Exception {
|
||||||
});
|
String email = randomStr(4) + "@celess.cn";
|
||||||
}
|
getMockData(get("/emailStatus/" + email)).andDo(result -> assertFalse((Boolean) getResponse(result, BOOLEAN_TYPE).getResult()));
|
||||||
|
getMockData(get("/emailStatus/" + ADMIN_EMAIL)).andDo(result -> assertTrue((Boolean) getResponse(result, BOOLEAN_TYPE).getResult()));
|
||||||
@Test
|
}
|
||||||
public void setPwd() throws Exception {
|
|
||||||
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
@Test
|
||||||
assertEquals(1, userMapper.addUser(new User(email, MD5Util.getMD5("1234567890"))));
|
public void setPwd() throws Exception {
|
||||||
LoginReq req = new LoginReq();
|
String email = randomStr(4) + "@celess.cn";
|
||||||
req.setEmail(email);
|
assertEquals(1, userMapper.addUser(new User(email, MD5Util.getMD5("1234567890"))));
|
||||||
req.setPassword("1234567890");
|
LoginReq req = new LoginReq(email, "1234567890", false);
|
||||||
req.setIsRememberMe(false);
|
String token = login(req);
|
||||||
JSONObject loginReq = JSONObject.fromObject(req);
|
assertNotNull(token);
|
||||||
String contentAsString = mockMvc.perform(post("/login").content(loginReq.toString()).contentType("application/json")).andReturn().getResponse().getContentAsString();
|
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
|
||||||
assertNotNull(contentAsString);
|
param.add("pwd", "1234567890");
|
||||||
String token = JSONObject.fromObject(contentAsString).getJSONObject(Result).getString("token");
|
param.add("newPwd", "aaabbbccc");
|
||||||
assertNotNull(token);
|
param.add("confirmPwd", "aaabbbccc");
|
||||||
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
|
getMockData(post("/user/setPwd").params(param), token).andDo(result -> {
|
||||||
param.add("pwd", "1234567890");
|
assertEquals(SUCCESS.getCode(), getResponse(result).getCode());
|
||||||
param.add("newPwd", "aaabbbccc");
|
assertEquals(MD5Util.getMD5("aaabbbccc"), userMapper.getPwd(email));
|
||||||
param.add("confirmPwd", "aaabbbccc");
|
});
|
||||||
mockMvc.perform(post("/user/setPwd").header("Authorization", token).params(param)).andDo(result -> {
|
}
|
||||||
String content = result.getResponse().getContentAsString();
|
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(content).getInt(Code));
|
|
||||||
assertEquals(MD5Util.getMD5("aaabbbccc"), userMapper.getPwd(email));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,29 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.VisitorModel;
|
import cn.celess.blog.entity.model.VisitorModel;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import net.sf.json.JSONObject;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
|
||||||
|
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
|
||||||
public class VisitorControllerTest extends BaseTest {
|
public class VisitorControllerTest extends BaseTest {
|
||||||
|
private final TypeReference<?> VISITOR_PAGE_TYPE = new TypeReference<Response<PageData<VisitorModel>>>() {
|
||||||
|
};
|
||||||
|
private final TypeReference<?> VISITOR_TYPE = new TypeReference<Response<VisitorModel>>() {
|
||||||
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getVisitorCount() throws Exception {
|
public void getVisitorCount() throws Exception {
|
||||||
mockMvc.perform(get("/visitor/count")).andDo(result -> {
|
getMockData(get("/visitor/count")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<Object> response = getResponse(result);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertTrue(object.containsKey(Result));
|
assertNotNull(response.getResult());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,29 +31,26 @@ public class VisitorControllerTest extends BaseTest {
|
|||||||
public void page() throws Exception {
|
public void page() throws Exception {
|
||||||
int count = 10;
|
int count = 10;
|
||||||
int page = 1;
|
int page = 1;
|
||||||
mockMvc.perform(get("/admin/visitor/page?count=" + count + "&page=" + page).header("Authorization", adminLogin()))
|
getMockData(get("/admin/visitor/page?count=" + count + "&page=" + page), adminLogin()).andDo(result -> {
|
||||||
.andDo(result -> {
|
Response<PageData<VisitorModel>> response = getResponse(result, VISITOR_PAGE_TYPE);
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
PageData<VisitorModel> pageData = response.getResult();
|
||||||
JSONObject resultJson = JSONObject.fromObject(object.getJSONObject(Result));
|
assertNotEquals(0, pageData.getTotal());
|
||||||
PageData<VisitorModel> pageData = (PageData<VisitorModel>) JSONObject.toBean(resultJson, PageData.class);
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertNotEquals(0, pageData.getTotal());
|
assertEquals(10, pageData.getPageSize());
|
||||||
assertEquals(1, pageData.getPageNum());
|
for (VisitorModel v : pageData.getList()) {
|
||||||
assertEquals(10, pageData.getPageSize());
|
assertNotEquals(0, v.getId());
|
||||||
for (Object ver : pageData.getList()) {
|
assertNotNull(v.getDate());
|
||||||
VisitorModel v = (VisitorModel) JSONObject.toBean(JSONObject.fromObject(ver), VisitorModel.class);
|
}
|
||||||
assertNotEquals(0, v.getId());
|
});
|
||||||
assertNotNull(v.getDate());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void add() throws Exception {
|
public void add() throws Exception {
|
||||||
mockMvc.perform(post("/visit")).andDo(MockMvcResultHandlers.print()).andDo(result -> {
|
getMockData(post("/visit")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<VisitorModel> response = getResponse(result, VISITOR_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
VisitorModel visitorModel = (VisitorModel) JSONObject.toBean(object.getJSONObject(Result), VisitorModel.class);
|
VisitorModel visitorModel = response.getResult();
|
||||||
assertNotEquals(0, visitorModel.getId());
|
assertNotEquals(0, visitorModel.getId());
|
||||||
assertNotNull(visitorModel.getIp());
|
assertNotNull(visitorModel.getIp());
|
||||||
});
|
});
|
||||||
@@ -57,26 +58,26 @@ public class VisitorControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dayVisitCount() throws Exception {
|
public void dayVisitCount() throws Exception {
|
||||||
mockMvc.perform(get("/dayVisitCount")).andDo(MockMvcResultHandlers.print()).andDo(result ->
|
getMockData(get("/dayVisitCount")).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手动测试
|
// 手动测试
|
||||||
// @Test
|
// @Test
|
||||||
public void ipLocation() throws Exception {
|
public void ipLocation() throws Exception {
|
||||||
String ip = "127.0.0.1";
|
String ip = "127.0.0.1";
|
||||||
mockMvc.perform(get("/ip/" + ip)).andDo(MockMvcResultHandlers.print()).andDo(result -> {
|
getMockData(get("/ip/" + ip)).andDo(result -> {
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
Response<Object> response = getResponse(result);
|
||||||
assertTrue(JSONObject.fromObject(result.getResponse().getContentAsString()).containsKey(Result));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getIp() throws Exception {
|
public void getIp() throws Exception {
|
||||||
mockMvc.perform(get("/ip")).andDo(MockMvcResultHandlers.print()).andDo(result -> {
|
getMockData(get("/ip")).andDo(result -> {
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
Response<String> response = getResponse(result, STRING_TYPE);
|
||||||
assertEquals("127.0.0.1", JSONObject.fromObject(result.getResponse().getContentAsString()).getString(Result));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertEquals("127.0.0.1", response.getResult());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,35 +1,46 @@
|
|||||||
package cn.celess.blog.controller;
|
package cn.celess.blog.controller;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.Response;
|
||||||
import cn.celess.blog.entity.WebUpdate;
|
import cn.celess.blog.entity.WebUpdate;
|
||||||
import cn.celess.blog.entity.model.PageData;
|
import cn.celess.blog.entity.model.PageData;
|
||||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||||
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
import cn.celess.blog.mapper.WebUpdateInfoMapper;
|
||||||
import net.sf.json.JSONArray;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import net.sf.json.JSONObject;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import static cn.celess.blog.enmu.ResponseEnum.DATA_NOT_EXIST;
|
||||||
|
import static cn.celess.blog.enmu.ResponseEnum.SUCCESS;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class WebUpdateInfoControllerTest extends BaseTest {
|
public class WebUpdateInfoControllerTest extends BaseTest {
|
||||||
|
|
||||||
|
private final TypeReference<?> MODAL_TYPE = new TypeReference<Response<WebUpdateModel>>() {
|
||||||
|
};
|
||||||
|
private final TypeReference<?> MODAL_LIST_TYPE = new TypeReference<Response<List<WebUpdateModel>>>() {
|
||||||
|
};
|
||||||
|
private final TypeReference<?> MODAL_PAGE_TYPE = new TypeReference<Response<PageData<WebUpdateModel>>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WebUpdateInfoMapper mapper;
|
WebUpdateInfoMapper mapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() throws Exception {
|
public void create() throws Exception {
|
||||||
String info = UUID.randomUUID().toString();
|
String info = randomStr();
|
||||||
mockMvc.perform(post("/admin/webUpdate/create?info=" + info).header("Authorization", adminLogin())).andDo(result -> {
|
getMockData(post("/admin/webUpdate/create?info=" + info), adminLogin()).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<WebUpdateModel> response = getResponse(result, MODAL_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertTrue(object.containsKey(Result));
|
assertNotNull(response.getResult());
|
||||||
WebUpdateModel webUpdateModel = (WebUpdateModel) JSONObject.toBean(object.getJSONObject(Result), WebUpdateModel.class);
|
WebUpdateModel webUpdateModel = response.getResult();
|
||||||
assertEquals(info, webUpdateModel.getInfo());
|
assertEquals(info, webUpdateModel.getInfo());
|
||||||
assertNotNull(webUpdateModel.getTime());
|
assertNotNull(webUpdateModel.getTime());
|
||||||
assertNotEquals(0, webUpdateModel.getId());
|
assertNotEquals(0, webUpdateModel.getId());
|
||||||
@@ -40,7 +51,7 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
public void del() throws Exception {
|
public void del() throws Exception {
|
||||||
// 新增数据
|
// 新增数据
|
||||||
WebUpdate webUpdate = new WebUpdate();
|
WebUpdate webUpdate = new WebUpdate();
|
||||||
webUpdate.setUpdateInfo(UUID.randomUUID().toString());
|
webUpdate.setUpdateInfo(randomStr());
|
||||||
webUpdate.setUpdateTime(new Date());
|
webUpdate.setUpdateTime(new Date());
|
||||||
mapper.insert(webUpdate);
|
mapper.insert(webUpdate);
|
||||||
// 接口测试
|
// 接口测试
|
||||||
@@ -49,32 +60,31 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
assertNotEquals(0, update.getId());
|
assertNotEquals(0, update.getId());
|
||||||
|
|
||||||
long id = update.getId();
|
long id = update.getId();
|
||||||
mockMvc.perform(delete("/admin/webUpdate/del/" + id).header("Authorization", adminLogin())).andDo(result -> {
|
getMockData(delete("/admin/webUpdate/del/" + id), adminLogin()).andDo(result -> {
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code));
|
Response<Object> response = getResponse(result);
|
||||||
assertTrue(JSONObject.fromObject(result.getResponse().getContentAsString()).getBoolean(Result));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
|
assertNotNull(response.getResult());
|
||||||
});
|
});
|
||||||
do {
|
do {
|
||||||
id += 2;
|
id += 2;
|
||||||
} while (mapper.existsById(id));
|
} while (mapper.existsById(id));
|
||||||
System.out.println("准备删除ID=" + id + "的不存在记录");
|
log.debug("准备删除ID={}的不存在记录", id);
|
||||||
mockMvc.perform(delete("/admin/webUpdate/del/" + id).header("Authorization", adminLogin())).andDo(result ->
|
getMockData(delete("/admin/webUpdate/del/" + id), adminLogin()).andDo(result -> assertEquals(DATA_NOT_EXIST.getCode(), getResponse(result).getCode()));
|
||||||
assertEquals(DATA_NOT_EXIST.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void update() throws Exception {
|
public void update() throws Exception {
|
||||||
// 新增数据
|
// 新增数据
|
||||||
WebUpdate webUpdate = new WebUpdate();
|
WebUpdate webUpdate = new WebUpdate();
|
||||||
webUpdate.setUpdateInfo(UUID.randomUUID().toString());
|
webUpdate.setUpdateInfo(randomStr());
|
||||||
webUpdate.setUpdateTime(new Date());
|
webUpdate.setUpdateTime(new Date());
|
||||||
mapper.insert(webUpdate);
|
mapper.insert(webUpdate);
|
||||||
List<WebUpdate> all = mapper.findAll();
|
List<WebUpdate> all = mapper.findAll();
|
||||||
WebUpdate update = all.get(all.size() - 1);
|
WebUpdate update = all.get(all.size() - 1);
|
||||||
assertNotEquals(0, update.getId());
|
assertNotEquals(0, update.getId());
|
||||||
assertNotNull(update.getUpdateInfo());
|
assertNotNull(update.getUpdateInfo());
|
||||||
String info = UUID.randomUUID().toString();
|
String info = randomStr();
|
||||||
mockMvc.perform(put("/admin/webUpdate/update?id=" + update.getId() + "&info=" + info).header("Authorization", adminLogin())).andDo(result -> {
|
getMockData(put("/admin/webUpdate/update?id=" + update.getId() + "&info=" + info), adminLogin()).andDo(result -> {
|
||||||
List<WebUpdate> list = mapper.findAll();
|
List<WebUpdate> list = mapper.findAll();
|
||||||
WebUpdate up = list.get(list.size() - 1);
|
WebUpdate up = list.get(list.size() - 1);
|
||||||
assertEquals(update.getId(), up.getId());
|
assertEquals(update.getId(), up.getId());
|
||||||
@@ -85,12 +95,12 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findAll() throws Exception {
|
public void findAll() throws Exception {
|
||||||
mockMvc.perform(get("/webUpdate")).andDo(result -> {
|
getMockData(get("/webUpdate")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<List<WebUpdateModel>> response = getResponse(result, MODAL_LIST_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
JSONArray jsonArray = object.getJSONArray(Result);
|
assertNotNull(response.getResult());
|
||||||
jsonArray.forEach(o -> {
|
assertNotEquals(0, response.getResult());
|
||||||
WebUpdateModel webUpdate = (WebUpdateModel) JSONObject.toBean(JSONObject.fromObject(o), WebUpdateModel.class);
|
response.getResult().forEach(webUpdate -> {
|
||||||
assertNotEquals(0, webUpdate.getId());
|
assertNotEquals(0, webUpdate.getId());
|
||||||
assertNotNull(webUpdate.getTime());
|
assertNotNull(webUpdate.getTime());
|
||||||
assertNotNull(webUpdate.getInfo());
|
assertNotNull(webUpdate.getInfo());
|
||||||
@@ -100,15 +110,14 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void page() throws Exception {
|
public void page() throws Exception {
|
||||||
mockMvc.perform(get("/webUpdate/pages?page=1&count=10")).andDo(result -> {
|
getMockData(get("/webUpdate/pages?page=1&count=10")).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<PageData<WebUpdateModel>> response = getResponse(result, MODAL_PAGE_TYPE);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(object.getJSONObject(Result));
|
assertNotNull(response.getResult());
|
||||||
PageData<WebUpdateModel> pageData = (PageData<WebUpdateModel>) JSONObject.toBean(object.getJSONObject(Result), PageData.class);
|
PageData<WebUpdateModel> pageData = response.getResult();
|
||||||
assertEquals(1, pageData.getPageNum());
|
assertEquals(1, pageData.getPageNum());
|
||||||
assertEquals(10, pageData.getPageSize());
|
assertEquals(10, pageData.getPageSize());
|
||||||
for (Object o : pageData.getList()) {
|
for (WebUpdateModel model : pageData.getList()) {
|
||||||
WebUpdateModel model = (WebUpdateModel) JSONObject.toBean(JSONObject.fromObject(o), WebUpdateModel.class);
|
|
||||||
assertNotEquals(0, model.getId());
|
assertNotEquals(0, model.getId());
|
||||||
assertNotNull(model.getTime());
|
assertNotNull(model.getTime());
|
||||||
assertNotNull(model.getInfo());
|
assertNotNull(model.getInfo());
|
||||||
@@ -118,7 +127,6 @@ public class WebUpdateInfoControllerTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lastestUpdateTime() throws Exception {
|
public void lastestUpdateTime() throws Exception {
|
||||||
mockMvc.perform(get("/lastestUpdate")).andDo(result ->
|
getMockData(get("/lastestUpdate")).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package cn.celess.blog.filter;
|
package cn.celess.blog.filter;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import net.sf.json.JSONObject;
|
import cn.celess.blog.entity.Response;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static cn.celess.blog.enmu.ResponseEnum.*;
|
import static cn.celess.blog.enmu.ResponseEnum.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
@@ -17,60 +17,37 @@ public class AuthorizationFilter extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void UserAccess() throws Exception {
|
public void UserAccess() throws Exception {
|
||||||
String token = "";
|
|
||||||
// 未登录
|
// 未登录
|
||||||
mockMvc.perform(get("/user/userInfo").header("Authorization", token)).andDo(result -> {
|
getMockData(get("/user/userInfo")).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result).getCode()));
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
// user权限登录
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
getMockData(get("/user/userInfo"), userLogin()).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
});
|
|
||||||
token = userLogin();
|
|
||||||
mockMvc.perform(get("/user/userInfo").header("Authorization", token)).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void AdminAccess() throws Exception {
|
public void AdminAccess() throws Exception {
|
||||||
String token = "";
|
|
||||||
// 未登录
|
// 未登录
|
||||||
mockMvc.perform(get("/admin/articles?page=1&count=1").header("Authorization", token)).andDo(result -> {
|
getMockData(get("/admin/articles?page=1&count=1")).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result).getCode()));
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
// user权限
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
getMockData(get("/admin/articles?page=1&count=1"), userLogin()).andDo(result -> assertEquals(PERMISSION_ERROR.getCode(), getResponse(result).getCode()));
|
||||||
});
|
// admin 权限
|
||||||
token = userLogin();
|
getMockData(get("/admin/articles?page=1&count=1"), adminLogin()).andDo(result -> assertEquals(SUCCESS.getCode(), getResponse(result).getCode()));
|
||||||
mockMvc.perform(get("/admin/articles?page=1&count=1").header("Authorization", token)).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(PERMISSION_ERROR.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
token = adminLogin();
|
|
||||||
mockMvc.perform(get("/admin/articles?page=1&count=1").header("Authorization", token)).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void VisitorAccess() throws Exception {
|
public void VisitorAccess() throws Exception {
|
||||||
mockMvc.perform(get("/user/userInfo")).andDo(result -> {
|
getMockData(get("/user/userInfo")).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result).getCode()));
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
getMockData(get("/admin/articles?page=1&count=1")).andDo(result -> assertEquals(HAVE_NOT_LOG_IN.getCode(), getResponse(result).getCode()));
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
mockMvc.perform(get("/admin/articles?page=1&count=1")).andDo(result -> {
|
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
|
||||||
assertEquals(HAVE_NOT_LOG_IN.getCode(), object.getInt(Code));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void authorizationTest() throws Exception {
|
public void authorizationTest() throws Exception {
|
||||||
// 测试response中有无Authorization字段
|
// 测试response中有无Authorization字段
|
||||||
String s = userLogin();
|
String token = userLogin();
|
||||||
mockMvc.perform(get("/user/userInfo").header("Authorization", s)).andDo(result -> {
|
getMockData(get("/user/userInfo"), token).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<Object> response = getResponse(result);
|
||||||
assertEquals(SUCCESS.getCode(), object.getInt(Code));
|
assertEquals(SUCCESS.getCode(), response.getCode());
|
||||||
assertNotNull(result.getResponse().getHeader("Authorization"));
|
assertNotNull(result.getResponse().getHeader("Authorization"));
|
||||||
assertNotEquals(s, result.getResponse().getHeader("Authorization"));
|
assertNotEquals(token, result.getResponse().getHeader("Authorization"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,11 @@ package cn.celess.blog.filter;
|
|||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
import cn.celess.blog.enmu.ResponseEnum;
|
||||||
import net.sf.json.JSONObject;
|
import cn.celess.blog.entity.Response;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
|
||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 小海
|
* @Author: 小海
|
||||||
@@ -31,11 +26,11 @@ public class MultipleSubmitFilter extends BaseTest {
|
|||||||
|
|
||||||
|
|
||||||
private void sendRequest(ResponseEnum expectResponse, String... msg) throws Exception {
|
private void sendRequest(ResponseEnum expectResponse, String... msg) throws Exception {
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/counts").session(session)).andDo(result -> {
|
getMockData(MockMvcRequestBuilders.get("/counts").session(session)).andDo(result -> {
|
||||||
JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString());
|
Response<Object> response = getResponse(result);
|
||||||
Assert.assertEquals(expectResponse.getCode(), object.getInt(Code));
|
Assert.assertEquals(expectResponse.getCode(), response.getCode());
|
||||||
if (msg.length != 0) {
|
if (msg.length != 0) {
|
||||||
Assert.assertEquals(msg[0], object.getString("msg"));
|
Assert.assertEquals(msg[0], response.getMsg());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.junit.Test;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ public class ArticleMapperTest extends BaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void update() {
|
public void update() {
|
||||||
Article article = generateArticle().getArticle();
|
Article article = generateArticle().getArticle();
|
||||||
String randomText = UUID.randomUUID().toString();
|
String randomText = randomStr();
|
||||||
|
|
||||||
// 此字段不会通过insert被写入数据库而是使用插入数据的默认值 数据库中该字段默认为true
|
// 此字段不会通过insert被写入数据库而是使用插入数据的默认值 数据库中该字段默认为true
|
||||||
article.setOpen(true);
|
article.setOpen(true);
|
||||||
@@ -117,7 +116,7 @@ public class ArticleMapperTest extends BaseTest {
|
|||||||
public void existsByTitle() {
|
public void existsByTitle() {
|
||||||
Article article = generateArticle().getArticle();
|
Article article = generateArticle().getArticle();
|
||||||
assertTrue(articleMapper.existsByTitle(article.getTitle()));
|
assertTrue(articleMapper.existsByTitle(article.getTitle()));
|
||||||
assertFalse(articleMapper.existsByTitle(UUID.randomUUID().toString()));
|
assertFalse(articleMapper.existsByTitle(randomStr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -196,7 +195,7 @@ public class ArticleMapperTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ArticleTag generateArticle() {
|
private ArticleTag generateArticle() {
|
||||||
String randomText = UUID.randomUUID().toString();
|
String randomText = randomStr();
|
||||||
|
|
||||||
Article article = new Article();
|
Article article = new Article();
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import cn.celess.blog.entity.*;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -111,7 +109,7 @@ public class ArticleTagMapperTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ArticleTag generateArticle() {
|
private ArticleTag generateArticle() {
|
||||||
String randomText = UUID.randomUUID().toString();
|
String randomText = randomStr();
|
||||||
|
|
||||||
Article article = new Article();
|
Article article = new Article();
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import cn.celess.blog.entity.Category;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
public class VisitorMapperTest extends BaseTest {
|
public class VisitorMapperTest extends BaseTest {
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
public class DateFormatUtilTest extends BaseTest {
|
public class DateFormatUtilTest extends BaseTest {
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
package cn.celess.blog.util;
|
package cn.celess.blog.util;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import cn.celess.blog.enmu.ResponseEnum;
|
|
||||||
import cn.celess.blog.entity.Response;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Map;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class HttpUtilTest extends BaseTest {
|
public class HttpUtilTest extends BaseTest {
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package cn.celess.blog.util;
|
|||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class MD5UtilTest extends BaseTest {
|
public class MD5UtilTest extends BaseTest {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user