| New file |
| | |
| | | package com.ruoyi.order.mapper; |
| | | |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertFalse; |
| | | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| | | |
| | | class PayOrderQueryPerformanceMapperTest { |
| | | |
| | | @Test |
| | | void readsRefundStatusFromOrderTablesWithoutJoiningRefundDetails() throws IOException { |
| | | InputStream input = getClass().getClassLoader() |
| | | .getResourceAsStream("mapper/order/TChargingOrderMapper.xml"); |
| | | assertNotNull(input); |
| | | |
| | | String mapper; |
| | | try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { |
| | | mapper = reader.lines().collect(Collectors.joining("\n")); |
| | | } |
| | | |
| | | String payOrderQuery = mapper.substring( |
| | | mapper.indexOf("<select id=\"payOrderQuery\""), |
| | | mapper.indexOf("<select id=\"getRefundList\"")); |
| | | assertEquals(3, countOccurrences(payOrderQuery, "a.refund_status as refund_status")); |
| | | assertFalse(payOrderQuery.contains("t_charging_order_refund")); |
| | | assertFalse(payOrderQuery.contains("t_shopping_order_refund")); |
| | | assertFalse(payOrderQuery.contains("t_vip_order_refund")); |
| | | } |
| | | |
| | | private int countOccurrences(String text, String target) { |
| | | int count = 0; |
| | | int index = 0; |
| | | while ((index = text.indexOf(target, index)) >= 0) { |
| | | count++; |
| | | index += target.length(); |
| | | } |
| | | return count; |
| | | } |
| | | } |