2.26.0
2.0.7
org.mockito
mockito-core
${mockito.version}
test
org.powermock
powermock-api-mockito2
${powermock.version}
test
org.powermock
powermock-module-junit4
${powermock.version}
test
junit
junit
org.hamcrest
hamcrest-all
1.3
test
com.h2database
h2
1.4.200
test
com.ninja-squad
DbSetup
2.1.0
test
"http://mybatis.org/dtd/mybatis-3-config.dtd">
CREATE TABLE IF NOT EXISTS authority
(
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT '权限id',
app_id varchar(32) comment '应用id',
name varchar(1024) NOT NULL comment '资源名称(资源表冗余)',
type varchar(20) NOT NULL comment '资源类型(资源表冗余)',
authority_type varchar(20) NOT NULL comment '权限生效类型,更新/新增',
workspace_id varchar(32) NOT NULL comment '所属空间id(资源表冗余)',
resource_id varchar(32) COMMENT '资源id',
auth_content TEXT COMMENT '资权限详细信息源id',
owner varchar(100) NOT NULL comment '权限owner',
owner_type tinyint(1) NOT NULL COMMENT '权限owner type 1.uin,2.role',
op_type varchar(32) comment '权限操作类型',
op_types varchar(200) comment '权限操作类型元数列表',
authority_source tinyint(1) comment '权限获取来源 1.申请,2.授权',
read tinyint(3) NOT NULL DEFAULT '0' COMMENT '资源读权限1.可读,0.不可读',
write tinyint(3) NOT NULL DEFAULT '0' COMMENT '资源写权限1.可写,0.不可写',
admin tinyint(3) NOT NULL DEFAULT '0' COMMENT '资源管理权限1.可管理,0.不可管理',
status tinyint(3) NOT NULL DEFAULT '1' COMMENT '权限状态1.有效,0.无效',
life_cycle varchar(100) NOT NULL COMMENT '权限生命周期',
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
CONSTRAINT pk_authority PRIMARY KEY(id)
) ;
CREATE UNIQUE INDEX uniq_app_resource_owner_type_status ON authority(app_id, resource_id, owner, owner_type, status);
INSERT INTO authority
(app_id, name, type, authority_type, workspace_id, first_key, second_key, third_key, fourth_key, resource_id, auth_content, owner, owner_type, op_type, op_types, read, write, admin, status, life_cycle, created_at, updated_at)
VALUES('', '', '', '', '', '', '', '', '', '', '', '', 0, '', '', 0, 0, 0, 1, '', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
import com.ninja_squad.dbsetup.DbSetupTracker;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@PowerMockIgnore({"javax.management.*"})
@ContextConfiguration("classpath:h2/grant/application-context.xml")
public class BaseTest1 {
protected static DbSetupTracker dbSetupTracker;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
}
@BeforeClass
public static void onceExecutedBeforeAll() {
dbSetupTracker = new DbSetupTracker();
}
}
public class AnalyzeOverviewServiceImplTest extends BaseTest1 {
@InjectMocks
private AnalyzeOverviewService analyzeOverviewService = new AnalyzeOverviewServiceImpl();
//这个对象是容器创建的,DAO层代码,根据你的实际情况来
@Autowired
private QualityTaskMapper qualityTaskMapper;
@Before
public void init(){
//数据库走真是逻辑
//因为数据库走真是逻辑,因此需要将上面的bean 注入到Mock的对象中
ReflectionTestUtils.setField(analyzeOverviewService, "qualityTaskMapper",
qualityTaskMapper);
}
/**
* Overview.
*/
@Test
public void overview() {
OverViewDataReq request = new OverViewDataReq();
request.setEndDate("2021-9-14");
request.setStartDate("2021-9-14");
request.setWorkspaceId("123");
final OverViewDataResp overview = analyzeOverviewService.overview(request);
}
}