test: 搭建审批流开发测试底座
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<skipITs>true</skipITs>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -382,11 +383,27 @@
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipITs>${skipITs}</skipITs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>approval-it</id>
|
||||
<properties>
|
||||
<skipITs>false</skipITs>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>aliYunMaven</id>
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.gxwebsoft.common.core.config;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
@@ -24,6 +25,7 @@ import java.util.List;
|
||||
*/
|
||||
@EnableOpenApi
|
||||
@Configuration
|
||||
@Profile("!test")
|
||||
public class SwaggerConfig {
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.gxwebsoft.think.service.ThinkOrderService;
|
||||
import com.gxwebsoft.think.service.ThinkSiteService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -35,7 +36,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@Api(tags = "定时任务")
|
||||
@RestController
|
||||
@RequestMapping("/api/scheduled")
|
||||
|
||||
@Profile("!test")
|
||||
public class SchedulingController extends BaseController {
|
||||
|
||||
@Resource
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.gxwebsoft.think.entity.*;
|
||||
import com.gxwebsoft.think.service.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -34,6 +35,7 @@ import java.util.stream.Collectors;
|
||||
* @since 2026-03-13
|
||||
*/
|
||||
@Component
|
||||
@Profile("!test")
|
||||
public class ThinkFaceAccessTask {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ThinkFaceAccessTask.class);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.gxwebsoft;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* 集成测试底座冒烟:只验证测试 profile 能启动上下文并连上共享测试库,不涉及业务表。
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ActiveProfiles({"gxtyzx-test", "test"})
|
||||
class ContextLoadsIT {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
void connectsToTestDatabase() {
|
||||
Integer result = new JdbcTemplate(dataSource).queryForObject("select 1", Integer.class);
|
||||
assertThat(result).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.gxwebsoft;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.gxwebsoft.think.entity.ThinkOrder;
|
||||
import com.gxwebsoft.think.service.ThinkOrderService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
|
||||
/**
|
||||
* Created by WebSoft on 2020-03-23 23:37
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class TestMain {
|
||||
/**
|
||||
* 生成唯一的key用于jwt工具类
|
||||
*/
|
||||
@Test
|
||||
public void testGenJwtKey() {
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(NumberUtil.decimalFormat("0.00", 1 * 0.01));
|
||||
System.out.println("实际付款金额 = " + bigDecimal);
|
||||
// System.out.println(JwtUtil.encodeKey(JwtUtil.randomKey()));
|
||||
|
||||
// final String encrypt = CommonUtil.encrypt("123456");
|
||||
// System.out.println("encrypt = " + encrypt);
|
||||
//
|
||||
// final String decrypt = CommonUtil.decrypt(encrypt);
|
||||
// System.out.println("decrypt = " + decrypt);
|
||||
}
|
||||
|
||||
|
||||
private String fenToYuan(String amount){
|
||||
NumberFormat format = NumberFormat.getInstance();
|
||||
try{
|
||||
Number number = format.parse(amount);
|
||||
double temp = number.doubleValue() / 100.0;
|
||||
format.setGroupingUsed(false);
|
||||
// 设置返回的小数部分所允许的最大位数
|
||||
format.setMaximumFractionDigits(2);
|
||||
amount = format.format(temp);
|
||||
} catch (ParseException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.gxwebsoft;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class WebSoftApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.gxwebsoft.support;
|
||||
|
||||
import com.gxwebsoft.common.system.entity.Menu;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 测试用登录态构造器:MockMvc 直接注入 Authentication,不触发 JwtAuthenticationFilter 的远程 core 调用。
|
||||
*
|
||||
* <p>租户与用户固定为测试库中已存在的 10150 / 3673(admin);权限串由调用方传入。</p>
|
||||
*/
|
||||
public final class TestAuthentication {
|
||||
|
||||
public static final int TENANT_ID = 10150;
|
||||
public static final int USER_ID = 3673;
|
||||
|
||||
private TestAuthentication() {
|
||||
}
|
||||
|
||||
public static Authentication admin(String... authorities) {
|
||||
List<Menu> menus = Arrays.stream(authorities)
|
||||
.map(authority -> {
|
||||
Menu menu = new Menu();
|
||||
menu.setAuthority(authority);
|
||||
return menu;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
User user = new User();
|
||||
user.setUserId(USER_ID);
|
||||
user.setUsername("admin");
|
||||
user.setTenantId(TENANT_ID);
|
||||
user.setStatus(0);
|
||||
user.setAuthorities(menus);
|
||||
|
||||
return new UsernamePasswordAuthenticationToken(user, null, menus);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.gxwebsoft.support;
|
||||
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestAuthenticationTest {
|
||||
|
||||
@Test
|
||||
void buildsAdminPrincipalWithAuthorities() {
|
||||
Authentication authentication = TestAuthentication.admin("approval:instance:list");
|
||||
|
||||
assertThat(authentication.getPrincipal()).isInstanceOf(User.class);
|
||||
User user = (User) authentication.getPrincipal();
|
||||
assertThat(user.getUserId()).isEqualTo(TestAuthentication.USER_ID);
|
||||
assertThat(user.getTenantId()).isEqualTo(TestAuthentication.TENANT_ID);
|
||||
assertThat(authentication.getAuthorities())
|
||||
.extracting(GrantedAuthority::getAuthority)
|
||||
.containsExactly("approval:instance:list");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# 测试专用覆盖;必须与 @ActiveProfiles({"gxtyzx-test", "test"}) 一起使用。
|
||||
# 数据源、Redis、远程 core 地址仍由 application-gxtyzx-test.yml 提供。
|
||||
config:
|
||||
upload-path: ${java.io.tmpdir}/gxtyzx-test-uploads/
|
||||
local-upload-path: ${java.io.tmpdir}/gxtyzx-test-uploads/
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.gxwebsoft: WARN
|
||||
com.baomidou.mybatisplus: WARN
|
||||
|
||||
springfox:
|
||||
documentation:
|
||||
enabled: false
|
||||
Reference in New Issue
Block a user