aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index edb43db4..ff86f4b4 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -272,9 +272,11 @@ public class ServerTests {
@Inject
private Users usersController;
+ @Inject
+ private User serviceUser;
- private static User ugnich, freefd, juick;
- static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword;
+ private static User ugnich, freefd;
+ static String ugnichName, ugnichPassword, freefdName, freefdPassword;
URI emptyUri = URI.create(StringUtils.EMPTY);
private static boolean isSetUp = false;
@@ -300,11 +302,8 @@ public class ServerTests {
ugnichPassword = "secret";
freefdName = "freefd";
freefdPassword = "MyPassw0rd!";
- juickName = "juick";
- juickPassword = "demo";
ugnich = userService.createUser(ugnichName, ugnichPassword).orElseThrow(IllegalStateException::new);
freefd = userService.createUser(freefdName, freefdPassword).orElseThrow(IllegalStateException::new);
- juick = userService.createUser(juickName, juickPassword).orElseThrow(IllegalStateException::new);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setCssEnabled(false);
isSetUp = true;
@@ -670,7 +669,7 @@ public class ServerTests {
.content(jsonMapper.writeValueAsBytes(Collections.singletonList(registration))))
.andExpect(status().isOk());
MvcResult result = mockMvc.perform(get("/api/notifications").param("uid", String.valueOf(ugnich.getUid()))
- .with(httpBasic(juickName, juickPassword))).andExpect(status().isOk()).andReturn();
+ .with(httpBasic(serviceUser.getName(), "password"))).andExpect(status().isOk()).andReturn();
List<User> users = jsonMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<>() {
});
assertThat(users.size(), is(1));
@@ -691,7 +690,7 @@ public class ServerTests {
mockMvc.perform(delete("/api/notifications").with(httpBasic(ugnichName, ugnichPassword))
.contentType(MediaType.APPLICATION_JSON).content(jsonMapper.writeValueAsBytes(tokens)))
.andExpect(status().isForbidden());
- mockMvc.perform(delete("/api/notifications").with(httpBasic(juickName, juickPassword))
+ mockMvc.perform(delete("/api/notifications").with(httpBasic(serviceUser.getName(), "password"))
.contentType(MediaType.APPLICATION_JSON).content(jsonMapper.writeValueAsBytes(tokens)))
.andExpect(status().isOk());
}
@@ -700,7 +699,7 @@ public class ServerTests {
public void notificationsSettingsAllowedOnlyForServiceUser() throws Exception {
CommandResult result = commandsManager.processCommand(ugnich, "yo", emptyUri);
String stringValueOfMid = String.valueOf(result.getNewMessage().get().getMid());
- mockMvc.perform(get("/api/notifications").with(httpBasic(juickName, juickPassword))
+ mockMvc.perform(get("/api/notifications").with(httpBasic(serviceUser.getName(), "password"))
.param("mid", stringValueOfMid).param("uid", String.valueOf(ugnich.getUid())))
.andExpect(status().isOk());
mockMvc.perform(
@@ -913,7 +912,7 @@ public class ServerTests {
+ "Content-Type: text/html; charset=\"UTF-8\"\n" + "\n" + "<div dir=\"ltr\">s2313334</div>\n"
+ "\n" + "--001a11454886e42be5056786ca70--",
mid, mid);
- mockMvc.perform(post("/api/mail").with(httpBasic(juickName, juickPassword)).content(mail))
+ mockMvc.perform(post("/api/mail").with(httpBasic(serviceUser.getName(), "password")).content(mail))
.andExpect(status().isOk());
String reply = "Return-Path: <ugnich@example.com>\n" + "Received: from [192.168.88.140] ([91.244.168.38])\n"
+ " by smtp.gmail.com with ESMTPSA id r84sm3970197lja.54.2019.06.20.08.39.54\n"
@@ -927,7 +926,7 @@ public class ServerTests {
+ "In-Reply-To: <CAF+0zPD_YLVgYovajLqUFwkRAgJT+FzyQ2EzikQsPKsrnfKv-Q@mail.gmail.com>\n"
+ "To: juick@juick.com\n" + "X-Mailer: iPhone Mail (16F203)\n" + "\n"
+ "0J3RgyDRjdGC0L4g0L/QvtC60LAhINCU0L7Qu9Cz0L4g0LvQuCwg0YPQvNC10Y7Rh9C4IQ==";
- mockMvc.perform(post("/api/mail").with(httpBasic(juickName, juickPassword)).content(reply))
+ mockMvc.perform(post("/api/mail").with(httpBasic(serviceUser.getName(), "password")).content(reply))
.andExpect(status().isOk());
}
@@ -999,7 +998,7 @@ public class ServerTests {
privacyQueriesService.blacklistUser(ugnich, freefd);
int newfreefdrid = messagesService.createReply(mid, 0, freefd, "from ban", null);
serverManager.processSystemEvent(new SystemEvent(this,
- SystemActivity.message(juick, messagesService.getReply(mid, newfreefdrid), Collections.emptyList())));
+ SystemActivity.message(serviceUser, messagesService.getReply(mid, newfreefdrid), Collections.emptyList())));
assertThat(userService.isReplyToBL(ugnich, messagesService.getReply(mid, newfreefdrid)), is(true));
// TODO: test event listeners correctly
Thread.sleep(2000L);
@@ -1024,10 +1023,10 @@ public class ServerTests {
.stream().noneMatch(m -> m.getTags().contains(banned)), is(true));
assertFalse(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getPhotos(ugnich.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
- jdbcTemplate.update("UPDATE messages SET popular=1 WHERE message_id=?", mid);
- assertThat(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getPopular(freefd.getUid(), 0))
+ messagesService.recommendMessage(mid, serviceUser.getUid());
+ assertThat(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getUserBlogWithRecommendations(serviceUser, freefd, 0, 0))
.stream().noneMatch(m -> m.getTags().contains(banned)), is(true));
- assertFalse(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getPopular(ugnich.getUid(), 0))
+ assertFalse(messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getUserBlogWithRecommendations(serviceUser, ugnich, 0, 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
assertThat(
messagesService.getMessages(AnonymousUser.INSTANCE, messagesService.getMyFeed(freefd.getUid(), 0, true))
@@ -1121,7 +1120,7 @@ public class ServerTests {
@Test
public void emptyAuthenticatedPostShouldThrowBadRequest() throws Exception {
- mockMvc.perform(post("/api/post").with(httpBasic(juickName, juickPassword))).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/api/post").with(httpBasic(serviceUser.getName(), "password"))).andExpect(status().isBadRequest());
}
@Test
@@ -1152,8 +1151,8 @@ public class ServerTests {
CommandResult result = commandsManager.processCommand(ugnich, "freefd - dick", emptyUri);
int mid = result.getNewMessage().get().getMid();
commandsManager.processCommand(freefd, String.format("#%d ugnich - dick too", mid), emptyUri);
- commandsManager.processCommand(juick, String.format("#%d/1 ban for a hour!", mid), emptyUri);
- commandsManager.processCommand(juick, String.format("#%d freefd is here but it is hidden from you", mid),
+ commandsManager.processCommand(serviceUser, String.format("#%d/1 ban for a hour!", mid), emptyUri);
+ commandsManager.processCommand(serviceUser, String.format("#%d freefd is here but it is hidden from you", mid),
emptyUri);
assertThat(messagesService.getMessage(mid).get().getReplies(), is(3));
Message reply = messagesService.getReply(mid, 3);
@@ -1164,7 +1163,7 @@ public class ServerTests {
assertThat(messagesService.getMessage(mid).get().getReplies(), is(4));
replies = messagesService.getReplies(ugnich, mid);
assertThat(replies.size(), is(1));
- commandsManager.processCommand(juick, String.format("#%d/4 mmm?!", mid), emptyUri);
+ commandsManager.processCommand(serviceUser, String.format("#%d/4 mmm?!", mid), emptyUri);
assertThat(messagesService.getMessage(mid).get().getReplies(), is(5));
replies = messagesService.getReplies(ugnich, mid);
reply = messagesService.getReply(mid, 5);
@@ -2023,8 +2022,8 @@ public class ServerTests {
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");
- jdbcTemplate.update("UPDATE messages SET popular=1 where message_id=?", msg.getMid());
- List<Message> top = messagesService.getMessages(ugnich, messagesService.getPopular(ugnich.getUid(), 0));
+ messagesService.recommendMessage(msg.getMid(), serviceUser.getUid());
+ List<Message> top = messagesService.getMessages(ugnich, messagesService.getUserBlogWithRecommendations(serviceUser, ugnich, 0, 0));
assertThat(top.size(), is(1));
}
@@ -2277,7 +2276,7 @@ public class ServerTests {
public void topEventShouldNotLossUser() {
Message topMessage = MockUtils.mockMessage(1000, ugnich, "top message");
topMessage.setTo(AnonymousUser.INSTANCE);
- SystemEvent event = new SystemEvent(this, SystemActivity.like(juick, topMessage, Collections.emptyList()));
+ SystemEvent event = new SystemEvent(this, SystemActivity.like(serviceUser, topMessage, Collections.emptyList()));
applicationEventPublisher.publishEvent(event);
Mockito.verify(notificationListener, Mockito.times(1)).onApplicationEvent(topEventCaptor.capture());
SystemEvent receivedEvent = topEventCaptor.getValue();