package com.ruoyi.system.omgpay.service; import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.Reader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.Properties; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; class OmgPaymentAttemptI18nContractTest { private static final List OMG_KEYS = List.of( "omg.payment.ddid.required", "omg.payment.merchantTradeNo.required", "omg.payment.storeId.required", "omg.payment.merchantId.required", "omg.payment.amount.invalid" ); @Test void omgValidationKeysResolveInAllBundlesAndBoundaryIsSeparated() throws IOException { for (Path bundle : allBundles()) { Properties properties = loadProperties(bundle); for (String key : OMG_KEYS) { assertNotNull(properties.getProperty(key), () -> bundle.getFileName() + " should resolve " + key); } } for (Path bundle : malformedBoundaryBundles()) { String normalized = Files.readString(bundle, StandardCharsets.UTF_8).replace("\r\n", "\n"); assertTrue(normalized.contains("\n\nomg.payment.ddid.required="), () -> bundle.getFileName() + " should start OMG keys on a separated block boundary"); } } private static Properties loadProperties(Path bundle) throws IOException { Properties properties = new Properties(); try (Reader reader = Files.newBufferedReader(bundle, StandardCharsets.UTF_8)) { properties.load(reader); } return properties; } private static List allBundles() { return List.of( bundle("messages.properties"), bundle("messages_en_US.properties"), bundle("messages_vi.properties"), bundle("messages_zh_CN.properties"), bundle("messages_zh_TW.properties") ); } private static List malformedBoundaryBundles() { return List.of( bundle("messages.properties"), bundle("messages_zh_CN.properties"), bundle("messages_zh_TW.properties") ); } private static Path bundle(String name) { return Paths.get("..", "ruoyi-admin", "src", "main", "resources", "i18n", name); } }