diff options
author | Vitaly Takmazov | 2017-11-20 15:04:38 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-11-20 15:04:38 +0300 |
commit | 2efaf52caa8c42ec30ba9967c5f5841e874e22f4 (patch) | |
tree | 6b55600860170307d1cae46e62c8706051fc11e6 /juick-api | |
parent | 3f7645e8547f9215342b5c235177e381522154ad (diff) |
fix api and www tests
Diffstat (limited to 'juick-api')
-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 |