JAVA-14723 Some additional improvements (#13517)

Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
timis1 2023-02-26 17:35:12 +02:00 committed by GitHub
parent f3a236c77c
commit 4e89577f19
3 changed files with 7 additions and 51 deletions

View File

@ -41,47 +41,4 @@ public class WebConfig {
public ObjectMapper objectMapper() {
return new ObjectMapper();
}
// Thymeleaf configuration
@Bean
public ViewResolver thymeleafViewResolver() {
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(thymeleafTemplateEngine());
viewResolver.setCharacterEncoding("UTF-8");
viewResolver.setOrder(0);
return viewResolver;
}
// Thymeleaf template engine with Spring integration
@Bean
public SpringTemplateEngine thymeleafTemplateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(thymeleafTemplateResolver());
templateEngine.setEnableSpringELCompiler(true);
return templateEngine;
}
@Bean
public SpringResourceTemplateResolver springResourceTemplateResolver() {
return new SpringResourceTemplateResolver();
}
@Bean
public ITemplateResolver thymeleafTemplateResolver() {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/templates/");
templateResolver.setCacheable(false);
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCharacterEncoding("UTF-8");
return templateResolver;
}
}

View File

@ -39,7 +39,7 @@ public class PassParametersControllerIntegrationTest {
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/showViewPage")).andReturn().getModelAndView();
//Validate view
Assert.assertEquals(mv.getViewName(), "viewPage");
Assert.assertEquals(mv.getViewName(), "view/viewPage");
//Validate attribute
Assert.assertEquals(mv.getModelMap().get("message").toString(), "Baeldung");
@ -50,7 +50,7 @@ public class PassParametersControllerIntegrationTest {
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/printViewPage")).andReturn().getModelAndView();
//Validate view
Assert.assertEquals(mv.getViewName(), "viewPage");
Assert.assertEquals(mv.getViewName(), "view/viewPage");
//Validate attribute
Assert.assertEquals(mv.getModelMap().get("message").toString(), "Baeldung");
@ -61,7 +61,7 @@ public class PassParametersControllerIntegrationTest {
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/goToViewPage")).andReturn().getModelAndView();
//Validate view
Assert.assertEquals(mv.getViewName(), "viewPage");
Assert.assertEquals(mv.getViewName(), "view/viewPage");
//Validate attribute
Assert.assertEquals(mv.getModelMap().get("message").toString(), "Baeldung");

View File

@ -34,17 +34,16 @@ public class ArticleViewerControllerWithRequiredAttributeIntegrationTest {
int articleId = 5;
this.mockMvc
.perform(MockMvcRequestBuilders.get("/article/{id}", articleId))
.perform(MockMvcRequestBuilders.get("/requiredAttribute/article/{id}", articleId))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.id").value(articleId));
}
@Test
public void whenIdPathVariableIsNotPassed_thenResponse500() throws Exception {
public void whenIdPathVariableIsNotPassed_thenResponseOK() throws Exception {
this.mockMvc
.perform(MockMvcRequestBuilders.get("/article"))
.andExpect(MockMvcResultMatchers.status().isInternalServerError());
.perform(MockMvcRequestBuilders.get("/requiredAttribute/article"))
.andExpect(MockMvcResultMatchers.status().isOk());
}
}