fix(selfop): remove obsolete execution binding on config refresh
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
package com.baiyue.lastleg.selfoperated.analytics.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.BindException;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.env.YamlPropertySourceLoader;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import java.util.Map;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SelfopAnalyticsPropertiesBindingTest {
|
||||
StandardEnvironment environment() throws Exception {
|
||||
var env=new StandardEnvironment();
|
||||
for(var source:new YamlPropertySourceLoader().load("application",new ClassPathResource("application.yml")))env.getPropertySources().addLast(source);
|
||||
env.getPropertySources().addFirst(new MapPropertySource("runtime",Map.of(
|
||||
"baiyue.self-operated-analytics.collection-mode","BUSINESS",
|
||||
"baiyue.self-operated-analytics.environment","test",
|
||||
"baiyue.self-operated-analytics.inventory-history-enabled",true)));
|
||||
return env;
|
||||
}
|
||||
@Test void refreshingRunningBusinessBeanBindsHistoryFlagWithoutDerivedExecutionInput() throws Exception {
|
||||
var config=new SelfopAnalyticsProperties();config.setCollectionMode("BUSINESS");
|
||||
var env=environment();
|
||||
assertNull(env.getProperty("baiyue.self-operated-analytics.execution-enabled"));
|
||||
Binder.get(env).bind("baiyue.self-operated-analytics",Bindable.ofInstance(config));
|
||||
assertTrue(config.isInventoryHistoryEnabled());assertTrue(config.isExecutionEnabled());
|
||||
Binder.get(env).bind("baiyue.self-operated-analytics",Bindable.ofInstance(config));
|
||||
assertTrue(config.isInventoryHistoryEnabled());assertTrue(config.isExecutionEnabled());
|
||||
}
|
||||
@Test void obsoleteFalseInputReproducesTheRefreshFailure() throws Exception {
|
||||
var config=new SelfopAnalyticsProperties();config.setCollectionMode("BUSINESS");
|
||||
var env=environment();env.getPropertySources().addFirst(new MapPropertySource("obsolete",Map.of("baiyue.self-operated-analytics.execution-enabled",false)));
|
||||
assertThrows(BindException.class,()->Binder.get(env).bind("baiyue.self-operated-analytics",Bindable.ofInstance(config)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user