package com.pgf.mqspring.component.impl; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.ByteArrayInputStream; import java.io.IOException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.core.io.ClassPathResource; import org.springframework.test.util.ReflectionTestUtils; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.S3Object; import com.pgf.mqspring.component.MqSpringMessageSourceComponent; import com.pgf.mqspring.constant.MqSpringMessageId; import com.pgf.mqspring.model.TelegramInfoModel; class TelegramInfoComponentImplTest01 { @Mock AmazonS3 s3Client; @Mock MqSpringMessageSourceComponent messageSource; TelegramInfoComponentImpl target; @BeforeEach void beforeEach() throws IOException { MockitoAnnotations.openMocks(this); S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ByteArrayInputStream(new byte[0])); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); target = new TelegramInfoComponentImpl(s3Client, messageSource, "", ""); } @Test void initTelegramInfo01() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo01/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertTrue(target.getTelegramInfoMap().isEmpty()); } @Test void initTelegramInfo02() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo02/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertTrue(target.getTelegramInfoMap().isEmpty()); } @Test void initTelegramInfo03() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo03/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertEquals(1, target.getTelegramInfoMap().size()); assertEquals(1, target.getTelegramInfoMap().get("EK10").size()); TelegramInfoModel model = target.getTelegramInfoMap().get("EK10").get(0); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("0", model.getRepeatNum()); assertEquals("0", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); } @Test void initTelegramInfo04() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo04/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertEquals(1, target.getTelegramInfoMap().size()); assertEquals(2, target.getTelegramInfoMap().get("EK10").size()); TelegramInfoModel model = target.getTelegramInfoMap().get("EK10").get(0); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("0", model.getRepeatNum()); assertEquals("0", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(1); assertEquals("EK10", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("0", model.getRepeatNum()); assertEquals("0", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); } @Test void initTelegramInfo05() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo05/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertEquals(1, target.getTelegramInfoMap().size()); assertEquals(2, target.getTelegramInfoMap().get("EK10").size()); TelegramInfoModel model = target.getTelegramInfoMap().get("EK10").get(0); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("1", model.getRepeatNum()); assertEquals("1", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(1); assertEquals("EK10", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("0", model.getRepeatNum()); assertEquals("0", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); } @Test void initTelegramInfo06() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo06/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertEquals(1, target.getTelegramInfoMap().size()); assertEquals(3, target.getTelegramInfoMap().get("EK10").size()); TelegramInfoModel model = target.getTelegramInfoMap().get("EK10").get(0); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("1", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(1); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("1", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(2); assertEquals("EK10", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("0", model.getRepeatNum()); assertEquals("0", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); } @Test void initTelegramInfo07() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo07/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertEquals(1, target.getTelegramInfoMap().size()); assertEquals(2, target.getTelegramInfoMap().get("EK10").size()); TelegramInfoModel model = target.getTelegramInfoMap().get("EK10").get(0); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("1", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(1); assertEquals("EK10", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("1", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); } @Test void initTelegramInfo08() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo08/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertEquals(1, target.getTelegramInfoMap().size()); assertEquals(4, target.getTelegramInfoMap().get("EK10").size()); TelegramInfoModel model = target.getTelegramInfoMap().get("EK10").get(0); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(1); assertEquals("EK10", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(2); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(3); assertEquals("EK10", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); } @Test void initTelegramInfo09() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo09/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertEquals(2, target.getTelegramInfoMap().size()); assertEquals(2, target.getTelegramInfoMap().get("EK10").size()); TelegramInfoModel model = target.getTelegramInfoMap().get("EK10").get(0); assertEquals("EK10", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("0", model.getRepeatNum()); assertEquals("0", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK10").get(1); assertEquals("EK10", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("0", model.getRepeatNum()); assertEquals("0", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); assertEquals(4, target.getTelegramInfoMap().get("EK12").size()); model = target.getTelegramInfoMap().get("EK12").get(0); assertEquals("EK12", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK12").get(1); assertEquals("EK12", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK12").get(2); assertEquals("EK12", model.getDispCode()); assertEquals("1.", model.getFieldNo()); assertEquals("SCRID", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); model = target.getTelegramInfoMap().get("EK12").get(3); assertEquals("EK12", model.getDispCode()); assertEquals("2.", model.getFieldNo()); assertEquals("DATE", model.getItemName()); assertEquals("8", model.getItemLength()); assertEquals("0", model.getCharDiv()); assertEquals("2", model.getRepeatNum()); assertEquals("2", model.getGroupNum()); assertEquals("2003-11-13", model.getInsDate()); } @Test void initTelegramInfo10() throws IOException { S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/TelegramInfoComponentImplTest_01/initTelegramInfo10/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertTrue(target.isTelegramInfoError()); assertEquals(0, target.getTelegramInfoMap().size()); } @Test void initTelegramInfo11() { S3Object s3Object = mock(S3Object.class); when(s3Object.getObjectContent()).thenThrow(new RuntimeException()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertTrue(target.isTelegramInfoError()); verify(messageSource, times(1)).getMessage(MqSpringMessageId.SYS7081E); } }