aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/test/java/com/juick/WebAppTests.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-30 17:52:53 +0300
committerGravatar Vitaly Takmazov2018-03-30 17:52:53 +0300
commitbda2d764a9c187da5aa8cd74fb8c4a9574d3996e (patch)
tree2d5bc98a5744f8f6a0ec4e7f9893c2355235267c /juick-www/src/test/java/com/juick/WebAppTests.java
parent7eb13edc1720b13924d7cbe715be67a535f0e02e (diff)
xmpp integration tests
Diffstat (limited to 'juick-www/src/test/java/com/juick/WebAppTests.java')
-rw-r--r--juick-www/src/test/java/com/juick/WebAppTests.java50
1 files changed, 36 insertions, 14 deletions
diff --git a/juick-www/src/test/java/com/juick/WebAppTests.java b/juick-www/src/test/java/com/juick/WebAppTests.java
index e9908acd..43198859 100644
--- a/juick-www/src/test/java/com/juick/WebAppTests.java
+++ b/juick-www/src/test/java/com/juick/WebAppTests.java
@@ -26,6 +26,11 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
+import com.juick.server.XMPPConnection;
+import com.juick.server.XMPPRouter;
+import com.juick.server.XMPPServer;
+import com.juick.server.configuration.ApiAppConfiguration;
+import com.juick.server.configuration.BaseWebConfiguration;
import com.juick.service.*;
import com.juick.util.MessageUtils;
import com.juick.www.WebApp;
@@ -38,9 +43,14 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+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.test.mock.mockito.MockBean;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.mock.web.MockMultipartFile;
@@ -49,6 +59,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.FileSystemUtils;
+import org.springframework.web.servlet.resource.ResourceUrlProvider;
import javax.inject.Inject;
import javax.servlet.http.Cookie;
@@ -74,9 +85,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@RunWith(SpringRunner.class)
@AutoConfigureMockMvc
-@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
-@TestPropertySource(properties = {"xmpp_disabled=true"})
-
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = {Application.class, XMPPRouter.class})
public class WebAppTests {
@MockBean
private ImagesService imagesService;
@@ -239,30 +248,37 @@ public class WebAppTests {
}
@Test
public void postMessageTests() throws Exception {
- mockMvc.perform(post("/post").param("body", "yo")).andExpect(redirectedUrl("http://localhost/login"));
+ ConfigurableApplicationContext context = new SpringApplicationBuilder(
+ ApiServer.class)
+ .properties("server.port=8081")
+ .run();
+ XMPPServer xmpp = context.getBean(XMPPServer.class);
+ assertThat(xmpp.getInConnections().size(), is(0));
+ mockMvc.perform(post("/post2").param("body", "yo")).andExpect(redirectedUrl("http://localhost/login"));
MvcResult loginResult = mockMvc.perform(post("/login")
.param("username", ugnichName)
.param("password", ugnichPassword)).andReturn();
- mockMvc.perform(post("/post")
- .cookie(loginResult.getResponse().getCookies())
- .param("wrong_param", "yo")).andExpect(status().isBadRequest());
String msgText = "yoppppl";
- mockMvc.perform(post("/post")
+ mockMvc.perform(post("/post2")
.cookie(loginResult.getResponse().getCookies())
- .param("body", msgText)).andExpect(status().isOk());
+ .param("body", msgText)).andExpect(status().isFound());
+ Thread.sleep(5000);
Message lastMessage = messagesService.getMessage(messagesService.getMyFeed(ugnich.getUid(), 0, false).get(0));
assertThat(lastMessage.getText(), equalTo(msgText));
- mockMvc.perform(post("/post")
+ mockMvc.perform(post("/post2")
.cookie(loginResult.getResponse().getCookies())
- .param("img", "http://static.juick.com/settings/facebook.png")).andExpect(status().isOk());
- mockMvc.perform(post("/post")
+ .param("img", "http://static.juick.com/settings/facebook.png")).andExpect(status().isFound());
+ Thread.sleep(5000);
+ lastMessage = messagesService.getMessage(messagesService.getMyFeed(ugnich.getUid(), 0, false).get(0));
+ assertThat(lastMessage.getAttachmentType(), equalTo("png"));
+ mockMvc.perform(post("/post2")
.cookie(loginResult.getResponse().getCookies())
.param("img", "bad_url")).andExpect(status().isBadRequest());
FileInputStream fi = new FileInputStream(new ClassPathResource("static/tagscloud.png").getFile());
MockMultipartFile file = new MockMultipartFile("attach", fi);
- mockMvc.perform(multipart("/post")
+ mockMvc.perform(multipart("/post2")
.file(file)
- .cookie(loginResult.getResponse().getCookies())).andExpect(status().isOk());
+ .cookie(loginResult.getResponse().getCookies())).andExpect(status().isFound());
int mid = messagesService.createMessage(ugnich.getUid(), "dummy message", null, null);
mockMvc.perform(post("/comment")
.param("mid", String.valueOf(mid))
@@ -286,6 +302,12 @@ public class WebAppTests {
.cookie(loginResult.getResponse().getCookies())
.param("mid", String.valueOf(mid))
.param("body", "yo")).andExpect(redirectedUrl(String.format("/%s/%d#%d", ugnichName, mid, 3)));
+ mockMvc.perform(post("/post2")
+ .cookie(loginResult.getResponse().getCookies())
+ .param("body", String.format("D #%d/%d", mid, 3)))
+ .andExpect(status().isFound());
+ Thread.sleep(5000);
+ assertThat(messagesService.getReplies(mid).size(), equalTo(2));
}
@Test
public void hashLoginShouldNotUseSession() throws Exception {