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.IOException; 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.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.component.TelegramInfoComponent; import com.pgf.mqspring.model.ReceiveMapVectorRequestModel; class CharacterCodeConverterComponentImplTest01 { @Mock AmazonS3 s3Client; @Mock MqSpringMessageSourceComponent messageSource; @InjectMocks CharacterCodeConverterComponentImpl target; @BeforeEach void beforeEacn() throws IOException { MockitoAnnotations.openMocks(this); S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ClassPathResource( "com/pgf/mqspring/component/impl/CharacterCodeConverterComponentImplTest_01/ibm_telegram_info.csv") .getInputStream()); when(s3Client.getObject(anyString(), anyString())).thenReturn(s3Object); TelegramInfoComponent telegramInfoComponent = new TelegramInfoComponentImpl(s3Client, 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)); } @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)); } @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)); } @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)); } @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)); } }