package com.zy.common.service; import com.zy.asrs.entity.LocMast; import com.zy.asrs.entity.result.FindLocNoAttributeVo; import com.zy.common.model.LocTypeDto; import org.junit.jupiter.api.Test; import org.springframework.test.util.ReflectionTestUtils; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; class CommonServiceLocTypeStrategyTest { private final CommonService commonService = new CommonService(); @Test void normalizeLocTypeDto_forFullPallet_ignoresLocType2AndLocType3() { FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo(); attributeVo.setMatnr("MAT-001"); LocTypeDto locTypeDto = new LocTypeDto(); locTypeDto.setLocType1((short) 1); locTypeDto.setLocType2((short) 1); locTypeDto.setLocType3((short) 2); LocTypeDto normalized = ReflectionTestUtils.invokeMethod( commonService, "normalizeLocTypeDto", 1, attributeVo, locTypeDto); assertEquals(Short.valueOf((short) 1), normalized.getLocType1()); org.junit.jupiter.api.Assertions.assertNull(normalized.getLocType2()); org.junit.jupiter.api.Assertions.assertNull(normalized.getLocType3()); } @Test void normalizeLocTypeDto_forEmptyPallet_prefersNarrowAndKeepsHeight() { FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo(); attributeVo.setMatnr("emptyPallet"); LocTypeDto locTypeDto = new LocTypeDto(); locTypeDto.setLocType1((short) 1); locTypeDto.setLocType3((short) 2); LocTypeDto normalized = ReflectionTestUtils.invokeMethod( commonService, "normalizeLocTypeDto", 10, attributeVo, locTypeDto); assertEquals(Short.valueOf((short) 1), normalized.getLocType1()); assertEquals(Short.valueOf((short) 1), normalized.getLocType2()); assertEquals(Short.valueOf((short) 2), normalized.getLocType3()); } @Test void buildRetryCompatibleLocTypeDto_forEmptyPallet_onlyRaisesHeightAndKeepsOtherLocTypes() { FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo(); attributeVo.setMatnr("emptyPallet"); LocTypeDto locTypeDto = new LocTypeDto(); locTypeDto.setLocType1((short) 1); locTypeDto.setLocType2((short) 1); locTypeDto.setLocType3((short) 2); LocTypeDto compatible = ReflectionTestUtils.invokeMethod( commonService, "buildRetryCompatibleLocTypeDto", 10, attributeVo, locTypeDto); assertEquals(Short.valueOf((short) 2), compatible.getLocType1()); assertEquals(Short.valueOf((short) 1), compatible.getLocType2()); assertEquals(Short.valueOf((short) 2), compatible.getLocType3()); } @Test void buildRetryCompatibleLocTypeDto_forFullPallet_onlyRaisesHeight() { FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo(); attributeVo.setMatnr("MAT-001"); LocTypeDto locTypeDto = new LocTypeDto(); locTypeDto.setLocType1((short) 1); locTypeDto.setLocType2((short) 2); locTypeDto.setLocType3((short) 2); LocTypeDto normalized = ReflectionTestUtils.invokeMethod( commonService, "normalizeLocTypeDto", 1, attributeVo, locTypeDto); LocTypeDto compatible = ReflectionTestUtils.invokeMethod( commonService, "buildRetryCompatibleLocTypeDto", 1, attributeVo, normalized); assertEquals(Short.valueOf((short) 2), compatible.getLocType1()); org.junit.jupiter.api.Assertions.assertNull(compatible.getLocType2()); org.junit.jupiter.api.Assertions.assertNull(compatible.getLocType3()); } @Test void wcsFullPalletPayload_whenLowLocExhausted_shouldRetryHighLocWithoutLocType2OrLocType3() { FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo(); attributeVo.setMatnr("MAT-80000001"); LocTypeDto requestLocType = new LocTypeDto(); requestLocType.setLocType1((short) 1); requestLocType.setLocType2((short) 2); requestLocType.setLocType3((short) 2); LocTypeDto normalized = ReflectionTestUtils.invokeMethod( commonService, "normalizeLocTypeDto", 1, attributeVo, requestLocType); LocTypeDto compatible = ReflectionTestUtils.invokeMethod( commonService, "buildRetryCompatibleLocTypeDto", 1, attributeVo, normalized); assertEquals(Short.valueOf((short) 2), compatible.getLocType1()); org.junit.jupiter.api.Assertions.assertNull(compatible.getLocType2()); org.junit.jupiter.api.Assertions.assertNull(compatible.getLocType3()); } @Test void matchesLocType_forFullPallet_rejectsNarrowLocType2() { FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo(); attributeVo.setMatnr("MAT-001"); LocTypeDto requestLocType = new LocTypeDto(); requestLocType.setLocType1((short) 1); LocTypeDto normalized = ReflectionTestUtils.invokeMethod( commonService, "normalizeLocTypeDto", 1, attributeVo, requestLocType); LocMast narrowLoc = new LocMast(); narrowLoc.setLocType1((short) 1); narrowLoc.setLocType2((short) 1); Boolean matched = ReflectionTestUtils.invokeMethod( commonService, "matchesLocType", narrowLoc, normalized); assertFalse(Boolean.TRUE.equals(matched)); } @Test void matchesLocType_forFullPallet_acceptsNonNarrowLocType2() { FindLocNoAttributeVo attributeVo = new FindLocNoAttributeVo(); attributeVo.setMatnr("MAT-001"); LocTypeDto requestLocType = new LocTypeDto(); requestLocType.setLocType1((short) 1); LocTypeDto normalized = ReflectionTestUtils.invokeMethod( commonService, "normalizeLocTypeDto", 1, attributeVo, requestLocType); LocMast wideLoc = new LocMast(); wideLoc.setLocType1((short) 1); wideLoc.setLocType2((short) 2); Boolean matched = ReflectionTestUtils.invokeMethod( commonService, "matchesLocType", wideLoc, normalized); assertTrue(Boolean.TRUE.equals(matched)); } @Test @SuppressWarnings("unchecked") void buildEmptyPalletSearchLocTypes_forLowLoc_returnsConfiguredFallbackOrder() { LocTypeDto locTypeDto = new LocTypeDto(); locTypeDto.setLocType1((short) 1); locTypeDto.setLocType2((short) 1); locTypeDto.setLocType3((short) 2); List stages = ReflectionTestUtils.invokeMethod( commonService, "buildEmptyPalletSearchLocTypes", locTypeDto); assertEquals(4, stages.size()); assertEquals(Short.valueOf((short) 1), stages.get(0).getLocType1()); assertEquals(Short.valueOf((short) 1), stages.get(0).getLocType2()); assertEquals(Short.valueOf((short) 1), stages.get(1).getLocType1()); org.junit.jupiter.api.Assertions.assertNull(stages.get(1).getLocType2()); assertEquals(Short.valueOf((short) 2), stages.get(2).getLocType1()); assertEquals(Short.valueOf((short) 1), stages.get(2).getLocType2()); assertEquals(Short.valueOf((short) 2), stages.get(3).getLocType1()); org.junit.jupiter.api.Assertions.assertNull(stages.get(3).getLocType2()); assertEquals(Short.valueOf((short) 2), stages.get(3).getLocType3()); } }