package com.nokia.sms.service;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

@Slf4j
class OtherTest {
    @Test
    void test() {
        String url = "http://localhost:12080/api/sms/sendByPhoneNumber";
        CompletableFuture.allOf(Stream.iterate(1L, n -> n + 1).limit(10).map(t ->
                CompletableFuture.runAsync(() -> {
                    RestTemplate template = new RestTemplate();
                    Map<Object, Object> m = new HashMap<>();
                    m.put("fromSystem", "test");
                    m.put("smsType", "test");
                    m.put("internalId", "000001");
                    m.put("phoneNumber", RandomUtil.randomLong(13000000000L, 13999999999L));
                    m.put("content", "测试" + IdUtil.fastSimpleUUID());
                    log.info("m: {}", JSON.toJSONString(m));
                    try {
                        ResponseEntity<Object> r = template.postForEntity(url, m, Object.class);
                        log.info("{} -> {}", r.getStatusCodeValue(), r.getBody());
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                    }
                })).toArray(CompletableFuture[]::new)).join();
    }
}
