From 2f2e9aab6194037259625200091949d8648e3409 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 24 Sep 2019 11:54:21 +0300 Subject: Use single event model for all application events --- .../java/com/juick/server/tests/ServerTests.java | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 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 901d1501..e5d39743 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -18,6 +18,7 @@ package com.juick.server.tests; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -34,6 +35,7 @@ import com.juick.model.CommandResult; import com.juick.model.PrivateChats; import com.juick.model.TagStats; import com.juick.server.*; +import com.juick.server.api.SystemActivity; import com.juick.server.api.Users; import com.juick.server.api.activity.Profile; import com.juick.server.api.activity.model.Context; @@ -46,8 +48,7 @@ import com.juick.server.util.HttpUtils; import com.juick.server.util.ImageUtils; import com.juick.server.www.WebApp; import com.juick.service.*; -import com.juick.service.component.MessageEvent; -import com.juick.service.component.TopEvent; +import com.juick.service.component.SystemEvent; import com.juick.test.util.MockUtils; import com.juick.util.DateFormattersHolder; import com.juick.util.MessageUtils; @@ -1011,8 +1012,8 @@ public class ServerTests { assertThat(lastRead.apply(ugnich, mid), is(freefdrid)); privacyQueriesService.blacklistUser(ugnich, freefd); int newfreefdrid = messagesService.createReply(mid, 0, freefd, "from ban", null); - serverManager.processMessageEvent(new MessageEvent(this, messagesService.getReply(mid, newfreefdrid), - Collections.emptyList())); + serverManager.processSystemEvent(new SystemEvent(this, SystemActivity.message(juick, messagesService.getReply(mid, newfreefdrid), + Collections.emptyList()))); assertThat(userService.isReplyToBL(ugnich, messagesService.getReply(mid, newfreefdrid)), is(true)); // TODO: test event listeners correctly Thread.sleep(2000L); @@ -2159,16 +2160,16 @@ public class ServerTests { @MockBean private MockNotificationListener notificationListener; @Captor - protected ArgumentCaptor topEventCaptor; + protected ArgumentCaptor topEventCaptor; @Test public void topEventShouldNotLossUser() { Message topMessage = MockUtils.mockMessage(1000, ugnich, "top message"); topMessage.setTo(AnonymousUser.INSTANCE); - TopEvent event = new TopEvent(this, topMessage); + SystemEvent event = new SystemEvent(this, SystemActivity.like(juick, topMessage, Collections.emptyList())); applicationEventPublisher.publishEvent(event); Mockito.verify(notificationListener, Mockito.times(1)).onApplicationEvent(topEventCaptor.capture()); - TopEvent receivedEvent = topEventCaptor.getValue(); - assertThat(receivedEvent.getMessage().getUser(), is(ugnich)); + SystemEvent receivedEvent = topEventCaptor.getValue(); + assertThat(receivedEvent.getActivity().getMessage().getUser(), is(ugnich)); } @Test public void tagStatsSpec() throws Exception { @@ -2221,4 +2222,11 @@ public class ServerTests { var authorResult = commandsManager.processCommand(ugnich, String.format("#%d PEOPLE", mid), emptyUri); assertThat(authorResult.getNewMessage().isPresent(), is(true)); } + @Test + public void activitySerializationTest() throws JsonProcessingException { + var freefd = MockUtils.mockUser(10, "freefd", "secret"); + var like = SystemActivity.like(MockUtils.mockUser(1, "ugnich", "secret"), + MockUtils.mockMessage(1, freefd, "txt"), Collections.singletonList(freefd)); + var likeStr = jsonMapper.writeValueAsString(like); + } } -- cgit v1.2.3