aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www
diff options
context:
space:
mode:
Diffstat (limited to 'juick-spring-www')
-rw-r--r--juick-spring-www/build.gradle1
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java12
-rw-r--r--juick-spring-www/src/test/java/com/juick/www/NotFoundPageTest.java30
3 files changed, 18 insertions, 25 deletions
diff --git a/juick-spring-www/build.gradle b/juick-spring-www/build.gradle
index c6da5edd..83430eb0 100644
--- a/juick-spring-www/build.gradle
+++ b/juick-spring-www/build.gradle
@@ -41,6 +41,7 @@ dependencies {
testCompile "ch.vorburger.mariaDB4j:mariaDB4j:2.2.2"
testCompile "org.thymeleaf:thymeleaf-testing:3.0.1.RELEASE"
+ testCompile "org.springframework.security:spring-security-test:${rootProject.springSecurityVersion}"
providedCompile "javax.servlet:javax.servlet-api:3.1.0"
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
index 62e7293b..406c27ed 100644
--- a/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/ShowMessageController.java
@@ -83,11 +83,11 @@ public class ShowMessageController {
// Check validity of user name before quering from database
if (WebUtils.isNotUserName(userName)) {
model.addAttribute("userName", userName);
- return "userNotFound";
+ throw new HttpNotFoundException();
}
User user = userService.getUserByName(userName);
- if (user == null) {
+ if (user.getUid() == 0) {
model.addAttribute("userName", userName);
throw new HttpNotFoundException();
}
@@ -106,7 +106,7 @@ public class ShowMessageController {
}
User user = userService.getUserByName(userName);
- if (user == null) {
+ if (user.getUid() == 0) {
model.addAttribute("userName", userName);
throw new HttpNotFoundException();
}
@@ -125,7 +125,7 @@ public class ShowMessageController {
}
User user = userService.getUserByName(userName);
- if (user == null) {
+ if (user.getUid() == 0) {
model.addAttribute("userName", userName);
throw new HttpNotFoundException();
}
@@ -144,7 +144,7 @@ public class ShowMessageController {
}
User user = userService.getUserByName(userName);
- if (user == null) {
+ if (user.getUid() == 0) {
model.addAttribute("userName", userName);
throw new HttpNotFoundException();
}
@@ -170,7 +170,7 @@ public class ShowMessageController {
}
User user = userService.getUserByName(userName);
- if (user == null) {
+ if (user.getUid() == 0) {
model.addAttribute("userName", userName);
throw new HttpNotFoundException();
}
diff --git a/juick-spring-www/src/test/java/com/juick/www/NotFoundPageTest.java b/juick-spring-www/src/test/java/com/juick/www/NotFoundPageTest.java
index 0b68fe70..c01194f4 100644
--- a/juick-spring-www/src/test/java/com/juick/www/NotFoundPageTest.java
+++ b/juick-spring-www/src/test/java/com/juick/www/NotFoundPageTest.java
@@ -6,7 +6,7 @@ import com.juick.www.configuration.WwwServletConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -15,6 +15,8 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
+import javax.inject.Inject;
+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
@@ -32,35 +34,25 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@ContextConfiguration(classes = {WwwServletConfiguration.class}),
})
public class NotFoundPageTest {
- @Autowired
+ @Inject
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
- this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
+ this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac)
+ .apply(SecurityMockMvcConfigurers.springSecurity()).build();
}
@Test
- public void postNotFoundTest() throws Exception {
+ public void pageNotFoundTest() throws Exception {
mockMvc.perform(get("/-11"))
- .andExpect(status().isOk())
- .andExpect(view().name("postNotFound"));
+ .andExpect(status().is4xxClientError())
+ .andExpect(view().name("views/error"));
mockMvc.perform(get("/-1"))
- .andExpect(status().isOk())
- .andExpect(view().name("postNotFound"));
- }
-
- @Test
- public void userNotFoundTest() throws Exception {
- mockMvc.perform(get("/-0"))
- .andExpect(status().isOk())
- .andExpect(view().name("userNotFound"));
-
- mockMvc.perform(get("/00000000000000000000000000"))
- .andExpect(status().isOk())
- .andExpect(view().name("userNotFound"));
+ .andExpect(status().is4xxClientError())
+ .andExpect(view().name("views/error"));
}
}