From 2efaf52caa8c42ec30ba9967c5f5841e874e22f4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 20 Nov 2017 15:04:38 +0300 Subject: fix api and www tests --- .../test/java/com/juick/api/tests/MessagesTests.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'juick-api') 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 tagsFromApi = jsonMapper.readValue(result.getResponse().getContentAsString(), + new TypeReference>(){}); + 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 ugnichTagsFromApi = jsonMapper.readValue(result2.getResponse().getContentAsString(), + new TypeReference>(){}); + TagStats yoUgnichStats = ugnichTagsFromApi.stream().filter(t -> t.getTag().getName().equals("yo")).findFirst().get(); + assertThat(yoUgnichStats.getUsageCount(), is(1)); } @Test -- cgit v1.2.3