package com.pgf.mqspring.component.impl; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.springframework.test.util.ReflectionTestUtils; import com.pgf.mqspring.component.MqSpringMessageSourceComponent; import com.pgf.mqspring.constant.MqSpringMessageId; import com.pgf.mqspring.model.TelegramInfoModel; class TelegramInfoComponentImplTest01 { @Mock MqSpringMessageSourceComponent messageSource; TelegramInfoComponentImpl target; @BeforeEach void beforeEach() throws IOException { MockitoAnnotations.openMocks(this); target = new TelegramInfoComponentImpl(messageSource, "", ""); } @Test void initTelegramInfo01() throws IOException { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo01\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); } assertTrue(target.getTelegramInfoMap().isEmpty()); } @Test void initTelegramInfo02() throws IOException { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo02\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); target = new TelegramInfoComponentImpl(messageSource, "", ""); } assertTrue(target.getTelegramInfoMap().isEmpty()); } @Test void initTelegramInfo03() throws IOException { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo03\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); 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 { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo04\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); 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 { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo05\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); 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 { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo06\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); 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 { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo07\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); 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 { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo08\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); 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 { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo09\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); 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 { String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\TelegramInfoComponentImplTest_01\\initTelegramInfo10\\ibm_telegram_info.csv"; Path path = Paths.get(csvPath); try (MockedStatic mockedStatic = Mockito.mockStatic(Paths.class)) { mockedStatic.when(() -> Paths.get("/ibm_telegram_info.csv")).thenReturn(path).toString(); ReflectionTestUtils.invokeMethod(target, "initTelegramInfo", "", ""); assertTrue(target.isTelegramInfoError()); assertEquals(0, target.getTelegramInfoMap().size()); } } @Test void initTelegramInfo11() { assertTrue(target.isTelegramInfoError()); verify(messageSource, times(1)).getMessage(MqSpringMessageId.SYS7081E); } }