[매입] mg_recv_svc → 전문수신 @Service (ACM-MG-004)
Some checks failed
ci / test (pull_request) Failing after 8s
Some checks failed
ci / test (pull_request) Failing after 8s
This commit is contained in:
parent
78dab9c159
commit
2eb0ef7f6e
1 changed files with 70 additions and 0 deletions
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.klaro.acquirecore.acquiring.codec;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class MessageCodecTest {
|
||||||
|
|
||||||
|
private MessageCodec codec;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
codec = new MessageCodec();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void unpack_validMessage_parsesCorrectly() {
|
||||||
|
// given
|
||||||
|
String raw = "MSGT123456789012TX01MER00001 1234567890123456789000000012340A12345678ETX";
|
||||||
|
byte[] rawMessage = raw.getBytes();
|
||||||
|
|
||||||
|
// when
|
||||||
|
ParsedMessage parsed = codec.unpack(rawMessage);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals("MSGT", parsed.getMessageType());
|
||||||
|
assertEquals("123456789012", parsed.getTxId());
|
||||||
|
assertEquals("TX01", parsed.getTxCode());
|
||||||
|
assertEquals("MER00001", parsed.getMerchantId());
|
||||||
|
assertEquals("12345678901234567890", parsed.getCardNumber());
|
||||||
|
assertEquals("0000001234", parsed.getAmount());
|
||||||
|
assertEquals("A12345678", parsed.getApprovalCode());
|
||||||
|
assertEquals("ETX", parsed.getTrailer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void unpack_nullMessage_throwsException() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> codec.unpack(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void unpack_shortMessage_throwsException() {
|
||||||
|
byte[] shortMessage = new byte[10];
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> codec.unpack(shortMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pack_validMessage_packsCorrectly() {
|
||||||
|
// given
|
||||||
|
ParsedMessage parsed = new ParsedMessage();
|
||||||
|
parsed.setMessageType("MSGT");
|
||||||
|
parsed.setTxId("123456789012");
|
||||||
|
parsed.setTxCode("TX01");
|
||||||
|
parsed.setMerchantId("MER00001");
|
||||||
|
parsed.setCardNumber("12345678901234567890");
|
||||||
|
parsed.setAmount("0000001234");
|
||||||
|
parsed.setApprovalCode("A12345678");
|
||||||
|
|
||||||
|
// when
|
||||||
|
byte[] packed = codec.pack(parsed);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertNotNull(packed);
|
||||||
|
assertTrue(packed.length > 0);
|
||||||
|
String packedStr = new String(packed);
|
||||||
|
assertTrue(packedStr.startsWith("MSGT"));
|
||||||
|
assertTrue(packedStr.endsWith("ETX"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue