package tech.easyflow.autoconfig.license;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;

/**
 * {@link LicenseCanonicalJsonSerializer} 测试。
 */
public class LicenseCanonicalJsonSerializerTest {

    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    /**
     * 应按 key 递归排序对象，且保持数组顺序。
     *
     * @throws Exception 解析失败
     */
    @Test
    public void shouldSerializeCanonicalJson() throws Exception {
        JsonNode jsonNode = OBJECT_MAPPER.readTree("{\"b\":1,\"arr\":[{\"b\":2,\"a\":1},3],\"a\":{\"d\":4,\"c\":3}}");
        String canonicalJson = LicenseCanonicalJsonSerializer.serialize(jsonNode);
        Assert.assertEquals("{\"a\":{\"c\":3,\"d\":4},\"arr\":[{\"a\":1,\"b\":2},3],\"b\":1}", canonicalJson);
    }
}
