package com.qiuguo.iot.third.service;

import cn.hutool.json.JSONObject;
import com.qiuguo.iot.data.request.third.ThirdWeatherInfoRequest;
import com.qiuguo.iot.data.resp.third.weather.WeatherResp;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;


/**
 * @author simon
 * @date 2023/9/21
 * @description
 **/

@SpringBootTest(classes = {WeatherService.class, IpService.class})
class WeatherServiceTest {
    @Resource
    private WeatherService weatherService;

    @Test
    void queryWeather() throws InterruptedException {
        ThirdWeatherInfoRequest thirdWeatherInfoRequest = new ThirdWeatherInfoRequest();
        thirdWeatherInfoRequest.setType(2);
        thirdWeatherInfoRequest.setSize(1);
        thirdWeatherInfoRequest.setIp("60.186.105.204");

        System.out.println(thirdWeatherInfoRequest.getIp());
        Mono<WeatherResp> jsonObjectMono = weatherService.queryWeather(thirdWeatherInfoRequest);

        jsonObjectMono.flatMap(r -> {
            System.out.println("flatMap");
            System.out.println(r.getApi_version());
            return Mono.just(r);
        }).subscribe(System.out::println);

        Thread.sleep(20000);
        System.out.println(thirdWeatherInfoRequest.getIp());
    }

    @Test
    void thirdQueryWeather() {
    }
}