refactor: remove generic mqtt enable alias

This commit is contained in:
lingniu
2026-07-01 08:56:59 +08:00
parent 9db8b15ae3
commit 7c51c83220
2 changed files with 69 additions and 2 deletions

View File

@@ -14,8 +14,7 @@ final class MqttInboundEnabledCondition implements Condition {
if (direct != null) {
return direct;
}
return isTrue(env.getProperty("MQTT_ENABLED"))
|| isTrue(env.getProperty("YUTONG_MQTT_ENABLED"));
return isTrue(env.getProperty("YUTONG_MQTT_ENABLED"));
}
private static boolean isTrue(String value) {

View File

@@ -0,0 +1,68 @@
package com.lingniu.ingest.inbound.mqtt.config;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ResourceLoader;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
class MqttInboundEnabledConditionTest {
private final MqttInboundEnabledCondition condition = new MqttInboundEnabledCondition();
@Test
void ignoresLegacyGenericMqttEnabledEnvironmentAlias() {
assertThat(condition.matches(context(Map.of("MQTT_ENABLED", "true")), null)).isFalse();
}
@Test
void acceptsYutongMqttEnabledEnvironmentAlias() {
assertThat(condition.matches(context(Map.of("YUTONG_MQTT_ENABLED", "true")), null)).isTrue();
}
@Test
void directPropertyOverridesEnvironmentAlias() {
assertThat(condition.matches(context(Map.of(
"lingniu.ingest.mqtt.enabled", "false",
"YUTONG_MQTT_ENABLED", "true")), null)).isFalse();
}
private static ConditionContext context(Map<String, Object> properties) {
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("test", properties));
return new TestConditionContext(environment);
}
private record TestConditionContext(StandardEnvironment environment) implements ConditionContext {
@Override
public BeanDefinitionRegistry getRegistry() {
return null;
}
@Override
public ConfigurableListableBeanFactory getBeanFactory() {
return null;
}
@Override
public StandardEnvironment getEnvironment() {
return environment;
}
@Override
public ResourceLoader getResourceLoader() {
return null;
}
@Override
public ClassLoader getClassLoader() {
return null;
}
}
}