From fc77902b14c16e7c911a0f2fe6a73e69b252f699 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 13 Nov 2017 15:23:06 +0300 Subject: notifications: moved top service from cron --- .../java/com/juick/api/tests/MessagesTests.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'juick-api/src/test/java') 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))); + } } -- cgit v1.2.3