ApplicationContextIT.java
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.xly.test4;
import java.util.Map;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
class ApplicationContextIT {
@Autowired
private ApplicationContext context;
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private MybatisPlusInterceptor mybatisPlusInterceptor;
@Test
void contextLoads() {
assertThat(context).isNotNull();
assertThat(context.getBean(Application.class)).isNotNull();
}
@Test
void flywayMigrationsApplied_seedDataPresent() {
Integer permCount = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM tPermission WHERE sCategory IN "
+ "('usr:user:create','usr:user:update','usr:user:list','usr:user:assign-role')",
Integer.class);
assertThat(permCount).isEqualTo(4);
Map<String, Object> admin = jdbcTemplate.queryForMap(
"SELECT sUserType, sBrandsId, sSubsidiaryId, iIsDisabled FROM tUser WHERE sUserName = 'admin'");
assertThat(admin.get("sUserType")).isEqualTo("ADMIN");
assertThat(admin.get("sBrandsId")).isEqualTo("BR-DEFAULT");
assertThat(admin.get("sSubsidiaryId")).isEqualTo("SUB-DEFAULT");
assertThat(((Number) admin.get("iIsDisabled")).intValue()).isEqualTo(0);
Integer authCount = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM tUserPermission WHERE iUserId = "
+ "(SELECT iIncrement FROM tUser WHERE sUserName = 'admin')",
Integer.class);
assertThat(authCount).isEqualTo(4);
}
@Test
void paginationInterceptorRegistered() {
assertThat(mybatisPlusInterceptor).isNotNull();
assertThat(mybatisPlusInterceptor.getInterceptors())
.anyMatch(i -> i instanceof PaginationInnerInterceptor);
}
}