package com.qmth.boot.test.solar;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qmth.boot.core.solar.model.AppLicense;
import com.qmth.boot.tools.crypto.RSA;
import com.qmth.boot.tools.device.DeviceInfo;
import com.qmth.boot.tools.models.ByteArray;
import org.junit.Assert;

import java.io.File;

public class AppLicenseUtilTest {

    //@Test
    public void testDeviceInfo() throws Exception {
        RSA.getPublicKey(ByteArray.fromFile(new File("/Users/luoshi/Downloads/ops/rsa/test/test-public.key")).value())
                .encrypt(new ObjectMapper().writeValueAsBytes(DeviceInfo.current()))
                .toFile(new File("/Users/luoshi/Downloads/solar/device-test.info"));
    }

    //@Test
    public void testParseAppInfo() throws JsonProcessingException {
        //
        String content = "{\"id\":26,\"name\":\"本地部署\",\"code\":\"markingcloud\",\"control\":{\"expireTime\":33239779200000,\"maxOnlineUserCount\":10, \"custom\":{\"extendKey\":true}},\"orgs\":[]}";
        //String content = "{\"id\":26,\"name\":\"本地部署\",\"code\":\"markingcloud\",\"control\":{\"expireTime\":33239779200000,\"maxOnlineUserCount\":10},\"orgs\":[]}";
        ObjectMapper mapper = new ObjectMapper();
        AppLicense license = mapper.readValue(content, AppLicense.class);
        Assert.assertNotNull(license);
        Assert.assertEquals(26, (long) license.getId());
        Assert.assertTrue(license.getControl().exceedOnlineUserCount(20));
        //Assert.assertNotNull(license.getControl().getCustomParam("extendKey"));
    }
}
