package com.zy.asrs.service.impl;
|
|
import com.zy.asrs.entity.BasCrnDepthRule;
|
import com.zy.asrs.entity.RowLastno;
|
import com.zy.asrs.entity.param.BasCrnDepthRuleTemplateParam;
|
import com.zy.asrs.service.RowLastnoService;
|
import com.zy.common.model.CrnDepthRuleProfile;
|
import com.zy.common.properties.SlaveProperties;
|
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.mockito.Mock;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
import java.util.Arrays;
|
import java.util.List;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.when;
|
|
@ExtendWith(MockitoExtension.class)
|
class BasCrnDepthRuleServiceImplTest {
|
|
@Mock
|
private RowLastnoService rowLastnoService;
|
|
private BasCrnDepthRuleServiceImpl service;
|
|
@BeforeEach
|
void setUp() {
|
service = spy(new BasCrnDepthRuleServiceImpl());
|
ReflectionTestUtils.setField(service, "rowLastnoService", rowLastnoService);
|
ReflectionTestUtils.setField(service, "slaveProperties", buildSlaveProperties());
|
}
|
|
@Test
|
void validateRule_forSingleExtension_fillsShallowRowsAndNormalizesCsv() {
|
BasCrnDepthRule rule = new BasCrnDepthRule();
|
rule.setWhsType(1);
|
rule.setCrnNo(1);
|
rule.setLayoutType(1);
|
rule.setSearchRowsCsv("1, 2,2");
|
|
service.validateRule(rule);
|
|
assertEquals("1,2", rule.getSearchRowsCsv());
|
assertEquals("1,2", rule.getShallowRowsCsv());
|
assertEquals(null, rule.getDeepRowsCsv());
|
assertEquals(Integer.valueOf(1), rule.getEnabled());
|
}
|
|
@Test
|
void validateRule_forSingleExtension_rejectsDeepRows() {
|
BasCrnDepthRule rule = new BasCrnDepthRule();
|
rule.setWhsType(1);
|
rule.setCrnNo(1);
|
rule.setLayoutType(1);
|
rule.setSearchRowsCsv("1,2");
|
rule.setDeepRowsCsv("3");
|
|
assertThrows(RuntimeException.class, () -> service.validateRule(rule));
|
}
|
|
@Test
|
void validateRule_forDoubleExtension_requiresBothShallowAndDeepRows() {
|
BasCrnDepthRule rule = new BasCrnDepthRule();
|
rule.setWhsType(1);
|
rule.setCrnNo(1);
|
rule.setLayoutType(2);
|
rule.setSearchRowsCsv("2,1");
|
rule.setShallowRowsCsv("2");
|
|
assertThrows(RuntimeException.class, () -> service.validateRule(rule));
|
}
|
|
@Test
|
void resolveProfile_prefersConfiguredRule() {
|
RowLastno rowLastno = new RowLastno();
|
rowLastno.setWhsType(1);
|
BasCrnDepthRule rule = new BasCrnDepthRule();
|
rule.setWhsType(1);
|
rule.setCrnNo(2);
|
rule.setLayoutType(2);
|
rule.setSearchRowsCsv("6,5");
|
rule.setShallowRowsCsv("6");
|
rule.setDeepRowsCsv("5");
|
|
doReturn(rule).when(service).findEnabledRule(1, 2);
|
|
CrnDepthRuleProfile profile = service.resolveProfile(rowLastno, 2, 6);
|
|
assertEquals(Integer.valueOf(2), profile.getLayoutType());
|
assertEquals(Arrays.asList(6, 5), profile.getSearchRows());
|
assertEquals(Arrays.asList(6), profile.getShallowRows());
|
assertEquals(Arrays.asList(5), profile.getDeepRows());
|
assertEquals(Integer.valueOf(5), profile.getPairedDeepRow(6));
|
}
|
|
@Test
|
void previewTemplate_buildsLegacyRowsForSingleExtensionWarehouse() {
|
RowLastno rowLastno = new RowLastno();
|
rowLastno.setWhsType(1);
|
rowLastno.setsCrnNo(1);
|
rowLastno.seteCrnNo(2);
|
rowLastno.setsRow(1);
|
rowLastno.seteRow(4);
|
rowLastno.setTypeId(2);
|
when(rowLastnoService.selectById(1)).thenReturn(rowLastno);
|
|
BasCrnDepthRuleTemplateParam param = new BasCrnDepthRuleTemplateParam();
|
param.setWhsType(1);
|
|
List<BasCrnDepthRule> preview = service.previewTemplate(param);
|
|
assertEquals(2, preview.size());
|
assertEquals(Integer.valueOf(1), preview.get(0).getLayoutType());
|
assertEquals("1,2", preview.get(0).getSearchRowsCsv());
|
assertEquals("3,4", preview.get(1).getSearchRowsCsv());
|
}
|
|
@Test
|
void previewTemplate_buildsLegacyRowsForDoubleExtensionWarehouse() {
|
RowLastno rowLastno = new RowLastno();
|
rowLastno.setWhsType(1);
|
rowLastno.setsCrnNo(1);
|
rowLastno.seteCrnNo(1);
|
rowLastno.setsRow(1);
|
rowLastno.seteRow(4);
|
rowLastno.setTypeId(1);
|
when(rowLastnoService.selectById(1)).thenReturn(rowLastno);
|
|
BasCrnDepthRuleTemplateParam param = new BasCrnDepthRuleTemplateParam();
|
param.setWhsType(1);
|
|
List<BasCrnDepthRule> preview = service.previewTemplate(param);
|
|
assertEquals(1, preview.size());
|
assertEquals("2,3", preview.get(0).getSearchRowsCsv());
|
assertTrue(preview.get(0).getShallowRowsCsv().contains("2"));
|
assertTrue(preview.get(0).getDeepRowsCsv().contains("1"));
|
}
|
|
private SlaveProperties buildSlaveProperties() {
|
SlaveProperties slaveProperties = new SlaveProperties();
|
slaveProperties.setDoubleDeep(true);
|
slaveProperties.setDoubleLocs(Arrays.asList(1, 4, 5, 8));
|
slaveProperties.setDoubleLocsLeft(Arrays.asList(1, 5));
|
slaveProperties.setDoubleLocsRight(Arrays.asList(4, 8));
|
slaveProperties.setGroupCount(4);
|
return slaveProperties;
|
}
|
}
|