This commit is contained in:
2026-08-18 15:43:58 +08:00
parent 4e4d047862
commit 4b0b3e9172
71 changed files with 523 additions and 724 deletions
@@ -16,7 +16,7 @@ public class InboundCodeModeProvider {
private final Mode mode;
public InboundCodeModeProvider(
@Value("${baiyue.order.inbound-code-mode:LEGACY_MANUAL}") String configuredMode) {
@Value("${baiyue.order.inbound-code-mode:AUTO}") String configuredMode) {
if (!StringUtils.hasText(configuredMode)) {
throw new IllegalStateException("baiyue.order.inbound-code-mode 必须显式配置");
}
+2
View File
@@ -35,6 +35,8 @@ baiyue:
url: ${WAREHOUSE_SERVICE_URL:}
file:
url: ${FILE_SERVICE_URL:}
order:
inbound-code-mode: ${ORDER_INBOUND_CODE_MODE:AUTO}
logging:
file:
name: "${LOGGING_FILE_NAME:${LOG_PATH:./logs}/${spring.application.name}.log}"
@@ -3,21 +3,35 @@ package com.baiyue.order.config;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class InboundCodeModeProviderTest {
@Test
void springPlaceholderDefaultsToLegacyManualWhenEnvironmentPropertyIsMissing() {
void springPlaceholderDefaultsToAutoWhenEnvironmentPropertyIsMissing() {
Constructor<?> constructor = InboundCodeModeProvider.class.getDeclaredConstructors()[0];
Value value = constructor.getParameters()[0].getAnnotation(Value.class);
assertThat(value.value())
.isEqualTo("${baiyue.order.inbound-code-mode:LEGACY_MANUAL}");
assertThat(new InboundCodeModeProvider("LEGACY_MANUAL").mode())
.isEqualTo(InboundCodeModeProvider.Mode.LEGACY_MANUAL);
.isEqualTo("${baiyue.order.inbound-code-mode:AUTO}");
assertThat(new InboundCodeModeProvider("AUTO").mode())
.isEqualTo(InboundCodeModeProvider.Mode.AUTO);
}
@Test
void applicationConfigurationSupportsOrderModeEnvironmentVariableWithoutNacos() throws IOException {
String applicationYaml;
try (var stream = InboundCodeModeProviderTest.class.getResourceAsStream("/application.yml")) {
assertThat(stream).isNotNull();
applicationYaml = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
}
assertThat(applicationYaml)
.contains("inbound-code-mode: ${ORDER_INBOUND_CODE_MODE:AUTO}");
}
@Test