package com.pgf.mqspring.service.impl; import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.jms.BytesMessage; import javax.jms.ConnectionFactory; import javax.jms.JMSContext; import javax.jms.JMSException; import javax.jms.JMSProducer; import javax.jms.Queue; import javax.xml.bind.DatatypeConverter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.springframework.jms.core.JmsTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; import com.ibm.mq.headers.MQCIH; import com.pgf.mqspring.component.CharacterCodeConverterComponent; import com.pgf.mqspring.component.MqSpringMessageSourceComponent; import com.pgf.mqspring.component.TelegramInfoComponent; import com.pgf.mqspring.constant.MqSpringMessageId; import com.pgf.mqspring.exception.MqSpringException; import com.pgf.mqspring.model.MqcihRequestModel; import com.pgf.mqspring.model.MqmdRequestModel; import com.pgf.mqspring.model.ReceiveMapVectorRequestModel; import com.pgf.mqspring.model.ReplyRequestModel; import com.pgf.mqspring.model.SendMessageRequestModel; import com.pgf.mqspring.model.TelegramInfoModel; @ExtendWith(SpringExtension.class) class MqSendServiceImplTest01 { @Mock JmsTemplate jmsTemplate; @Mock JMSProducer jmsProducer; @Mock ConnectionFactory connectionFactory; @Mock JMSContext jMSContext; @Mock Queue queue; @Mock BytesMessage bytesMessage; @Mock MQCIH cih; @Mock TelegramInfoComponent telegramInfoComponent; @Mock CharacterCodeConverterComponent characterCodeConverter; @Mock MqSpringMessageSourceComponent messageSource; @InjectMocks MqSendServiceImpl mqSendService; private ReplyRequestModel replyRequestModel; @BeforeEach public void beforeEacn() throws JMSException { MockitoAnnotations.openMocks(this); replyRequestModel = getReplyRequestModel(); Map> telegramInfoMap = getTelegramInfoMap(); Mockito.when(telegramInfoComponent.getTelegramInfoMap()).thenReturn(telegramInfoMap); byte[] bytesVector = {6, -13, -15, -8, -16, -14, -55, -16, -16, -16, -16, -16, -16, -16, -24, 64, 64, 64, -44, -59, -44, -16, -12, -16, -16, 64, -44, -59, -44, -16, -12, -16, -16, 64, 125, 64, 64, 64, 0, 0, 0, 0, 6, -61}; Mockito.when(characterCodeConverter.encodeVectorData(Mockito.anyString(), Mockito.any(), Mockito.anyInt())). thenReturn(bytesVector); byte[] bytesAds = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -52, 0, 0, -59, -44, -16, -12, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, -8, -7, -9, -12, -8, -10, -12, -14, -7, -15, 0, 0, -52, 0, 0, -14, -16, -14, -11, -16, -12, -13, -16, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 0, 0, -52, 0, 0, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, -52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Mockito.when(characterCodeConverter.encodeAdsData(Mockito.anyString(), Mockito.anyString())).thenReturn(bytesAds); Mockito.when(jmsTemplate.getConnectionFactory()).thenReturn(connectionFactory); Mockito.when(connectionFactory.createContext()).thenReturn(jMSContext); Mockito.when(jMSContext.createProducer()).thenReturn(jmsProducer); Mockito.when(jMSContext.createQueue(Mockito.anyString())).thenReturn(queue); Mockito.when(jMSContext.createBytesMessage()).thenReturn(bytesMessage); String body = "c3c9c84000000002000000b40000000000000000c3e2d8c3c2c4c3d600000000000000000000000000000000000001110002bf2000000002000001d4000000b4000000000000000000010000016800020000000200000000404040405c5c5c5c5c5c5c5c40404040404040404040404040404040c3c9f1f840404040c7c5f0f240404040404040404040404040404040c7c5f0f240404040404040404040404040404040000000000000000000000003000000000000011ef1f8f0f4d6404040f0f0f0f0c5404040d5404040e8404040d5404040d5404040d5404040d5404040ffffffff00000000d4c7c5f0f2f0f040d4c7c5f0f2f0f040d5404040000000c600000058000000000000011e000000000000000000000000000000000040404040404040400000000000f1f061f1f761f2f200000000000000000000000000004040404040404040404040404040404040404040404040404040404040404040404040404040404040400000000000f1f07af5f97af5f2ffffc100004040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; byte[] bytesBm = DatatypeConverter.parseHexBinary(body); Mockito.when(bytesMessage.getBody(byte[].class)).thenReturn(bytesBm); } @Test void sendMqMessage01() { mqSendService.sendMqMessage(replyRequestModel); assertTrue(true); } @Test void sendMqMessage02() { Mockito.when(characterCodeConverter.encodeVectorData(Mockito.anyString(), Mockito.any(), Mockito.anyInt())). thenReturn(null); Mockito.when(characterCodeConverter.encodeAdsData(Mockito.anyString(), Mockito.anyString())).thenReturn(null); mqSendService.sendMqMessage(replyRequestModel); assertTrue(true); } @Test void sendMqMessage03() { replyRequestModel.getSendMessage().setReceiveMapVector(null); replyRequestModel.getSendMessage().setAds(null); Mockito.when(characterCodeConverter.encodeVectorData(Mockito.anyString(), Mockito.any(), Mockito.anyInt())). thenReturn(null); Mockito.when(characterCodeConverter.encodeAdsData(Mockito.anyString(), Mockito.anyString())).thenReturn(null); mqSendService.sendMqMessage(replyRequestModel); assertTrue(true); } // 運用上Nullが渡ることはあり得ないため実施不要 // @Test // void sendMqMessage04() { // } @Test void sendMqMessage05() { replyRequestModel.getMqcih().setTransactionId(null); Mockito.when(messageSource.getMessage(Mockito.any())).thenReturn("画面コード未入力エラー。"); try { mqSendService.sendMqMessage(replyRequestModel); assertTrue(false); } catch (MqSpringException e) { assertEquals(MqSpringMessageId.SYS7027E, e.getMessageId()); } } @Test void sendMqMessage06() { replyRequestModel.getMqcih().setUowControl("test"); Mockito.when(messageSource.getMessage(Mockito.any())).thenReturn("電文の組立に失敗しました。"); try { mqSendService.sendMqMessage(replyRequestModel); assertTrue(false); } catch (MqSpringException e) { assertEquals(MqSpringMessageId.SYS7070E, e.getMessageId()); } } // JUnitテスト実施不可 // @Test // void sendMqMessage07() throws IOException { // } @Test void sendMqMessage08() { Mockito .when(characterCodeConverter.encodeVectorData(Mockito.anyString(), Mockito.any(), Mockito.anyInt())) .thenThrow(new RuntimeException(new Exception("sendMqMessage08 to error"))); Mockito.when(messageSource.getMessage(Mockito.any())).thenReturn("電文の組立に失敗しました。"); try { mqSendService.sendMqMessage(replyRequestModel); assertTrue(false); } catch (MqSpringException e) { assertEquals(MqSpringMessageId.SYS7070E, e.getMessageId()); } } // JUnitテスト実施不可 // @Test // void sendMqMessage09() { // } // JUnitテスト実施不可 // @Test // void sendMqMessage10() { // } @Test void sendMqMessage11() { Mockito .when(jMSContext.createProducer()) .thenThrow(new RuntimeException(new Exception("sendMqMessage11 to error"))); Mockito.when(messageSource.getMessage(Mockito.any())).thenReturn("MQ送信エラー。"); try { mqSendService.sendMqMessage(replyRequestModel); assertTrue(false); } catch (MqSpringException e) { assertEquals(MqSpringMessageId.SYS7005E, e.getMessageId()); } } private ReplyRequestModel getReplyRequestModel() { MqmdRequestModel mqmd = new MqmdRequestModel(); mqmd.setFormat("MQCICS"); mqmd.setCorrelId("AMQ!NEW_SESSION_CORRELID"); mqmd.setPersistence("0"); mqmd.setExpiry(""); MqcihRequestModel mqcih = new MqcihRequestModel(); mqcih.setUowControl("273"); mqcih.setGetWaitInterval("180000"); mqcih.setLinkType("2"); mqcih.setFacilityKeepTime("180"); mqcih.setConversationalTask("0"); mqcih.setFacility("0138000100000001"); mqcih.setAutherticator("GETS3333"); mqcih.setTransactionId("EM04"); ReceiveMapVectorRequestModel receiveMapVector = new ReceiveMapVectorRequestModel(); receiveMapVector.setVectorDescriptor("1802"); receiveMapVector.setVectorType("I"); receiveMapVector.setVectorVersion("00000000"); receiveMapVector.setRmTransmitSendAreas("Y"); receiveMapVector.setRmMapset("MEM0400"); receiveMapVector.setRmMap("MEM0400"); receiveMapVector.setRmAid("DFHENTER"); receiveMapVector.setRmCposn(""); SendMessageRequestModel sendMessage = new SendMessageRequestModel(); sendMessage.setReceiveMapVector(receiveMapVector); sendMessage.setAds("EM04,,,,,,8974864291,20250430,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"); ReplyRequestModel replyRequestModel = new ReplyRequestModel(); replyRequestModel.setMqmd(mqmd); replyRequestModel.setTimeout("60000"); replyRequestModel.setMqcih(mqcih); replyRequestModel.setSendMessage(sendMessage); return replyRequestModel; } private Map> getTelegramInfoMap() { Map> telegramInfoMap = new HashMap<>(); List telInfoByDispCodeList = new ArrayList(); TelegramInfoModel telegramInfoModel = new TelegramInfoModel(); telegramInfoModel.setDispCode("EM04"); telegramInfoModel.setFieldNo("1"); telegramInfoModel.setItemName("SCRID"); telegramInfoModel.setItemLength("8"); telegramInfoModel.setCharDiv("0"); telegramInfoModel.setRepeatNum("0"); telegramInfoModel.setGroupNum("0"); telegramInfoModel.setInsDate("2010-02-28"); telInfoByDispCodeList.add(telegramInfoModel); telegramInfoMap.put("EM04", telInfoByDispCodeList); return telegramInfoMap; } }