refactor: remove generic mqtt enable alias
This commit is contained in:
@@ -14,8 +14,7 @@ final class MqttInboundEnabledCondition implements Condition {
|
|||||||
if (direct != null) {
|
if (direct != null) {
|
||||||
return direct;
|
return direct;
|
||||||
}
|
}
|
||||||
return isTrue(env.getProperty("MQTT_ENABLED"))
|
return isTrue(env.getProperty("YUTONG_MQTT_ENABLED"));
|
||||||
|| isTrue(env.getProperty("YUTONG_MQTT_ENABLED"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isTrue(String value) {
|
private static boolean isTrue(String value) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user