diff options
Diffstat (limited to 'juick-api/src')
-rw-r--r-- | juick-api/src/test/java/com/juick/api/tests/MessagesTests.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java index 35f09314..07e649ec 100644 --- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java +++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java @@ -27,6 +27,7 @@ import com.juick.api.configuration.ApiAppConfiguration; import com.juick.api.configuration.ApiSecurityConfig; import com.juick.api.tests.configuration.MockStorageConfiguration; import com.juick.configuration.RepositoryConfiguration; +import com.juick.server.helpers.TagStats; import com.juick.service.ImagesService; import com.juick.service.MessagesService; import com.juick.service.TagService; @@ -214,15 +215,21 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { Tag yo = tagService.getTag("yo", true); messagesService.createMessage(ugnich.getUid(), "text", null, Arrays.asList(yo, weather)); messagesService.createMessage(freefd.getUid(), "text2", null, Collections.singletonList(yo)); - mockMvc.perform(get("/tags")) + MvcResult result = mockMvc.perform(get("/tags")) .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(2))) - .andExpect(jsonPath("$[0].messages", is(2))); - mockMvc.perform(get("/tags") + .andReturn(); + List<TagStats> tagsFromApi = jsonMapper.readValue(result.getResponse().getContentAsString(), + new TypeReference<List<TagStats>>(){}); + TagStats yoStats = tagsFromApi.stream().filter(t -> t.getTag().getName().equals("yo")).findFirst().get(); + assertThat(yoStats.getUsageCount(), is(2)); + MvcResult result2 = mockMvc.perform(get("/tags") .param("user_id", String.valueOf(ugnich.getUid()))) .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(2))) - .andExpect(jsonPath("$[0].messages", is(1))); + .andReturn(); + List<TagStats> ugnichTagsFromApi = jsonMapper.readValue(result2.getResponse().getContentAsString(), + new TypeReference<List<TagStats>>(){}); + TagStats yoUgnichStats = ugnichTagsFromApi.stream().filter(t -> t.getTag().getName().equals("yo")).findFirst().get(); + assertThat(yoUgnichStats.getUsageCount(), is(1)); } @Test |