diff options
author | Vitaly Takmazov | 2017-11-13 15:23:06 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-11-13 15:23:06 +0300 |
commit | fc77902b14c16e7c911a0f2fe6a73e69b252f699 (patch) | |
tree | 4e86783db9b588af9f98a8a3e56a48be7a6d53a5 /juick-api/src/test/java | |
parent | 4f32ea8c6889be56861a290e633a89c5b6740e3a (diff) |
notifications: moved top service from cron
Diffstat (limited to 'juick-api/src/test/java')
-rw-r--r-- | juick-api/src/test/java/com/juick/api/tests/MessagesTests.java | 25 |
1 files changed, 24 insertions, 1 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 13d399ca..35f09314 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 @@ -24,6 +24,7 @@ import com.juick.Message; import com.juick.Tag; import com.juick.User; 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.service.ImagesService; @@ -51,6 +52,7 @@ import javax.inject.Inject; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.stream.IntStream; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -62,7 +64,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * Created by vitalyster on 25.11.2016. */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {RepositoryConfiguration.class, ApiAppConfiguration.class, MockStorageConfiguration.class}) +@ContextConfiguration(classes = {ApiAppConfiguration.class, ApiSecurityConfig.class, RepositoryConfiguration.class, MockStorageConfiguration.class}) @WebAppConfiguration public class MessagesTests extends AbstractJUnit4SpringContextTests { @@ -84,6 +86,7 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { private static User ugnich, freefd, juick; static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword; static Message msg; + static int juickTagId; private static boolean isSetUp = false; @@ -112,6 +115,8 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { int mid = messagesService.createMessage(ugnich.getUid(), msgText, "png", null); msg = messagesService.getMessage(mid); + tagService.createTag("ัะตัั"); + juickTagId = tagService.createTag("juick"); isSetUp = true; } } @@ -281,4 +286,22 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsBytes(tokens))).andExpect(status().isOk()); } + @Test + public void topTest() throws Exception { + int topmid = messagesService.createMessage(ugnich.getUid(), "top message", null, null); + IntStream.rangeClosed(6, 12).forEach(i -> { + messagesService.createReply(topmid, 0, i, "yo", null); + }); + mockMvc.perform(get("/messages/top_candidates").with(httpBasic(juickName, juickPassword)) + .contentType(MediaType.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$[0]", is(topmid))); + Tag juickTag = tagService.getTag(juickTagId); + assertThat(juickTag.TID, is(2)); + tagService.updateTags(topmid, Collections.singletonList(juickTag)); + mockMvc.perform(get("/messages/top_candidates").with(httpBasic(juickName, juickPassword)) + .contentType(MediaType.APPLICATION_JSON_UTF8)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", hasSize(0))); + } } |