aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/test/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-02-24 16:54:28 +0300
committerGravatar Vitaly Takmazov2018-03-15 12:05:59 +0300
commitbebe7c159f00e6d5a83bb786824d5f32e4de9270 (patch)
tree151801a2e625d4952d12630da6a4aec6a37fb76d /juick-server/src/test/java/com/juick/server
parent70f481e2fe39a9029b1896d7b351293fd5de4ef8 (diff)
spring boot wip
Diffstat (limited to 'juick-server/src/test/java/com/juick/server')
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java36
1 files changed, 15 insertions, 21 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 ecb06d45..cd1af5a4 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,8 +24,6 @@ import com.juick.ExternalToken;
import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
-import com.juick.configuration.DataConfiguration;
-import com.juick.configuration.RepositoryConfiguration;
import com.juick.server.EmailManager;
import com.juick.server.XMPPBot;
import com.juick.server.XMPPServer;
@@ -33,18 +31,21 @@ import com.juick.server.configuration.ApiAppConfiguration;
import com.juick.server.configuration.ApiSecurityConfig;
import com.juick.server.helpers.TagStats;
import com.juick.service.*;
+import com.juick.service.security.NotAuthorizedAuthenticationEntryPoint;
import com.juick.util.DateFormattersHolder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
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.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
@@ -75,16 +76,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
/**
* Created by vitalyster on 25.11.2016.
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {ApiAppConfiguration.class, ApiSecurityConfig.class, DataConfiguration.class, RepositoryConfiguration.class})
-@TestPropertySource(properties = {"broken_ssl_hosts=localhost,serverstorageisfull.tld"})
-@WebAppConfiguration
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+@TestPropertySource(properties = {"broken_ssl_hosts=localhost,serverstorageisfull.tld", "xmpp_disabled=true"})
+@AutoConfigureMockMvc
public class ServerTests extends AbstractJUnit4SpringContextTests {
- private MockMvc mockMvc;
@Inject
- private WebApplicationContext webApplicationContext;
-
+ private MockMvc mockMvc;
@Inject
private MessagesService messagesService;
@Inject
@@ -118,13 +117,9 @@ public class ServerTests extends AbstractJUnit4SpringContextTests {
@Before
public void setUp() {
- mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
- .apply(SecurityMockMvcConfigurers.springSecurity())
- .dispatchOptions(true)
- .build();
if (!isSetUp) {
ugnichName = "ugnich";
- ugnichPassword = "MyPassw0rd!";
+ ugnichPassword = "secret";
freefdName = "freefd";
freefdPassword = "MyPassw0rd!";
juickName = "juick";
@@ -148,21 +143,20 @@ public class ServerTests extends AbstractJUnit4SpringContextTests {
@Test
public void testAllUnAuthorized() throws Exception {
-
mockMvc.perform(get("/"))
.andExpect(status().isMovedPermanently());
mockMvc.perform(get("/auth"))
- .andExpect(status().is4xxClientError());
+ .andExpect(status().isUnauthorized());
mockMvc.perform(get("/home"))
- .andExpect(status().is4xxClientError());
+ .andExpect(status().isUnauthorized());
mockMvc.perform(get("/messages/recommended"))
- .andExpect(status().is4xxClientError());
+ .andExpect(status().isUnauthorized());
mockMvc.perform(get("/messages/set_privacy"))
- .andExpect(status().is4xxClientError());
+ .andExpect(status().isUnauthorized());
}
@Test
@@ -356,7 +350,7 @@ public class ServerTests extends AbstractJUnit4SpringContextTests {
}
@Test
public void statusPageIsUp() throws Exception {
- mockMvc.perform(get("http://localhost:8080/status").with(httpBasic(ugnichName, ugnichPassword))).andExpect(status().isOk());
+ mockMvc.perform(get("/api/status").with(httpBasic(ugnichName, ugnichPassword))).andExpect(status().isOk());
assertThat(server.getJid(), equalTo(jid));
}
@Test