34 lines
2.4 KiB
Java
34 lines
2.4 KiB
Java
package com.baiyue.lastleg.appointmentplanning;
|
|
|
|
import org.apache.ibatis.mapping.Environment;
|
|
import org.apache.ibatis.session.Configuration;
|
|
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
|
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
|
import org.h2.jdbcx.JdbcDataSource;
|
|
import org.junit.jupiter.api.Test;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class AppointmentBatchPreviewMapperTest {
|
|
@Test void flagsUseRealCustomerOwnershipAndIgnoreCancelledAppointments() throws Exception {
|
|
var ds=new JdbcDataSource();ds.setURL("jdbc:h2:mem:batch-preview-"+UUID.randomUUID()+";MODE=MySQL;DB_CLOSE_DELAY=-1");
|
|
try(var c=ds.getConnection();var s=c.createStatement()) {
|
|
s.execute("CREATE TABLE ll_order(id BIGINT, customer_id VARCHAR(32),detained BOOLEAN,fba_warehouse_code VARCHAR(32))");
|
|
s.execute("CREATE TABLE ll_order_detail(order_id BIGINT,customer_id VARCHAR(32),destination_warehouse_code VARCHAR(32))");
|
|
s.execute("CREATE TABLE ll_inbound_fba_appointment(id BIGINT,appointment_status VARCHAR(32))");
|
|
s.execute("CREATE TABLE ll_inbound_fba_appointment_item(order_id BIGINT,customer_id VARCHAR(32),appointment_id BIGINT)");
|
|
s.execute("INSERT INTO ll_order VALUES(1,'A',FALSE,'ONT8'),(2,'B',TRUE,'ONT8'),(3,'C',FALSE,'ONT8')");
|
|
s.execute("INSERT INTO ll_order_detail VALUES(1,'OTHER','LAX9'),(2,'B','ONT8'),(3,'C','LAX9')");
|
|
s.execute("INSERT INTO ll_inbound_fba_appointment VALUES(10,'CANCELLED'),(11,'SUCCESS')");
|
|
s.execute("INSERT INTO ll_inbound_fba_appointment_item VALUES(1,'A',10),(1,'OTHER',11),(3,'C',11)");
|
|
}
|
|
var config=new Configuration(new Environment("test",new JdbcTransactionFactory(),ds));config.addMapper(AppointmentBatchPreviewMapper.class);
|
|
try(var session=new SqlSessionFactoryBuilder().build(config).openSession()) {
|
|
var flags=session.getMapper(AppointmentBatchPreviewMapper.class).flags(List.of(1L,2L,3L)).stream().collect(java.util.stream.Collectors.toMap(AppointmentBatchPreviewMapper.Flags::orderId,r->r));
|
|
assertFalse(flags.get(1L).mixedDestinations());assertFalse(flags.get(1L).activeAppointment());
|
|
assertTrue(flags.get(2L).detained());assertTrue(flags.get(3L).mixedDestinations());assertTrue(flags.get(3L).activeAppointment());
|
|
}
|
|
}
|
|
}
|