✅Test: 在 Lark 中使用天气服务
This commit is contained in:
@@ -33,6 +33,12 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hezhaohui</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package cn.hezhaohui.lark.client;
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@FeignClient(name = "service-weather")
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
|
||||
public interface WeatherClient {
|
||||
|
||||
@GetMapping("get")
|
||||
Weather getWeather();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
public class WeatherClientImpl implements WeatherClient {
|
||||
|
||||
|
||||
@Override
|
||||
public Weather getWeather() {
|
||||
String ans = HttpUtil.get("http://localhost:8083/get");
|
||||
Weather weather = JSONUtil.toBean(ans, Weather.class);
|
||||
return weather;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.hezhaohui.lark.client.impl;
|
||||
|
||||
import cn.hezhaohui.entity.Weather;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
class WeatherClientImplTest {
|
||||
|
||||
@Resource
|
||||
private WeatherClient weatherClient;
|
||||
|
||||
@Test
|
||||
void getWeather() {
|
||||
Weather weather = weatherClient.getWeather();
|
||||
log.info(weather.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user