package com.malk.harrison.config;

import org.junit.Test;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;

/**
 * Harrison 环境配置绑定测试。
 */
public class HarrisonConfigTest {

    @Test
    public void bind_nestedCredentials_returnsConfiguredValues() {
        Map<String, Object> properties = new HashMap<>();
        properties.put("harrison.xiangyu.base-url", "https://example.test/api");
        properties.put("harrison.xiangyu.system", "system-test");
        properties.put("harrison.xiangyu.secure", "secure-test");
        properties.put("harrison.xiangyu.api-key", "api-key-test");
        properties.put("harrison.yida.app-type", "APP_TEST");
        properties.put("harrison.yida.system-token", "token-test");

        HarrisonConfig config = new Binder(new MapConfigurationPropertySource(properties))
                .bind("harrison", Bindable.of(HarrisonConfig.class))
                .get();

        assertEquals("https://example.test/api", config.getXiangyu().getBaseUrl());
        assertEquals("system-test", config.getXiangyu().getSystem());
        assertEquals("secure-test", config.getXiangyu().getSecure());
        assertEquals("api-key-test", config.getXiangyu().getApiKey());
        assertEquals("APP_TEST", config.getYida().getAppType());
        assertEquals("token-test", config.getYida().getSystemToken());
    }
}
