From 6cd35dbc723a64720c08a331ede9e605df11b8b4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 28 Jan 2023 19:58:01 +0300 Subject: CI: enable sqlserver job --- .../java/com/juick/server/tests/ServerTests.java | 60 +++++++++------------- 1 file changed, 23 insertions(+), 37 deletions(-) (limited to 'src/test/java/com/juick/server/tests') diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index ea1e6100..1cd51f7f 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -197,8 +197,6 @@ public class ServerTests { @Inject private ActivityPubService activityPubService; @Inject - private SignatureService signatureService; - @Inject private ActivityPubManager activityPubManager; @Inject private ProfileUriBuilder profileUriBuilder; @@ -208,19 +206,8 @@ public class ServerTests { private String baseUri; @Value("${web_domain:localhost}") private String webDomain; - @Inject - private OkHttpClient apClient; - @Value("classpath:snapshots/activity/testuser.json") private Resource testuserResponse; - @Value("classpath:snapshots/activity/testapp.json") - private Resource testappResponse; - @Value("classpath:snapshots/activity/testfollow.json") - private Resource testfollowRequest; - @Value("classpath:snapshots/activity/testdelete.json") - private Resource testDeleteRequest; - @Value("classpath:snapshots/activity/test_suspended_user.json") - private Resource testSuspendedUserResponse; @Value("classpath:snapshots/email/subscription.html") private Resource testSubscriptionHtmlEmail; @Value("classpath:snapshots/email/private.html") @@ -249,30 +236,20 @@ public class ServerTests { private Resource invisiblePixel; @Value("classpath:sape.xml") private Resource sapeOutput; - @Value("classpath:flag.json") - private Resource flagPayload; @Value("classpath:friendica_update.json") private Resource friendicaUpdate; @Inject AppleClientSecretGenerator clientSecretGenerator; @Inject private Remark remarkConverter; - - @Inject - private KeystoreManager testKeystoreManager; - @Inject private ApplicationEventPublisher applicationEventPublisher; - @Inject private Users usersController; @Inject private User serviceUser; @Inject private User archiveUser; - @Inject - private ConversionService conversionService; - private static User ugnich, freefd; static String ugnichName, ugnichPassword, freefdName, freefdPassword; URI emptyUri = URI.create(StringUtils.EMPTY); @@ -382,6 +359,7 @@ public class ServerTests { @Test public void messageTests() { + deleteMessages(); User user = userService.createUser("mmmme", "secret").orElseThrow(IllegalStateException::new); assertEquals("mmmme", user.getName()); int mid = messagesService.createMessage(user.getUid(), "yo", null, Set.of()); @@ -898,8 +876,8 @@ public class ServerTests { .getUsersSubscribedToComments(messagesService.getMessage(mid).get(), messagesService.getReply(mid, rid)) .size()); - assertNotEquals("should NOT be deleted", String.format("Message %s deleted", mid), - commandsManager.processCommand(readerUser, "D #" + mid, emptyUri).getText()); + var deletion = commandsManager.processCommand(readerUser, "D #" + mid, emptyUri).getText(); + assertThat(deletion, is("This is not your message")); assertEquals("Message deleted", commandsManager.processCommand(user, "D #" + mid, emptyUri).getText()); assertEquals("Message not found", commandsManager.processCommand(user, "#" + mid, emptyUri).getText()); @@ -1039,11 +1017,18 @@ public class ServerTests { assertThat(messagesService.getMessage(mid1).get().getRecommendations().size(), is(1)); } + void deleteMessages() { + var ids = messagesService.getAll(0, 0); + var msgs = messagesService.getMessages(0, ids); + var results = msgs.stream().map(i -> messagesService.deleteMessage(i.getUser().getUid(), i.getMid())); + assertThat(results.allMatch(i -> i), is(true)); + } + @Test @Order(5) public void lastReadTests() throws Exception { jdbcTemplate.execute("DELETE FROM bl_users"); - jdbcTemplate.execute("DELETE FROM messages"); + deleteMessages(); assertThat(userService.isInBLAny(ugnich.getUid(), freefd.getUid()), is(false)); int mid = messagesService.createMessage(ugnich.getUid(), "to be watched", null, Set.of()); subscriptionService.subscribeMessage(messagesService.getMessage(mid).get(), ugnich); @@ -1616,8 +1601,9 @@ public class ServerTests { } @Test + @Order(5) public void bannedUserShouldNotBeVisibleToOthers() { - jdbcTemplate.execute("DELETE FROM messages"); + deleteMessages(); User casualUser = userService.createUser("user", "secret").orElseThrow(IllegalStateException::new); User bannedUser = userService.createUser("banned", "banned").orElseThrow(IllegalStateException::new); jdbcTemplate.update("UPDATE users SET banned=1 WHERE id=?", bannedUser.getUid()); @@ -1661,7 +1647,7 @@ public class ServerTests { .andExpect(jsonPath("$.icon.url", is(String.format(baseUri + "av-96-%s.png", hash)))) .andExpect(jsonPath("$.publicKey.publicKeyPem", is(keystoreManager.getPublicKeyPem()))); - jdbcTemplate.execute("DELETE FROM messages"); + deleteMessages(); List mids = IteratorUtils.toList(IntStream.rangeClosed(1, 30) .mapToObj( i -> messagesService.createMessage(ugnich.getUid(), @@ -1700,8 +1686,7 @@ public class ServerTests { return display == null || !display.getValue().equals("none"); }).count(); assertThat(visibleItems, equalTo(14L)); - jdbcTemplate.execute("DELETE FROM messages"); - jdbcTemplate.execute("DELETE FROM replies"); + deleteMessages(); } @Test @@ -1793,6 +1778,7 @@ public class ServerTests { } @Test + @Order(20) public void discussionsShouldBePageableByTimestamp() throws Exception { String msgText = "Привет, я снова Угнич"; int mid = messagesService.createMessage(ugnich.getUid(), msgText, null, Set.of()); @@ -1887,9 +1873,7 @@ public class ServerTests { @Test public void notificationsTests() throws Exception { - jdbcTemplate.execute("DELETE FROM messages"); - jdbcTemplate.execute("DELETE FROM replies"); - jdbcTemplate.execute("DELETE FROM subscr_messages"); + deleteMessages(); jdbcTemplate.execute("DELETE FROM bl_users"); MvcResult loginResult = mockMvc .perform(post("/login").with(csrf()).param("username", freefdName).param("password", @@ -2024,6 +2008,7 @@ public class ServerTests { @Test public void activitySerialization() throws Exception { + deleteMessages(); Message msgNoTags = commandsManager.processCommand(ugnich, "people", emptyUri).getNewMessage().get(); String json = jsonMapper.writeValueAsString(Context.build(activityPubManager.makeNote(msgNoTags))); Message msg = commandsManager.processCommand(ugnich, "*NSFW *shit happens", emptyUri).getNewMessage() @@ -2032,7 +2017,7 @@ public class ServerTests { assertThat(note.isSensitive(), is(true)); json = jsonMapper.writeValueAsString(Context.build(note)); Note replyNote = new Note(); - replyNote.setId("http://localhost:8080/n/2-1"); + replyNote.setId("http://localhost:8080/n/" + msg.getMid() + "-1"); replyNote.setInReplyTo(profileUriBuilder.messageUri(msg)); replyNote.setAttributedTo("http://localhost:8080/u/freefd"); replyNote.setTo(Collections.singletonList(profileUriBuilder.personUri(ugnich))); @@ -2052,9 +2037,9 @@ public class ServerTests { json = jsonMapper.writeValueAsString(Context.build( activityPubManager.makeNote( messagesService.getReply(replyToExt.getMid(), replyToExt.getRid())))); - mockMvc.perform(get("/n/2-0")).andExpect(status().isOk()); + mockMvc.perform(get("/n/" + msg.getMid() + "-0")).andExpect(status().isOk()); mockMvc.perform(get("/n/2222-0")).andExpect(status().isNotFound()); - mockMvc.perform(get("/n/2-14")).andExpect(status().isNotFound()); + mockMvc.perform(get("/n/"+ msg.getMid() + "-14")).andExpect(status().isNotFound()); } @Test @@ -2159,8 +2144,9 @@ public class ServerTests { } @Test + @Order(6) public void ActivityPubLikesShouldNotMirrorMessage() throws Exception { - jdbcTemplate.execute("DELETE FROM messages"); + deleteMessages(); Message msg = commandsManager.processCommand(ugnich, "YO", emptyUri).getNewMessage().get(); messagesService.likeMessage(msg.getMid(), freefd.getUid(), Reaction.LIKE); messagesService.likeMessage(msg.getMid(), 0, Reaction.LIKE, "http://localhost:8080/u/test"); -- cgit v1.2.3