Skip to content

Commit 27bb2be

Browse files
Fixed test cases
1 parent 90dd071 commit 27bb2be

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

lemon-demo-jpa/src/test/java/com/naturalprogrammer/spring/lemondemo/AbstractMvcTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public abstract class AbstractMvcTests {
6464

6565
protected String login(String userName, String password) throws Exception {
6666

67-
MvcResult result = mvc.perform(post("/login")
67+
MvcResult result = mvc.perform(post("/api/core/login")
6868
.param("username", userName)
6969
.param("password", password)
7070
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))

lemon-demo-jpa/src/test/java/com/naturalprogrammer/spring/lemondemo/LoginMvcTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class LoginMvcTests extends AbstractMvcTests {
2222
@Test
2323
public void testLogin() throws Exception {
2424

25-
mvc.perform(post("/login")
25+
mvc.perform(post("/api/core/login")
2626
.param("username", ADMIN_EMAIL)
2727
.param("password", ADMIN_PASSWORD)
2828
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))
@@ -82,7 +82,7 @@ public void testObsoleteToken() throws Exception {
8282
@Test
8383
public void testLoginWrongPassword() throws Exception {
8484

85-
mvc.perform(post("/login")
85+
mvc.perform(post("/api/core/login")
8686
.param("username", ADMIN_EMAIL)
8787
.param("password", "wrong-password")
8888
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))
@@ -92,7 +92,7 @@ public void testLoginWrongPassword() throws Exception {
9292
@Test
9393
public void testLoginBlankPassword() throws Exception {
9494

95-
mvc.perform(post("/login")
95+
mvc.perform(post("/api/core/login")
9696
.param("username", ADMIN_EMAIL)
9797
.param("password", "")
9898
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))
@@ -125,7 +125,7 @@ public void testLogout() throws Exception {
125125

126126
private String login(String username, String password, long expirationMillis) throws Exception {
127127

128-
MvcResult result = mvc.perform(post("/login")
128+
MvcResult result = mvc.perform(post("/api/core/login")
129129
.param("username", ADMIN_EMAIL)
130130
.param("password", ADMIN_PASSWORD)
131131
.param("expirationMillis", Long.toString(expirationMillis))

lemon-demo-jpa/src/test/java/com/naturalprogrammer/spring/lemondemo/ResetPasswordMvcTests.java

+22-15
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
import org.springframework.beans.factory.annotation.Autowired;
1212
import org.springframework.http.MediaType;
1313

14+
import com.fasterxml.jackson.core.JsonProcessingException;
15+
import com.naturalprogrammer.spring.lemon.commons.domain.ResetPasswordForm;
1416
import com.naturalprogrammer.spring.lemon.commons.security.JwtService;
1517
import com.naturalprogrammer.spring.lemon.commons.util.LecUtils;
18+
import com.naturalprogrammer.spring.lemon.util.LemonUtils;
1619

1720
public class ResetPasswordMvcTests extends AbstractMvcTests {
1821

@@ -37,9 +40,8 @@ public void testResetPassword() throws Exception {
3740
//Thread.sleep(1001L);
3841

3942
mvc.perform(post("/api/core/reset-password")
40-
.param("code", forgotPasswordCode)
41-
.param("newPassword", NEW_PASSWORD)
42-
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))
43+
.contentType(MediaType.APPLICATION_JSON)
44+
.content(form(forgotPasswordCode, NEW_PASSWORD)))
4345
.andExpect(status().is(200))
4446
.andExpect(header().string(LecUtils.TOKEN_RESPONSE_HEADER_NAME, containsString(".")))
4547
.andExpect(jsonPath("$.id").value(ADMIN_ID));
@@ -49,9 +51,8 @@ public void testResetPassword() throws Exception {
4951

5052
// Repeating shouldn't work
5153
mvc.perform(post("/api/core/reset-password")
52-
.param("code", forgotPasswordCode)
53-
.param("newPassword", NEW_PASSWORD)
54-
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))
54+
.contentType(MediaType.APPLICATION_JSON)
55+
.content(form(forgotPasswordCode, NEW_PASSWORD)))
5556
.andExpect(status().is(401));
5657
}
5758

@@ -60,23 +61,29 @@ public void testResetPasswordInvalidData() throws Exception {
6061

6162
// Wrong code
6263
mvc.perform(post("/api/core/reset-password")
63-
.param("code", "wrong-code")
64-
.param("newPassword", "abc99!")
65-
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))
64+
.contentType(MediaType.APPLICATION_JSON)
65+
.content(form("wrong-code", "abc99!")))
6666
.andExpect(status().is(401));
6767

6868
// Blank password
6969
mvc.perform(post("/api/core/reset-password")
70-
.param("code", forgotPasswordCode)
71-
.param("newPassword", "")
72-
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))
70+
.contentType(MediaType.APPLICATION_JSON)
71+
.content(form(forgotPasswordCode, "")))
7372
.andExpect(status().is(422));
7473

7574
// Invalid password
7675
mvc.perform(post("/api/core/reset-password")
77-
.param("code", forgotPasswordCode)
78-
.param("newPassword", "abc")
79-
.header("contentType", MediaType.APPLICATION_FORM_URLENCODED))
76+
.contentType(MediaType.APPLICATION_JSON)
77+
.content(form(forgotPasswordCode, "abc")))
8078
.andExpect(status().is(422));
8179
}
80+
81+
private String form(String code, String newPassword) throws JsonProcessingException {
82+
83+
ResetPasswordForm form = new ResetPasswordForm();
84+
form.setCode(code);
85+
form.setNewPassword(newPassword);
86+
87+
return LemonUtils.toJson(form);
88+
}
8289
}

0 commit comments

Comments
 (0)