mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
create test for MetaMap
This commit is contained in:
parent
d0434ef05e
commit
5a8f5aa29c
@ -5,6 +5,7 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.config.preprocessor.MetaListPreprocessor;
|
||||
import com.dfsek.terra.config.preprocessor.MetaMapPreprocessor;
|
||||
import com.dfsek.terra.config.preprocessor.MetaValuePreprocessor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -26,12 +27,36 @@ public class MetaTest {
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
|
||||
|
||||
loader.load(new ConfigTest(), meta).list.forEach(System.out::println);
|
||||
loader.load(new MetaListConfig(), meta).list.forEach(System.out::println);
|
||||
}
|
||||
|
||||
private static final class ConfigTest implements ConfigTemplate {
|
||||
private static final class MetaListConfig implements ConfigTemplate {
|
||||
@Value("list")
|
||||
private @Meta List<@Meta String> list;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetaMap() {
|
||||
Configuration meta = new YamlConfiguration(MetaTest.class.getResourceAsStream("/meta.yml"), "meta.yml");
|
||||
Configuration metaTarget = new YamlConfiguration(MetaTest.class.getResourceAsStream("/metaTarget.yml"), "metaTarget.yml");
|
||||
|
||||
Map<String, Configuration> configurationMap = new HashMap<>();
|
||||
|
||||
configurationMap.put(meta.getName(), meta);
|
||||
configurationMap.put(metaTarget.getName(), metaTarget);
|
||||
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
|
||||
|
||||
loader.load(new MetaMapConfig(), meta).map.forEach((k, v) -> System.out.println(k + ": " + v));
|
||||
}
|
||||
|
||||
private static final class MetaMapConfig implements ConfigTemplate {
|
||||
@Value("map")
|
||||
private @Meta Map<@Meta String, @Meta String> map;
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,10 @@ list:
|
||||
- SIX
|
||||
- "<< metaTarget.yml:list2"
|
||||
- NINE
|
||||
- TEN
|
||||
- TEN
|
||||
map:
|
||||
"<<":
|
||||
- metaTarget.yml:map1
|
||||
- metaTarget.yml:map2
|
||||
one: ONE
|
||||
two: TWO
|
@ -3,4 +3,10 @@ list:
|
||||
- THREE
|
||||
list2:
|
||||
- SEVEN
|
||||
- EIGHT
|
||||
- EIGHT
|
||||
map1:
|
||||
three: THREE
|
||||
four: FOUR
|
||||
five: FIVE
|
||||
map2:
|
||||
six: SIX
|
Loading…
x
Reference in New Issue
Block a user