Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

fix flaky behavior in top30_검증 when asserting json list #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.moment.the.controller.release;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.moment.the.uncomfortable.UncomfortableDomain;
import com.moment.the.uncomfortable.controller.UncomfortableController;
Expand All @@ -23,6 +25,8 @@

import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
Expand All @@ -32,6 +36,7 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.junit.jupiter.api.Assertions.*;


@SpringBootTest
Expand Down Expand Up @@ -65,7 +70,9 @@ void showRequestResponse() throws Exception {
}

String objectToJson(Object object) throws JsonProcessingException {
return new ObjectMapper().writeValueAsString(object);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
return objectMapper.writeValueAsString(object);
}

@Test @DisplayName("[POST]/v1/uncomfortable write 검증")
Expand Down Expand Up @@ -146,8 +153,19 @@ String objectToJson(Object object) throws JsonProcessingException {
//Then
resultActions
.andExpect(status().is2xxSuccessful())
.andExpect(content().string(containsString(top30Data)))
;
.andDo(mvcResult -> {
String contentString = mvcResult.getResponse().getContentAsString();
ObjectMapper objectMapper = new ObjectMapper();
HashMap expectedResponse = objectMapper.readValue(contentString, HashMap.class);
ObjectMapper objectToStringMapper = new ObjectMapper();
objectToStringMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
List<String> expectedSortedJsonList = new ArrayList<String>();
for (Object o : (List<Object[]>) expectedResponse.get("list")) {
expectedSortedJsonList.add(objectToStringMapper.writeValueAsString(o));
}
assertEquals('[' + String.join(",", expectedSortedJsonList) + ']', top30Data);
}
);
}
@Test @DisplayName("[PUT]/v1/uncomfortable/{uncomfortable} goods 추가")
void goods_검증() throws Exception {
Expand Down