diff options
Diffstat (limited to 'juick-server/src/test/java/com/juick')
-rw-r--r-- | juick-server/src/test/java/com/juick/server/tests/ServerTests.java | 25 |
1 files changed, 24 insertions, 1 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 0aa1e3ca..fcc0a422 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 @@ -24,9 +24,11 @@ import com.juick.ExternalToken; import com.juick.Message; import com.juick.Tag; import com.juick.User; +import com.juick.configuration.DataConfiguration; import com.juick.server.EmailManager; import com.juick.server.XMPPBot; import com.juick.server.XMPPServer; +import com.juick.server.configuration.ApiAppConfiguration; import com.juick.server.helpers.TagStats; import com.juick.service.*; import com.juick.util.DateFormattersHolder; @@ -39,7 +41,13 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.TestPropertySource; @@ -51,9 +59,11 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import rocks.xmpp.addr.Jid; +import rocks.xmpp.core.stanza.MessageEvent; import rocks.xmpp.core.stanza.model.Stanza; import rocks.xmpp.core.stanza.model.server.ServerMessage; +import javax.annotation.Nonnull; import javax.inject.Inject; import java.lang.reflect.InvocationTargetException; import java.text.ParseException; @@ -61,6 +71,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Scanner; +import java.util.concurrent.CountDownLatch; import java.util.stream.IntStream; import static org.hamcrest.MatcherAssert.assertThat; @@ -78,7 +89,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @TestPropertySource(properties = {"broken_ssl_hosts=localhost,serverstorageisfull.tld", "xmpp_disabled=true"}) @AutoConfigureMockMvc -public class ServerTests extends AbstractJUnit4SpringContextTests { +public class ServerTests { @Inject private MockMvc mockMvc; @@ -114,6 +125,14 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { private static boolean isSetUp = false; + @Import({ApiAppConfiguration.class, DataConfiguration.class}) + @Configuration + static class TestConfig { + @Bean + ApplicationListener<com.juick.server.component.MessageEvent> listener() { + return event -> latch.countDown(); + } + } @Before public void setUp() { @@ -380,6 +399,7 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { int uid = userService.createUser("me", "secret"); User user = userService.getUserByUID(uid).orElse(new User()); Tag yo = tagService.getTag("yo", true); + bot.incomingMessageJuick(user, Jid.of("test@localhost"), "*yo yoyo"); int mid = messagesService.createMessage(uid, "yoyo", null, Collections.singletonList(yo)); assertEquals("should be message", true, bot.processCommand(user, Jid.of("test@localhost"), String.format("#%d", mid)).get().startsWith("@me")); @@ -468,6 +488,7 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { bot.processCommand(user, Jid.of("test@localhost"), "D #" + mid).get()); assertEquals("should be not found", "Message not found", bot.processCommand(user, Jid.of("test@localhost"), "#" + mid).get()); + assertThat(latch.getCount(), equalTo(0L)); } @Test public void mailParserTest() throws Exception { @@ -507,4 +528,6 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { Assert.assertThat(count, equalTo(0L)); mockMvc.perform(get("/ws/_all")).andExpect(status().isBadRequest()); } + + private static CountDownLatch latch = new CountDownLatch(1); } |