aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-06-17 10:36:33 +0300
committerGravatar Vitaly Takmazov2019-06-17 10:36:33 +0300
commit789884af0ccdd299f943cfbce1afd15f69f6f567 (patch)
treef9ad0d25780f8ae719000e326ef40ce68bcc9c3c /src/test/java
parentcdafc30dbe57982844dd1b8fb3292c0013bd12ba (diff)
Added red test case for future top event problem triaging
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/juick/server/MockNotificationListener.java13
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java45
2 files changed, 54 insertions, 4 deletions
diff --git a/src/test/java/com/juick/server/MockNotificationListener.java b/src/test/java/com/juick/server/MockNotificationListener.java
new file mode 100644
index 00000000..4fc9a1d9
--- /dev/null
+++ b/src/test/java/com/juick/server/MockNotificationListener.java
@@ -0,0 +1,13 @@
+package com.juick.server;
+
+import com.juick.service.component.TopEvent;
+import org.springframework.context.ApplicationListener;
+
+import javax.annotation.Nonnull;
+
+public class MockNotificationListener implements ApplicationListener<TopEvent> {
+ @Override
+ public void onApplicationEvent(@Nonnull TopEvent event) {
+
+ }
+}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 5d13095b..9b905319 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -45,6 +45,7 @@ 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.test.util.MockUtils;
import com.juick.util.DateFormattersHolder;
import com.juick.util.MessageUtils;
@@ -63,10 +64,16 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.*;
@@ -90,7 +97,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.session.Extension;
import rocks.xmpp.core.session.XmppSession;
@@ -104,8 +110,13 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.*;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -114,7 +125,15 @@ import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.sql.Timestamp;
import java.time.Instant;
-import java.util.*;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Scanner;
+import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -223,6 +242,9 @@ public class ServerTests {
@Inject
private KeystoreManager testKeystoreManager;
+ @Inject
+ private ApplicationEventPublisher applicationEventPublisher;
+
private static User ugnich, freefd, juick;
static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword;
URI emptyUri = URI.create(StringUtils.EMPTY);
@@ -258,6 +280,7 @@ public class ServerTests {
webClient.getOptions().setJavaScriptEnabled(false);
isSetUp = true;
}
+ MockitoAnnotations.initMocks(this);
}
@After
public void teardown() throws IOException {
@@ -2066,4 +2089,18 @@ public class ServerTests {
.andExpect(status().isFound())
.andExpect(redirectedUrl("/ugnich/" + mid));
}
+ @MockBean
+ private MockNotificationListener notificationListener;
+ @Captor
+ protected ArgumentCaptor<TopEvent> topEventCaptor;
+ @Test
+ public void topEventShouldNotLossUser() {
+ Message topMessage = MockUtils.mockMessage(1000, ugnich, "top message");
+ topMessage.setTo(AnonymousUser.INSTANCE);
+ TopEvent event = new TopEvent(this, topMessage);
+ applicationEventPublisher.publishEvent(event);
+ Mockito.verify(notificationListener, Mockito.times(1)).onApplicationEvent(topEventCaptor.capture());
+ TopEvent receivedEvent = topEventCaptor.getValue();
+ assertThat(receivedEvent.getMessage().getUser(), is(ugnich));
+ }
}