ZCH-18 重构 Topic 对象用于处理返回和数据描述

This commit is contained in:
2023-10-04 08:07:57 -04:00
parent b911e962d8
commit ea9e13e304
3 changed files with 24 additions and 0 deletions
@@ -2,6 +2,7 @@ package com.ossez.discourse.client.service;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.ossez.discourse.common.model.dto.Topic;
import com.ossez.discourse.client.DiscourseClient;
import okhttp3.*;
@@ -42,6 +43,7 @@ public class TopicsService extends DiscourseClient {
if (response.code() == HttpStatus.SC_OK) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
discourseTopic = Optional.of(objectMapper.readValue(responseStr, Topic.class));
}
@@ -36,6 +36,8 @@ public class TopicServiceTest extends TestBase {
Optional<Topic> topic = topicsService.getTopic(DISCOURSE_TOPIC_ID);
assertThat(topic).isNotEmpty();
assertThat(topic.get().getPostStream().getPosts().size()).isGreaterThan(1);
assertThat(topic.get().getPostStream().getPosts().get(0).getId()).isEqualTo(DISCOURSE_POST_ID);
assertThat(topic.get().getId()).isEqualTo(DISCOURSE_TOPIC_ID);
assertThat(topic.get().getTitle()).isNotEmpty();
log.debug("{}", topic.get().getTitle());