jasmine.framework.test.liquibase.loader.AbstractTestDataLoader Maven / Gradle / Ivy
package jasmine.framework.test.liquibase.loader;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ReflectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jasmine.framework.test.liquibase.log.TestDataChangeLog;
import jasmine.framework.test.liquibase.log.TestDataChangeLogMapper;
import jasmine.framework.test.util.MybatisPlusUtil;
import jasmine.framework.database.mybatisplus.util.MybatisPlusCsvUtil;
import org.springframework.context.ApplicationContext;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.function.Function;
/**
* @author mh.z
*/
public abstract class AbstractTestDataLoader implements TestDataLoader {
/** 类型 */
protected Class> type;
/** 日志数据接口 */
protected TestDataChangeLogMapper logMapper;
@Override
public void init(ApplicationContext applicationContext, Class> type) {
this.type = type;
this.logMapper = applicationContext.getBean(TestDataChangeLogMapper.class);
}
@Override
public void load(String resourcePath, InputStream inputStream) {
Assert.notNull(resourcePath, "resourcePath null");
Assert.notNull(inputStream, "inputStream null");
LambdaQueryWrapper logWrapper = Wrappers.lambdaQuery();
logWrapper.eq(TestDataChangeLog::getResourcePath, resourcePath);
List logList = logMapper.selectList(logWrapper);
// 加载数据的逻辑是,1.先根据测试数据变更日志表里的记录删除原表里的记录。
// 2.然后把新的数据插入到表里。
if (CollUtil.isNotEmpty(logList)) {
// 删除原来的数据
List recordIdList = CollStreamUtil.toList(logList, TestDataChangeLog::getRecordId);
deleteRecords(recordIdList);
// 删除原来的日志记录
List logIdList = CollStreamUtil.toList(logList, TestDataChangeLog::getId);
logMapper.deleteBatchIds(logIdList);
}
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy