package com.malk.guangming.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;

/**
 * 光明环境配置绑定测试。
 */
public class GuangmingConfigTest {

    @Test
    public void bind_nestedCredentials_returnsConfiguredValues() {
        Map<String, Object> properties = new HashMap<>();
        properties.put("guangming.dingtalk.app-key", "app-key-test");
        properties.put("guangming.dingtalk.app-secret", "app-secret-test");
        properties.put("guangming.dingtalk.corp-id", "corp-test");
        properties.put("guangming.mail-sso.sso-url", "https://mail.example.test/sso");
        properties.put("guangming.mail-sso.public-key", "public-key-test");

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

        assertEquals("app-key-test", config.getDingtalk().getAppKey());
        assertEquals("app-secret-test", config.getDingtalk().getAppSecret());
        assertEquals("corp-test", config.getDingtalk().getCorpId());
        assertEquals("https://mail.example.test/sso", config.getMailSso().getSsoUrl());
        assertEquals("public-key-test", config.getMailSso().getPublicKey());
    }
}
