费用提交
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
package com.baiyue.lastleg.procurement.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||
import com.baiyue.lastleg.procurement.mapper.ProcurementDirectionMapper;
|
||||
import com.baiyue.lastleg.procurement.repository.ProcurementDirectionRepository;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import java.util.UUID;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ProcurementDirectionPersistenceTest {
|
||||
@Test void directionGateReadsOnlyThisOrdersRecordedFacts() throws Exception {
|
||||
var ds = new DriverManagerDataSource("jdbc:h2:mem:"+UUID.randomUUID()+";MODE=MySQL;DB_CLOSE_DELAY=-1","sa","");
|
||||
var jdbc = new JdbcTemplate(ds);
|
||||
jdbc.execute("CREATE TABLE ll_procurement_flow(order_id BIGINT PRIMARY KEY,purchased_at TIMESTAMP,actual_warehouse_id BIGINT,overseas_shipped_at TIMESTAMP)");
|
||||
var config = new MybatisConfiguration(); config.addMapper(ProcurementDirectionMapper.class);
|
||||
var factory = new MybatisSqlSessionFactoryBean(); factory.setDataSource(ds); factory.setConfiguration(config);
|
||||
var repository = new ProcurementDirectionRepository(new SqlSessionTemplate(factory.getObject()).getMapper(ProcurementDirectionMapper.class));
|
||||
assertThat(repository.hasStarted(1)).isFalse();
|
||||
jdbc.update("INSERT INTO ll_procurement_flow(order_id) VALUES(1)");
|
||||
assertThat(repository.hasStarted(1)).isFalse();
|
||||
jdbc.update("UPDATE ll_procurement_flow SET purchased_at=CURRENT_TIMESTAMP WHERE order_id=1");
|
||||
assertThat(repository.hasStarted(1)).isTrue();
|
||||
assertThat(repository.hasStarted(2)).isFalse();
|
||||
jdbc.update("UPDATE ll_procurement_flow SET purchased_at=NULL,actual_warehouse_id=91 WHERE order_id=1");
|
||||
assertThat(repository.hasStarted(1)).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user