Commit b87d6a78 authored by 龚小红's avatar 龚小红

Merge branch 'feature/20211020-xmc' into 'master'

Feature/20211020 xmc-企业后台-框架版本

See merge request test-group/kejiji!143
parents 871deaf4 c8539426
package com.kjj.bean.corp;
import lombok.Data;
@Data
public class Auth {
private String authName;
private Long id;
private int totalCount;
}
package com.kjj.bean.corp;
import lombok.Data;
@Data
public class Corp {
private Integer companyEnable;
private String companyName;
private long id;
}
package com.kjj.bean.corp;
import lombok.Data;
@Data
public class Page {
private long authId;
private int hideState;
private long id;
private String pageName;
}
package com.kjj.bean.corp;
import lombok.Data;
@Data
public class Staff {
private long authId;
private long id;
private int staffEnable;
private String staffName;
private String staffPhone;
}
package com.kjj.cases.live.Corp;
import com.kjj.bean.corp.Auth;
import com.kjj.bean.corp.Corp;
import com.kjj.bean.corp.Page;
import com.kjj.bean.corp.Staff;
import com.kjj.cases.admin.Authorization;
import com.kjj.config.BasicConfig;
import com.kjj.utils.BaseUtils;
import com.kjj.utils.JsonUtil;
import com.kjj.utils.ThreadSleepUtils;
import io.restassured.response.Response;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.*;
public class ManageCorp implements Authorization {
private static final String initCompanyName = "自动化企业";
private static String companyName;
private static String companyNameOfTimeStamp;
public static long companyId;
private static final String authName = "权限等级1";
public static long authId;
private static List<Long> authToDelete = new ArrayList<>();
private static final String pageUrl = "https://kjj-mng.duibatest.com.cn/#/enterprise/list";
private static long pageId;
private static final String pageName = "自动化页面1";
private static final String staffName = "自动化员工";
private static final String staffPhone = "13700000000";
public static long staffId;
@BeforeClass
public void setUp(){
BaseUtils.ssoLogin();
}
// 企业管理
@Test(description = "新建企业", priority = 1)
public void 新建企业() {
Map<String, Object> saveCorpPar = new HashMap<>();
saveCorpPar.put("companyName", initCompanyName);
Response saveCorpRes = network.postResponse(saveCorpPar, BasicConfig.MANAGER_corp_saveCorp);
try {
boolean data = saveCorpRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(saveCorpPar, BasicConfig.MANAGER_corp_saveCorp, "新建企业失败", saveCorpRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(saveCorpPar, BasicConfig.MANAGER_corp_saveCorp,"获取数据失败", saveCorpRes.body().asString()));
}
}
@Test(description = "查询企业列表", priority = 2)
public void 查询企业列表() {
Response selectCorpListRes = network.getResponse(BasicConfig.MANAGER_corp_CorpLists);
try {
List<Corp> corpLists = JsonUtil.parseResponseToPageBean(selectCorpListRes, Corp.class);
Corp newCorp = corpLists.get(0);
Assert.assertEquals(newCorp.getCompanyName(), initCompanyName, network.message(BasicConfig.MANAGER_corp_CorpLists, "企业列表首行企业名称与实际添加不符", selectCorpListRes.body().asString()));
// 校验通过获取companyId
companyId = newCorp.getId();
}catch (Exception e){
e.printStackTrace();
Assert.fail(network.message(BasicConfig.MANAGER_corp_CorpLists, "获取数据失败", selectCorpListRes.body().asString()));
}
}
@Test(description = "编辑企业信息", priority = 3)
public void 编辑企业信息() {
/**
* 以时间戳的不同来使公司名称不重复
*/
// 给companyNameOfTimeStamp变量赋值
getCurrentTimeStamp();
companyName = "自动化企业" + companyNameOfTimeStamp;
Map<String, Object> editCorpPar = new HashMap<>();
editCorpPar.put("companyName", companyName);
editCorpPar.put("id", companyId);
Response editCorpRes = network.postResponse(editCorpPar, BasicConfig.MANAGER_corp_saveCorp);
try {
boolean data = editCorpRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(editCorpPar, BasicConfig.MANAGER_corp_saveCorp, "编辑企业信息失败", editCorpRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(editCorpPar, BasicConfig.MANAGER_corp_saveCorp, "获取数据失败", editCorpRes.body().asString()));
}
}
@Test(description = "按照名称搜索企业", priority = 4)
public void 按照名称搜索企业() {
// sleep 2秒
// 等待企业信息的变更生效
ThreadSleepUtils.sleep(2000);
Map<String, Object> searchCorpPar = new HashMap<>();
searchCorpPar.put("companyName", companyNameOfTimeStamp);
Response searchCorpRes = network.getResponse(searchCorpPar, BasicConfig.MANAGER_corp_searchCorp);
try {
List<Map<String, Object>> searchResults = searchCorpRes.jsonPath().getList("data");
if (searchResults.size() != 1){
Assert.fail(network.message(searchCorpPar, BasicConfig.MANAGER_corp_searchCorp, "搜索结果数量错误", searchCorpRes.body().asString()));
}
Map<String, Object> searchResult = searchResults.get(0);
System.out.println(searchResult);
Assert.assertEquals(searchResult.get("id"), (int)companyId, network.message(searchCorpPar, BasicConfig.MANAGER_corp_searchCorp, "搜索结果错误", searchCorpRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(searchCorpPar, BasicConfig.MANAGER_corp_searchCorp, "获取数据失败", searchCorpRes.body().asString()));
}
}
// 权限管理
@Test(description = "新增权限等级", priority = 6)
public void 新增权限等级(){
Map<String, Object> saveAuthPar = new HashMap<>();
saveAuthPar.put("companyId", companyId);
saveAuthPar.put("authName", "权限等级");
Response saveAuthRes = network.postResponse(saveAuthPar, BasicConfig.MANAGER_corp_saveAuth);
try {
boolean data = saveAuthRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(saveAuthPar, BasicConfig.MANAGER_corp_saveAuth, "新增权限等级失败", saveAuthRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(saveAuthPar, BasicConfig.MANAGER_corp_saveAuth, "获取数据失败", saveAuthRes.body().asString()));
}
}
@Test(description = "查询权限列表", priority = 7)
public void 查询权限列表() {
Map<String, Object> authListsPar = new HashMap<>();
authListsPar.put("companyId", companyId);
Response authListsRes = network.getResponse(authListsPar, BasicConfig.MANAGER_corp_authLists);
try {
List<Auth> authLists = JsonUtil.parseResponseToListBean(authListsRes, Auth.class);
Auth newAuth = authLists.get(authLists.size()-1);
Assert.assertEquals(newAuth.getAuthName(), "权限等级", network.message(authListsPar, BasicConfig.MANAGER_corp_authLists, "列表最新权限等级名称与实际添加不符", authListsRes.body().asString()));
authId = newAuth.getId();
// 将默认的三个权限等级ID添加进列表
for (Auth authLists1 : authLists){
if (authLists1.getId() != authId){
authToDelete.add(authLists1.getId());
}
}
}catch (Exception e){
e.printStackTrace();
Assert.fail(network.message(authListsPar, BasicConfig.MANAGER_corp_authLists, "获取数据失败", authListsRes.body().asString()));
}
}
@Test(description = "删除权限等级", priority = 8)
public void 删除权限等级() {
Map<String, Object> delAuthPar = new HashMap<>();
Response delAuthRes;
for (long id : authToDelete){
delAuthPar.clear();
delAuthPar.put("id", id);
delAuthRes = network.postResponse(delAuthPar, BasicConfig.MANAGER_corp_deleteAuthById);
try {
boolean data = delAuthRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(delAuthPar, BasicConfig.MANAGER_corp_deleteAuthById, "删除权限等级失败", delAuthRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(delAuthPar, BasicConfig.MANAGER_corp_deleteAuthById, "获取数据失败", delAuthRes.body().asString()));
}
}
}
@Test(description = "编辑权限等级信息", priority = 9)
public void 编辑权限等级信息() {
Map<String, Object> saveAuthPar = new HashMap<>();
saveAuthPar.put("companyId", companyId);
saveAuthPar.put("authName", authName);
saveAuthPar.put("id", authId);
Response saveAuthRes = network.postResponse(saveAuthPar, BasicConfig.MANAGER_corp_saveAuth);
try {
boolean data = saveAuthRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(saveAuthPar, BasicConfig.MANAGER_corp_saveAuth, "编辑权限等级信息失败", saveAuthRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(saveAuthPar, BasicConfig.MANAGER_corp_saveAuth, "获取数据失败", saveAuthRes.body().asString()));
}
}
// 页面管理
@Test(description = "新增页面", priority = 10)
public void 新增页面() {
Map<String, Object> addPagePar = new HashMap<>();
addPagePar.put("companyId", companyId);
addPagePar.put("pageName", "自动化页面");
addPagePar.put("pageUrl", pageUrl);
addPagePar.put("authId", authId);
Response addPageRes = network.postResponse(addPagePar, BasicConfig.MANAGER_corp_savePage);
try {
boolean data = addPageRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(addPagePar, BasicConfig.MANAGER_corp_savePage, "新增页面失败", addPageRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(addPagePar, BasicConfig.MANAGER_corp_savePage, "获取数据失败", addPageRes.body().asString()));
}
}
@Test(description = "获取页面列表", priority = 11)
public void 获取页面列表() {
Map<String, Object> pageListsPar = new HashMap<>();
pageListsPar.put("companyId", companyId);
pageListsPar.put("authId", authId);
Response pageListsRes = network.getResponse(pageListsPar, BasicConfig.MANAGER_corp_pageLists);
try {
List<Page> pageList = JsonUtil.parseResponseToListBean(pageListsRes, Page.class);
Assert.assertEquals(pageList.get(0).getPageName(), "自动化页面", network.message(pageListsPar, BasicConfig.MANAGER_corp_pageLists, "列表最新数据页面名称与实际添加不符", pageListsRes.body().asString()));
pageId = pageList.get(0).getId();
}catch (Exception e){
e.printStackTrace();
Assert.fail(network.message(pageListsPar, BasicConfig.MANAGER_corp_pageLists, "获取数据失败", pageListsRes.body().asString()));
}
}
@Test(description = "删除页面", priority = 12)
public void 删除页面() {
//
}
@Test(description = "编辑页面信息", priority = 13)
public void 编辑页面信息() {
Map<String, Object> addPagePar = new HashMap<>();
addPagePar.put("companyId", companyId);
addPagePar.put("pageName", pageName);
addPagePar.put("pageUrl", pageUrl);
addPagePar.put("authId", authId);
addPagePar.put("id", pageId);
Response addPageRes = network.postResponse(addPagePar, BasicConfig.MANAGER_corp_savePage);
try {
boolean data = addPageRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(addPagePar, BasicConfig.MANAGER_corp_savePage, "编辑页面信息失败", addPageRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(addPagePar, BasicConfig.MANAGER_corp_savePage, "获取数据失败", addPageRes.body().asString()));
}
}
// 人员管理
@Test(description = "新增人员", priority = 14)
public void 新增人员() {
Map<String, Object> addStaffPar = new HashMap<>();
addStaffPar.put("staffName", "员工1");
addStaffPar.put("staffPhone", staffPhone);
addStaffPar.put("authId", authId);
addStaffPar.put("companyId", companyId);
Response addStaffRes = network.postResponse(addStaffPar, BasicConfig.MANAGER_corp_saveStaff);
try {
boolean data = addStaffRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(addStaffPar, BasicConfig.MANAGER_corp_saveStaff, "新增员工失败", addStaffRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(addStaffPar, BasicConfig.MANAGER_corp_saveStaff, "获取数据失败", addStaffRes.body().asString()));
}
}
@Test(description = "查询员工列表", priority = 15)
public void 查询员工列表() {
Map<String, Object> staffListPar = new HashMap<>();
staffListPar.put("companyId", companyId);
Response staffListRes = network.getResponse(staffListPar, BasicConfig.MANAGER_corp_staffList);
try {
List<Staff> staffList = JsonUtil.parseResponseToPageBean(staffListRes, Staff.class);
Staff newStaff = staffList.get(0);
Assert.assertEquals(newStaff.getStaffName(), "员工1", network.message(staffListPar, BasicConfig.MANAGER_corp_staffList, "最新员工姓名与实际添加不符", staffListRes.body().asString()));
staffId = newStaff.getId();
}catch (Exception e){
e.printStackTrace();
Assert.fail(network.message(staffListPar, BasicConfig.MANAGER_corp_staffList, "获取数据失败", staffListRes.body().asString()));
}
}
@Test(description = "删除员工", priority = 16)
public void 删除员工() {
}
@Test(description = "编辑员工信息", priority = 17)
public void 编辑员工信息() {
Map<String, Object> addStaffPar = new HashMap<>();
addStaffPar.put("staffName", staffName);
addStaffPar.put("staffPhone", staffPhone);
addStaffPar.put("authId", authId);
addStaffPar.put("id", staffId);
addStaffPar.put("companyId", companyId);
Response addStaffRes = network.postResponse(addStaffPar, BasicConfig.MANAGER_corp_saveStaff);
try {
boolean data = addStaffRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(addStaffPar, BasicConfig.MANAGER_corp_saveStaff, "编辑员工信息失败", addStaffRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(addStaffPar, BasicConfig.MANAGER_corp_saveStaff, "获取数据失败", addStaffRes.body().asString()));
}
}
@Test(description = "判断员工手机号是否已存在", priority = 18)
public void 判断员工手机号是否已存在() {
Map<String , Object> phoneExistPar = new HashMap<>();
phoneExistPar.put("companyId", companyId);
phoneExistPar.put("phone", staffPhone);
Response phoneExistRes = network.getResponse(phoneExistPar, BasicConfig.MANAGER_corp_phoneExist);
try {
boolean data = phoneExistRes.jsonPath().getBoolean("data");
Assert.assertTrue(data, network.message(phoneExistPar, BasicConfig.MANAGER_corp_phoneExist, "未校验到号码已重复", phoneExistRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(phoneExistPar, BasicConfig.MANAGER_corp_phoneExist, "获取数据失败", phoneExistRes.body().asString()));
}
}
@Test(description = "同一公司员工手机号不可重复", priority = 19)
public void 同一公司员工手机号不可重复() {
Map<String, Object> addStaffPar = new HashMap<>();
addStaffPar.put("staffName", "员工2");
addStaffPar.put("staffPhone", staffPhone);
addStaffPar.put("authId", authId);
addStaffPar.put("companyId", companyId);
Response addStaffRes = network.postResponse(addStaffPar, BasicConfig.MANAGER_corp_saveStaff);
try {
boolean success = addStaffRes.jsonPath().getBoolean("success");
Assert.assertFalse(success, network.message(addStaffPar, BasicConfig.MANAGER_corp_saveStaff, "同一手机号重复注册员工成功", addStaffRes.body().asString()));
}catch (NullPointerException e){
e.printStackTrace();
Assert.fail(network.message(addStaffPar, BasicConfig.MANAGER_corp_saveStaff, "获取数据失败", addStaffRes.body().asString()));
}
}
public void getCurrentTimeStamp() {
// 将companyNameOfTimeStamp赋值操作单独封装成一个方法
// 保证在多次使用该变量时他的值不会发生变化
companyNameOfTimeStamp = String.valueOf(new Date().getTime());
}
}
......@@ -1163,4 +1163,17 @@ public class BasicConfig {
public static final String MANAGER_exclusiveItemDel = MANAGER_HOST + "/kjy/manager/exclusiveItem/del";
public static final String MANAGER_searchCompany = MANAGER_HOST + "/kjy/manager/live/company/search";
public static final String MANAGER_liveList = MANAGER_HOST + "/kjy/manager/live/list";
// 企业后台
public static final String MANAGER_corp_saveCorp = MANAGER_HOST + "/kjy/manager/corp/company/saveOrUpdate";
public static final String MANAGER_corp_CorpLists = MANAGER_HOST + "/kjy/manager/corp/company/selectList";
public static final String MANAGER_corp_searchCorp = MANAGER_HOST + "/kjy/manager/corp/company/search";
public static final String MANAGER_corp_saveAuth = MANAGER_HOST + "/kjy/manager/corp/company/auth/saveOrUpdate";
public static final String MANAGER_corp_authLists = MANAGER_HOST + "/kjy/manager/corp/company/auth/selectList";
public static final String MANAGER_corp_deleteAuthById = MANAGER_HOST + "/kjy/manager/corp/company/auth/deleteById";
public static final String MANAGER_corp_savePage = MANAGER_HOST + "/kjy/manager/corp/company/page/saveOrUpdate";
public static final String MANAGER_corp_pageLists = MANAGER_HOST + "/kjy/manager/corp/company/page/selectList";
public static final String MANAGER_corp_saveStaff = MANAGER_HOST + "/kjy/manager/corp/company/staff/saveOrUpdate";
public static final String MANAGER_corp_staffList = MANAGER_HOST + "/kjy/manager/corp/company/staff/selectList";
public static final String MANAGER_corp_phoneExist = MANAGER_HOST + "/kjy/manager/corp/company/staff/phoneExist";
}
......@@ -277,5 +277,10 @@
<class name="com.kjj.cases.live.treasure.GoldenEgg" />
</classes>
</test>
<test preserve-order="true" name="企业后台后台配置">
<classes>
<class name="com.kjj.cases.live.Corp.ManageCorp" />
</classes>
</test>
</suite>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment