package com.pgf.mqspring.component.impl; import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import javax.xml.bind.DatatypeConverter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; 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.component.TelegramInfoComponent; import com.pgf.mqspring.model.ReceiveMapVectorRequestModel; class CharacterCodeConverterComponentImplTest01 { @Mock MqSpringMessageSourceComponent messageSource; @InjectMocks CharacterCodeConverterComponentImpl target; @BeforeEach void beforeEacn() throws IOException { MockitoAnnotations.openMocks(this); String csvPath = "C:\\pleiades\\2022-12\\workspace_PGF\\mq-spring\\src\\test\\resources\\com\\pgf\\mqspring\\component\\impl\\CharacterCodeConverterComponentImplTest_01\\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(); TelegramInfoComponent telegramInfoComponent = new TelegramInfoComponentImpl(messageSource, "", ""); ReflectionTestUtils.setField(target, "telegramInfoComponent", telegramInfoComponent); } } @Test void encodeVectorData01() { ReceiveMapVectorRequestModel model = new ReceiveMapVectorRequestModel(); model.setVectorDescriptor("1802"); model.setVectorType("I"); model.setVectorVersion("00000001"); model.setRmTransmitSendAreas("Y"); model.setRmMapset("MUT0100"); model.setRmMap("MUT0100"); model.setRmAid("DFHPF8"); model.setRmCposn("0"); byte[] vectorDescriptor = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "1802", 4, false); byte[] vectorType = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "I", 1, false); byte[] vectorVersion = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "00000001", 7, false); byte[] rmTransmitSendAreas = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "Y", 4, false); byte[] rmMapset = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0100", 8, false); byte[] rmMap = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0100", 8, false); byte[] rmAid = { -8, 64, 64, 64 }; byte[] rmCposn = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "0", 4, false); byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)), vectorDescriptor, vectorType, vectorVersion, rmTransmitSendAreas, rmMapset, rmMap, rmAid, rmCposn, DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)) }); assertArrayEquals(expected, target.encodeVectorData("UT01", model, 0, true)); } @Test void encodeVectorData02() { ReceiveMapVectorRequestModel model = new ReceiveMapVectorRequestModel(); model.setVectorDescriptor("1802"); model.setVectorType("I"); model.setVectorVersion("00000001"); model.setRmTransmitSendAreas("Y"); model.setRmMapset("MUT0200"); model.setRmMap("MUT0200"); model.setRmAid("DFHPF10"); model.setRmCposn("0"); byte[] vectorDescriptor = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "1802", 4, false); byte[] vectorType = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "I", 1, false); byte[] vectorVersion = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "00000001", 7, false); byte[] rmTransmitSendAreas = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "Y", 4, false); byte[] rmMapset = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0200", 8, false); byte[] rmMap = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0200", 8, false); byte[] rmAid = { 122, 64, 64, 64 }; byte[] rmCposn = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "0", 4, false); byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)), vectorDescriptor, vectorType, vectorVersion, rmTransmitSendAreas, rmMapset, rmMap, rmAid, rmCposn, DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)) }); assertArrayEquals(expected, target.encodeVectorData("UT02", model, 0, true)); } @Test void encodeVectorData03() { ReceiveMapVectorRequestModel model = new ReceiveMapVectorRequestModel(); model.setVectorDescriptor("1802"); model.setVectorType("I"); model.setVectorVersion("00000001"); model.setRmTransmitSendAreas("Y"); model.setRmMapset("MUT0300"); model.setRmMap("MUT0300"); model.setRmAid("DFHENTER"); model.setRmCposn("0"); byte[] vectorDescriptor = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "1802", 4, false); byte[] vectorType = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "I", 1, false); byte[] vectorVersion = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "00000001", 7, false); byte[] rmTransmitSendAreas = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "Y", 4, false); byte[] rmMapset = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0300", 8, false); byte[] rmMap = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0300", 8, false); byte[] rmAid = { 125, 64, 64, 64 }; byte[] rmCposn = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "0", 4, false); byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)), vectorDescriptor, vectorType, vectorVersion, rmTransmitSendAreas, rmMapset, rmMap, rmAid, rmCposn, DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)) }); assertArrayEquals(expected, target.encodeVectorData("UT03", model, 0, true)); } @Test void encodeVectorData04() { ReceiveMapVectorRequestModel model = new ReceiveMapVectorRequestModel(); model.setVectorDescriptor("1802"); model.setVectorType("I"); model.setVectorVersion("00000001"); model.setRmTransmitSendAreas("Y"); model.setRmMapset("MUT0400"); model.setRmMap("MUT0400"); model.setRmAid("DFHENTER_"); model.setRmCposn("0"); byte[] vectorDescriptor = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "1802", 4, false); byte[] vectorType = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "I", 1, false); byte[] vectorVersion = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "00000001", 7, false); byte[] rmTransmitSendAreas = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "Y", 4, false); byte[] rmMapset = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0400", 8, false); byte[] rmMap = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0400", 8, false); byte[] rmAid = { 125, 64, 64, 64 }; byte[] rmCposn = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "0", 4, false); byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)), vectorDescriptor, vectorType, vectorVersion, rmTransmitSendAreas, rmMapset, rmMap, rmAid, rmCposn, DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)) }); assertArrayEquals(expected, target.encodeVectorData("UT04", model, 0, true)); } @Test void encodeVectorData05() { ReceiveMapVectorRequestModel model = new ReceiveMapVectorRequestModel(); model.setVectorDescriptor("1802"); model.setVectorType("I"); model.setVectorVersion("00000001"); model.setRmTransmitSendAreas("Y"); model.setRmMapset("MUT0500"); model.setRmMap("MUT0500"); model.setRmAid("DFHPF8"); model.setRmCposn(""); byte[] vectorDescriptor = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "1802", 4, false); byte[] vectorType = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "I", 1, false); byte[] vectorVersion = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "00000001", 7, false); byte[] rmTransmitSendAreas = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "Y", 4, false); byte[] rmMapset = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0500", 8, false); byte[] rmMap = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0500", 8, false); byte[] rmAid = { -8, 64, 64, 64 }; byte[] rmCposn = new byte[4]; byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)), vectorDescriptor, vectorType, vectorVersion, rmTransmitSendAreas, rmMapset, rmMap, rmAid, rmCposn, DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)) }); assertArrayEquals(expected, target.encodeVectorData("UT05", model, 0, true)); } @Test void encodeVectorData06() { ReceiveMapVectorRequestModel model = new ReceiveMapVectorRequestModel(); model.setVectorDescriptor("1802"); model.setVectorType("I"); model.setVectorVersion("00000001"); model.setRmTransmitSendAreas("Y"); model.setRmMapset("MUT0500"); model.setRmMap("MUT0500"); model.setRmAid("DFHPF8"); model.setRmCposn(""); byte[] vectorDescriptor = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "1802", 4, false); byte[] vectorType = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "I", 1, false); byte[] vectorVersion = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "00000001", 7, false); byte[] rmTransmitSendAreas = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "Y", 4, false); byte[] rmMapset = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0500", 8, false); byte[] rmMap = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0500", 8, false); byte[] rmAid = { -8, 64, 64, 64 }; byte[] rmCposn = new byte[4]; byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { DatatypeConverter.parseHexBinary(String.format("%08x", 0)), vectorDescriptor, vectorType, vectorVersion, rmTransmitSendAreas, rmMapset, rmMap, rmAid, rmCposn, DatatypeConverter.parseHexBinary(String.format("%08x", 0)) }); assertArrayEquals(expected, target.encodeVectorData("UT06", model, 0, false)); } @Test void encodeVectorData07() { ReceiveMapVectorRequestModel model = new ReceiveMapVectorRequestModel(); model.setVectorDescriptor("1802"); model.setVectorType("I"); model.setVectorVersion("00000001"); model.setRmTransmitSendAreas("Y"); model.setRmMapset("MUT0700"); model.setRmMap("MUT0700"); model.setRmAid("DFHPF5"); model.setRmCposn("0"); byte[] vectorDescriptor = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "1802", 4, false); byte[] vectorType = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "I", 1, false); byte[] vectorVersion = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "00000001", 7, false); byte[] rmTransmitSendAreas = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "Y", 4, false); byte[] rmMapset = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0700", 8, false); byte[] rmMap = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0700", 8, false); byte[] rmAid = { -11, 64, 64, 64 }; byte[] rmCposn = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "0", 4, false); byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)), vectorDescriptor, vectorType, vectorVersion, rmTransmitSendAreas, rmMapset, rmMap, rmAid, rmCposn, DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)) }); assertArrayEquals(expected, target.encodeVectorData("UT07", model, 0, true)); } @Test void encodeVectorData08() { ReceiveMapVectorRequestModel model = new ReceiveMapVectorRequestModel(); model.setVectorDescriptor("1802"); model.setVectorType("I"); model.setVectorVersion("00000001"); model.setRmTransmitSendAreas("Y"); model.setRmMapset("MUT0800"); model.setRmMap("MUT0800"); model.setRmAid("DFHPF1"); model.setRmCposn("0"); byte[] vectorDescriptor = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "1802", 4, false); byte[] vectorType = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "I", 1, false); byte[] vectorVersion = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "00000001", 7, false); byte[] rmTransmitSendAreas = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "Y", 4, false); byte[] rmMapset = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0800", 8, false); byte[] rmMap = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "MUT0800", 8, false); byte[] rmAid = { -15, 64, 64, 64 }; byte[] rmCposn = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "encodeStringData", "0", 4, false); byte[] expected = ReflectionTestUtils.invokeMethod(CharacterCodeConverterComponentImpl.class, "concatByteArrays", (Object) new byte[][] { DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)), vectorDescriptor, vectorType, vectorVersion, rmTransmitSendAreas, rmMapset, rmMap, rmAid, rmCposn, DatatypeConverter.parseHexBinary(String.format("%08x", 12 + 8 + 5 + 7 + 5)) }); assertArrayEquals(expected, target.encodeVectorData("UT08", model, 0, true)); } }