Files
spring-boot-rest/spring-boot-modules/spring-boot-mvc-3/src/test/java/com/baeldung/springvalidation/UserAccountUnitTest.java
Rutuja Joshi a5d22387aa BAEL-4201 - Initial Commit (#9957)
* BAEL-4201 - Initial commit

* BAEL-4201 - Initial Commit

* Update UserAccountController.java

removed the additional brackets

* Update UserAccountValidationTest.java

Updated the tests

* Bael - 4201 - recommit for github issue fix

For 'This commit does not belong to any branch on this repository' - delete and recommitting controller

* Bael - 4201 - recommit for github issue fix

For 'This commit does not belong to any branch on this repository' - delete and recommitting test

* Bael - 4201 - add for github issue fix

For 'This commit does not belong to any branch on this repository' - adding controller again

* Bael - 4201 - add for github issue fix

For 'This commit does not belong to any branch on this repository' - adding test again

* BAEL-4201: Initial Commit

* Update UserAccountUnitTest.java

* BAEL-4201: updated to fix the commit issue

* BAEL-4201 - temporary deleting 

Deleting to fix branch issue

* BAEL-4201 - commiting test again

* BAEL-4201 

Fixing build issues

* BAEL-4201 

Github commit issue

* BAEL-4201

Github commit issue - webapp folder

* BAEL-4201 - commiting test after view upload

* Bael- 4201 ThymeLeaf related issues

* Bael- 4201 ThymeLeaf related issues

* Bael- 4201 ThymeLeaf related issues

* Bael- 4201 ThymeLeaf related issues - added html

* Bael- 4201 ThymeLeaf issue ; updated suffix- html

* Bael - 4201 white label issue

* Bael - 4201 white label issue

* BAEL-4201 : moving html to templates

* BAEL-4201 - moving to templates

* BAEL-4201 - moving to templates

* BAEL-4201 - review related updates

* BAEL-4201 - review related updates

* BAEL-4201 - review related updates

* BAEL-4201 - review related updates

* BAEL-4201 - review related updates

* BAEL-4201 - review related updates

* BAEL-4201 - review related updates

* BAEL-4201 - added the spring-boot-starter-validation dependency
2020-09-17 09:32:51 -07:00

58 lines
2.2 KiB
Java

package com.baeldung.springvalidation;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class UserAccountUnitTest {
@Autowired
private MockMvc mockMvc;
@Test
public void givenSaveBasicInfo_whenCorrectInput_thenSuccess() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post("/saveBasicInfo")
.accept(MediaType.TEXT_HTML)
.param("name", "test123")
.param("password", "pass"))
.andExpect(view().name("success"))
.andExpect(status().isOk())
.andDo(print());
}
@Test
public void givenSaveBasicInfoStep1_whenCorrectInput_thenSuccess() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post("/saveBasicInfoStep1")
.accept(MediaType.TEXT_HTML)
.param("name", "test123")
.param("password", "pass"))
.andExpect(view().name("success"))
.andExpect(status().isOk())
.andDo(print());
}
@Test
public void givenSaveBasicInfoStep1_whenIncorrectInput_thenError() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post("/saveBasicInfoStep1")
.accept(MediaType.TEXT_HTML))
// .param("name", "test123")
// .param("password", "pass"))
.andExpect(model().errorCount(2))
// .andExpect(view().name("error"))
.andExpect(status().isOk())
.andDo(print());
}
}