diff options
author | Vitaly Takmazov | 2018-05-17 23:18:40 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-05-17 23:18:40 +0300 |
commit | b17bf6508ef2b00fbd1ad04725ab457e0cf93831 (patch) | |
tree | 772661f08eba13623b72883bc660ec7787516668 /juick-server/src/test/java/com | |
parent | 235bb5b9fc7072531f19cc25c3b07258198d86ec (diff) |
tests refactoring
Diffstat (limited to 'juick-server/src/test/java/com')
-rw-r--r-- | juick-server/src/test/java/com/juick/server/tests/ServerTests.java | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index 924615d7f..ebca8c6cf 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -160,8 +160,7 @@ public class ServerTests { private static User ugnich, freefd, juick; static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword; - static Message msg; - static int juickTagId; + URI emptyUri = URI.create(StringUtils.EMPTY); private static boolean isSetUp = false; @@ -184,13 +183,6 @@ public class ServerTests { freefd = userService.getUserByUID(freefdId).orElseThrow(IllegalStateException::new); int juickId = userService.createUser(juickName, juickPassword); juick = userService.getUserByUID(juickId).orElseThrow(IllegalStateException::new); - - String msgText = "Привет, я - Угнич"; - CommandResult result = commandsManager.processCommand(ugnich, msgText, URI.create("http://static.juick.com/settings/facebook.png")); - int mid = result.getNewMessage().get().getMid(); - msg = messagesService.getMessage(mid); - tagService.createTag("тест"); - juickTagId = tagService.createTag("juick"); isSetUp = true; } } @@ -384,17 +376,24 @@ public class ServerTests { @Test public void homeTestWithMessages() throws Exception { + String msgText = "Привет, я - Угнич"; + CommandResult result = commandsManager.processCommand(ugnich, msgText, URI.create("http://static.juick.com/settings/facebook.png")); + int mid = result.getNewMessage().get().getMid(); + Message msg = messagesService.getMessage(mid); + tagService.createTag("тест"); mockMvc.perform( get("/home") .with(httpBasic(ugnichName, ugnichPassword))) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andExpect(jsonPath("$[-1].mid", is(msg.getMid()))) - .andExpect(jsonPath("$[-1].timestamp", + .andExpect(jsonPath("$[0].mid", is(msg.getMid()))) + .andExpect(jsonPath("$[0].timestamp", is(DateFormattersHolder.getMessageFormatterInstance().format(msg.getTimestamp())))) - .andExpect(jsonPath("$[-1].body", is(msg.getText()))) - .andExpect(jsonPath("$[-1].attachment.url", is("https://i.juick.com/p/1.png"))) - .andExpect(jsonPath("$[-1].attachment.small.url", is("https://i.juick.com/photos-512/1.png"))); + .andExpect(jsonPath("$[0].body", is(msg.getText()))) + .andExpect(jsonPath("$[0].attachment.url", + is(String.format("https://i.juick.com/p/%d.png", msg.getMid())))) + .andExpect(jsonPath("$[0].attachment.small.url", + is(String.format("https://i.juick.com/photos-512/%d.png", msg.getMid())))); } @Test @@ -564,10 +563,12 @@ public class ServerTests { } @Test public void notificationsSettingsAllowedOnlyForServiceUser() throws Exception { + CommandResult result = commandsManager.processCommand(ugnich, "yo", emptyUri); + String stringValueOfMid = String.valueOf(result.getNewMessage().get().getMid()); mockMvc.perform(get("/notifications").with(httpBasic(juickName, juickPassword)) - .param("mid", "1").param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isOk()); + .param("mid", stringValueOfMid).param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isOk()); mockMvc.perform(get("/notifications") - .param("mid", "1").param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isUnauthorized()); + .param("mid", stringValueOfMid).param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isUnauthorized()); } @Test public void topTest() { @@ -578,8 +579,10 @@ public class ServerTests { messagesService.createReply(topmid, 0, next, "yo", null); }); - assertThat(messagesService.getPopularCandidates().get(0), is(topmid)); - Tag juickTag = tagService.getTag(juickTagId); + List<Integer> topCandidates = messagesService.getPopularCandidates(); + assertThat(topCandidates.size(), is(1)); + assertThat(topCandidates.get(0), is(topmid)); + Tag juickTag = tagService.getTag("juick", false); assertThat(juickTag.TID, is(2)); tagService.updateTags(topmid, Collections.singletonList(juickTag)); assertThat(messagesService.getPopularCandidates().isEmpty(), is(true)); @@ -654,7 +657,6 @@ public class ServerTests { } @Test public void botCommandsTests() throws Exception { - URI emptyUri = URI.create(StringUtils.EMPTY); assertThat(commandsManager.processCommand(AnonymousUser.INSTANCE, "PING", emptyUri).getText(), is("PONG")); // subscription commands have two lines, others have 1 assertThat(commandsManager.processCommand(AnonymousUser.INSTANCE, "help", emptyUri).getText().split("\n").length, is(32)); |