代码初始化提交。
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
package com.jero;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.jero.common.util.security.SecurityTools;
|
||||
import com.jero.common.util.security.entity.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SecurityToolsTest {
|
||||
@Test
|
||||
public void Test(){
|
||||
MyKeyPair mkeyPair = SecurityTools.generateKeyPair();
|
||||
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("name", "党政辉");
|
||||
msg.put("age", 50);
|
||||
JSONObject identity = new JSONObject();
|
||||
identity.put("type", "01");
|
||||
identity.put("no", "210882165896524512");
|
||||
msg.put("identity", identity);
|
||||
|
||||
// 签名加密部分
|
||||
SecuritySignReq signReq = new SecuritySignReq();
|
||||
// data为要加密的报文字符串
|
||||
signReq.setData(msg.toString());
|
||||
// 为rsa私钥
|
||||
signReq.setPrikey(mkeyPair.getPriKey());
|
||||
// 调用签名方法
|
||||
SecuritySignResp sign = SecurityTools.sign(signReq);
|
||||
// 打印出来加密数据
|
||||
// signData为签名数据
|
||||
// data为aes加密数据
|
||||
// asekey为ras加密过的aeskey
|
||||
System.out.println(new JSONObject(sign).toStringPretty());
|
||||
|
||||
// 验签解密部分
|
||||
SecurityReq req = new SecurityReq();
|
||||
//对方传过来的数据一一对应
|
||||
req.setAesKey(sign.getAesKey());
|
||||
req.setData(sign.getData());
|
||||
req.setSignData(sign.getSignData());
|
||||
//我们的公钥
|
||||
req.setPubKey(mkeyPair.getPubKey());
|
||||
//验签方法调用
|
||||
SecurityResp securityResp = SecurityTools.valid(req);
|
||||
//解密报文data为解密报文
|
||||
//sucess 为验签成功失败标志 true代码验签成功,false代表失败
|
||||
System.out.println(new JSONObject(securityResp).toStringPretty());
|
||||
}
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
package com.jero.modules.online.desform.test;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.JeroSystemSingleApplication;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.common.util.RestUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* 表单设计器 API 接口单元测试
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeroSystemSingleApplication.class)
|
||||
@SuppressWarnings({"FieldCanBeLocal", "SpringJavaAutowiredMembersInspection"})
|
||||
public class DesformApiTest {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 测试地址:实际使用时替换成你自己的地址
|
||||
*/
|
||||
private final String BASE_URL = "http://localhost:8080/jero-boot/desform/api/";
|
||||
|
||||
// 请实际使用时替换成你自己的用户名和密码
|
||||
private final String USERNAME = "admin";
|
||||
private final String PASSWORD = "123456";
|
||||
|
||||
/**
|
||||
* 表单code,实际使用时可以替换成你要测试的表单code
|
||||
*/
|
||||
private final String DESFORM_CODE = "qingjiadan";
|
||||
|
||||
/**
|
||||
* 测试用例:新增
|
||||
*/
|
||||
@Test
|
||||
public void testAdd() {
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + DESFORM_CODE;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 POST 代表提交新增数据
|
||||
HttpMethod method = HttpMethod.POST;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("name", "张三");
|
||||
params.put("sex", "1");
|
||||
params.put("begin_time", "2019-12-27");
|
||||
params.put("remarks", "生病了");
|
||||
|
||||
System.out.println("请求参数:" + params.toJSONString());
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试用例:修改
|
||||
*/
|
||||
@Test
|
||||
public void testEdit() {
|
||||
// 数据Id
|
||||
String dataId = "f43ea15c654337fbcb2336dd5422ffc3";
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + DESFORM_CODE + "/" + dataId;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 PUT 代表提交修改数据
|
||||
HttpMethod method = HttpMethod.PUT;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("name", "李四");
|
||||
params.put("sex", "0");
|
||||
params.put("begin_time", "2019-12-27");
|
||||
params.put("remarks", "感冒了");
|
||||
|
||||
System.out.println("请求参数:" + params.toJSONString());
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试用例:删除
|
||||
*/
|
||||
@Test
|
||||
public void testDelete() {
|
||||
// 数据Id
|
||||
String dataId = "f43ea15c654337fbcb2336dd5422ffc3";
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + DESFORM_CODE + "/" + dataId;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 DELETE 代表删除数据
|
||||
HttpMethod method = HttpMethod.DELETE;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试用例:查询记录
|
||||
*/
|
||||
@Test
|
||||
public void testQuery() {
|
||||
// 数据Id
|
||||
String dataId = "18146ddaa062296442a9310a51baf67b";
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + DESFORM_CODE + "/" + dataId;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 GET 代表获取数据
|
||||
HttpMethod method = HttpMethod.GET;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
private String getToken() {
|
||||
String token = JwtUtil.sign(USERNAME, PASSWORD);
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60);
|
||||
return token;
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders(String token) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
String mediaType = MediaType.APPLICATION_JSON_UTF8_VALUE;
|
||||
headers.setContentType(MediaType.parseMediaType(mediaType));
|
||||
headers.set("Accept", mediaType);
|
||||
headers.set("X-Access-Token", token);
|
||||
return headers;
|
||||
}
|
||||
|
||||
}
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
package com.jero.modules.online.desform.test;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.JeroSystemSingleApplication;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.common.util.RestUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* online api online表单单元测试
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeroSystemSingleApplication.class)
|
||||
@SuppressWarnings({"FieldCanBeLocal", "SpringJavaAutowiredMembersInspection"})
|
||||
public class OnlineApiTest {
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 测试地址:实际使用时替换成你自己的地址
|
||||
*/
|
||||
private final String BASE_URL = "http://localhost:8080/jero-boot/online/cgform/api/";
|
||||
|
||||
// 请实际使用时替换成你自己的用户名和密码
|
||||
private final String USERNAME = "admin";
|
||||
private final String PASSWORD = "123456";
|
||||
|
||||
/**
|
||||
* online表单code,实际使用时可以替换成你要测试的表单code
|
||||
* (测试表test_demo)
|
||||
*/
|
||||
private final String ONLINE_CODE = "d35109c3632c4952a19ecc094943dd71";
|
||||
|
||||
/**
|
||||
* 测试用例:新增
|
||||
*/
|
||||
@Test
|
||||
public void testAdd() {
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + "form/" + ONLINE_CODE;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 POST 代表提交新增数据
|
||||
HttpMethod method = HttpMethod.POST;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("name", "张三");
|
||||
params.put("sex", "1");
|
||||
params.put("age",15);
|
||||
params.put("descc", "<p>富文本编辑</p>");
|
||||
|
||||
System.out.println("请求参数:" + params.toJSONString());
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试用例:修改
|
||||
*/
|
||||
@Test
|
||||
public void testEdit() {
|
||||
// dataId
|
||||
String dataId = "1331797913880883201";
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + "form/" + ONLINE_CODE;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 PUT 代表提交修改数据
|
||||
HttpMethod method = HttpMethod.PUT;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("id", dataId);
|
||||
params.put("name", "张三");
|
||||
params.put("sex", "1");
|
||||
params.put("age",30);
|
||||
params.put("descc", "<p>富文本编辑,重新编辑</p>");
|
||||
|
||||
System.out.println("请求参数:" + params.toJSONString());
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试用例:删除
|
||||
*/
|
||||
@Test
|
||||
public void testDelete() {
|
||||
// 数据id
|
||||
String dataId = "1331797913880883201";
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + "form/" + ONLINE_CODE + "/" + dataId;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 DELETE 代表删除数据
|
||||
HttpMethod method = HttpMethod.DELETE;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试用例:查询记录
|
||||
*/
|
||||
@Test
|
||||
public void testQuery() {
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + "getData/"+ ONLINE_CODE ;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 GET 代表获取数据
|
||||
HttpMethod method = HttpMethod.GET;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
private String getToken() {
|
||||
String token = JwtUtil.sign(USERNAME, PASSWORD);
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60);
|
||||
return token;
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders(String token) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
String mediaType = MediaType.APPLICATION_JSON_UTF8_VALUE;
|
||||
headers.setContentType(MediaType.parseMediaType(mediaType));
|
||||
headers.set("Accept", mediaType);
|
||||
headers.set("X-Access-Token", token);
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.jero.modules.standard.domestic;
|
||||
|
||||
import com.jero.JeroSystemSingleApplication;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/9/14 17:14
|
||||
* @Description:
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeroSystemSingleApplication.class)
|
||||
public class StandardTest {
|
||||
//
|
||||
// @Autowired
|
||||
// private ILawsDomesticStandardService lawsDomesticStandardService;
|
||||
// @Autowired
|
||||
// private AsmsPostUtil asmsPostUtil;
|
||||
//
|
||||
// @Test
|
||||
// public void getByIdTest() {
|
||||
// LawsDomesticStandard byId = lawsDomesticStandardService.getById("86a75ae628c9485ca002b56551606684");
|
||||
// System.out.println(byId);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAsmsPost() {
|
||||
// asmsPostUtil.sendGetReq("/countriesregions/list", null);
|
||||
// }
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.jero.modules.standard.enterprise;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import com.jero.JeroSystemSingleApplication;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/9/7 15:36
|
||||
*/
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeroSystemSingleApplication.class)
|
||||
public class LawsEnterpriseStandardTest {
|
||||
|
||||
// @Resource
|
||||
// private ILawsEnterpriseStandardService ILawsEnterpriseStandardService;
|
||||
//
|
||||
// @Resource
|
||||
// private EnterpriseStandardRmrEvaluateDetailService enterpriseStandardRmrEvaluateDetailService;
|
||||
//
|
||||
// @Resource
|
||||
// private EnterpriseStandardPlanService enterpriseStandardPlanService;
|
||||
//
|
||||
// private static final Faker faker = new Faker();
|
||||
// private static final Random random = new Random();
|
||||
//
|
||||
// public static LawsEnterpriseStandard generateRandomEnterpriseStandard() {
|
||||
// LawsEnterpriseStandard lawsEnterpriseStandard = new LawsEnterpriseStandard();
|
||||
//
|
||||
// //lawsEnterpriseStandard.setDelFlag(faker.bool().bool() ? 1 : 0);
|
||||
// lawsEnterpriseStandard.setStandardCode(faker.code().ean13());
|
||||
// lawsEnterpriseStandard.setNameCode(faker.code().asin());
|
||||
// lawsEnterpriseStandard.setCategoryCode(faker.commerce().department());
|
||||
// lawsEnterpriseStandard.setYearNumber(String.valueOf(faker.number().numberBetween(1990, 2023)));
|
||||
// lawsEnterpriseStandard.setStandardCategory(faker.commerce().department());
|
||||
// lawsEnterpriseStandard.setGradeClassification(faker.book().genre());
|
||||
// lawsEnterpriseStandard.setCompIllustration(faker.lorem().sentence());
|
||||
// //lawsEnterpriseStandard.setTryFlag(faker.bool().bool() ? 1 : 0);
|
||||
// lawsEnterpriseStandard.setTrialPeriod(String.valueOf(faker.number().numberBetween(1, 12)) + " months");
|
||||
// lawsEnterpriseStandard.setMainDraftingUser(faker.name().fullName());
|
||||
// lawsEnterpriseStandard.setMainDraftingUnit(faker.company().name());
|
||||
// lawsEnterpriseStandard.setMainDraftingUnitResponsiblePerson(faker.name().fullName());
|
||||
// lawsEnterpriseStandard.setCooperationUnit(faker.company().name());
|
||||
// lawsEnterpriseStandard.setPartName(faker.lorem().word());
|
||||
//
|
||||
// // ... continue with more fields as needed
|
||||
//
|
||||
// lawsEnterpriseStandard.setStandardNumber(faker.code().ean8());
|
||||
// lawsEnterpriseStandard.setStandardName(faker.commerce().productName());
|
||||
// lawsEnterpriseStandard.setStandardEnglishName(faker.commerce().productName());
|
||||
// lawsEnterpriseStandard.setReleaseDate(faker.date().past(1, TimeUnit.SECONDS));
|
||||
// lawsEnterpriseStandard.setImplementationDate(faker.date().past(1, TimeUnit.SECONDS));
|
||||
// //lawsEnterpriseStandard.setStandardState(faker.random().nextInt(5));
|
||||
//
|
||||
// return lawsEnterpriseStandard;
|
||||
// }
|
||||
//
|
||||
// public static EnterpriseStandardPlan generateRandomEnterpriseStandardPlan() {
|
||||
// EnterpriseStandardPlan enterpriseStandardPlan = new EnterpriseStandardPlan();
|
||||
//
|
||||
// //enterpriseStandardPlan.setDelFlag(faker.bool().bool() ? 1 : 0);
|
||||
// enterpriseStandardPlan.setMainDraftingUser(faker.name().fullName());
|
||||
// enterpriseStandardPlan.setMainDraftingUnit(faker.company().name());
|
||||
// enterpriseStandardPlan.setMainDraftingUnitResponsiblePerson(faker.name().fullName());
|
||||
//
|
||||
//
|
||||
// // ... continue with more fields as needed
|
||||
//
|
||||
// enterpriseStandardPlan.setReleaseDate(faker.date().past(1, TimeUnit.SECONDS));
|
||||
//
|
||||
// return enterpriseStandardPlan;
|
||||
// }
|
||||
// @Test
|
||||
// public void insertRandomES() {
|
||||
// LawsEnterpriseStandard randomData = generateRandomEnterpriseStandard();
|
||||
// ILawsEnterpriseStandardService.save(randomData);
|
||||
// System.out.println(randomData);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void insertRandomESRmrDetail() {
|
||||
// for (int i = 0; i < 6; i++) {
|
||||
// EnterpriseStandardRmrEvaluateDetail random = new EnterpriseStandardRmrEvaluateDetail();
|
||||
// random.setEvaluateItem(String.valueOf(i + 1));
|
||||
// random.setDeductionScoreReason("无");
|
||||
// enterpriseStandardRmrEvaluateDetailService.save(random);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void insertRandomESP() {
|
||||
// for (int i = 0; i < 1; i++) {
|
||||
// EnterpriseStandardPlan random = generateRandomEnterpriseStandardPlan();
|
||||
// enterpriseStandardPlanService.save(random);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
package com.jero.modules.system.test;
|
||||
|
||||
import com.jero.JeroSystemSingleApplication;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.common.util.RestUtil;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
/**
|
||||
* 系统用户单元测试
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeroSystemSingleApplication.class)
|
||||
@SuppressWarnings({"FieldCanBeLocal", "SpringJavaAutowiredMembersInspection"})
|
||||
public class SysUserTest {
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 测试地址:实际使用时替换成你自己的地址
|
||||
*/
|
||||
private final String BASE_URL = "http://localhost:8080/jero-boot/sys/user/";
|
||||
|
||||
// 请实际使用时替换成你自己的用户名和密码
|
||||
private final String USERNAME = "admin";
|
||||
private final String PASSWORD = "123456";
|
||||
|
||||
/**
|
||||
* 测试用例:新增
|
||||
*/
|
||||
@Test
|
||||
public void testAdd() {
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + "add" ;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 POST 代表提交新增数据
|
||||
HttpMethod method = HttpMethod.POST;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("username", "wangwuTest");
|
||||
params.put("password", "123456");
|
||||
params.put("confirmpassword","123456");
|
||||
params.put("realname", "单元测试");
|
||||
params.put("activitiSync", "1");
|
||||
params.put("userIdentity","1");
|
||||
|
||||
System.out.println("请求参数:" + params.toJSONString());
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试用例:修改
|
||||
*/
|
||||
@Test
|
||||
public void testEdit() {
|
||||
// 数据Id
|
||||
String dataId = "1331795062924374018";
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + "edit";
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 PUT 代表提交修改数据
|
||||
HttpMethod method = HttpMethod.PUT;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("username", "wangwuTest");
|
||||
params.put("realname", "单元测试1111");
|
||||
params.put("activitiSync", "1");
|
||||
params.put("userIdentity","1");
|
||||
params.put("id",dataId);
|
||||
|
||||
System.out.println("请求参数:" + params.toJSONString());
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试用例:删除
|
||||
*/
|
||||
@Test
|
||||
public void testDelete() {
|
||||
// 数据Id
|
||||
String dataId = "1331795062924374018";
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + "delete" + "?id=" + dataId;
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 DELETE 代表删除数据
|
||||
HttpMethod method = HttpMethod.DELETE;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试用例:查询记录
|
||||
*/
|
||||
@Test
|
||||
public void testQuery() {
|
||||
// 用户Token
|
||||
String token = this.getToken();
|
||||
// 请求地址
|
||||
String url = BASE_URL + "list";
|
||||
// 请求 Header (用于传递Token)
|
||||
HttpHeaders headers = this.getHeaders(token);
|
||||
// 请求方式是 GET 代表获取数据
|
||||
HttpMethod method = HttpMethod.GET;
|
||||
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("请求方式:" + method);
|
||||
System.out.println("请求Token:" + token);
|
||||
|
||||
// 利用 RestUtil 请求该url
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
|
||||
if (result != null && result.getBody() != null) {
|
||||
System.out.println("返回结果:" + result.getBody().toJSONString());
|
||||
} else {
|
||||
System.out.println("查询失败");
|
||||
}
|
||||
}
|
||||
|
||||
private String getToken() {
|
||||
String token = JwtUtil.sign(USERNAME, PASSWORD);
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60);
|
||||
return token;
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders(String token) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
String mediaType = MediaType.APPLICATION_JSON_UTF8_VALUE;
|
||||
headers.setContentType(MediaType.parseMediaType(mediaType));
|
||||
headers.set("Accept", mediaType);
|
||||
headers.set("X-Access-Token", token);
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user