diff --git a/spring-web-modules/spring-thymeleaf/pom.xml b/spring-web-modules/spring-thymeleaf/pom.xml index 8201cb5c5b..94ae05ca11 100644 --- a/spring-web-modules/spring-thymeleaf/pom.xml +++ b/spring-web-modules/spring-thymeleaf/pom.xml @@ -115,10 +115,9 @@ org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} + cargo-maven3-plugin + ${cargo-maven3-plugin.version} - true jetty9x embedded @@ -143,7 +142,7 @@ 2.0.1.Final 6.0.11.Final - 1.6.1 + 1.9.9 \ No newline at end of file diff --git a/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FunctionCallController.java b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FunctionCallController.java new file mode 100644 index 0000000000..751dbc4e9d --- /dev/null +++ b/spring-web-modules/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FunctionCallController.java @@ -0,0 +1,18 @@ +package com.baeldung.thymeleaf.controller; + +import com.baeldung.thymeleaf.utils.StudentUtils; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@Controller +public class FunctionCallController { + + @RequestMapping(value = "/function-call", method = RequestMethod.GET) + public String getExampleHTML(Model model) { + model.addAttribute("totalStudents", StudentUtils.buildStudents().size()); + model.addAttribute("student", StudentUtils.buildStudents().get(0)); + return "functionCall.html"; + } +} diff --git a/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/functionCall.html b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/functionCall.html new file mode 100644 index 0000000000..d21fb7cf27 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/functionCall.html @@ -0,0 +1,32 @@ + + + + +Thymeleaf: Javascript function call + + + + +
+
Thymeleaf: Javascript function call
+
+
+
+ + + + + + +
+
+ + \ No newline at end of file diff --git a/spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FunctionCallIntegrationTest.java b/spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FunctionCallIntegrationTest.java new file mode 100644 index 0000000000..90e8989aae --- /dev/null +++ b/spring-web-modules/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FunctionCallIntegrationTest.java @@ -0,0 +1,57 @@ +package com.baeldung.thymeleaf.controller; + +import com.baeldung.thymeleaf.config.InitSecurity; +import com.baeldung.thymeleaf.config.WebApp; +import com.baeldung.thymeleaf.config.WebMVCConfig; +import com.baeldung.thymeleaf.config.WebMVCSecurity; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockHttpSession; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.RequestPostProcessor; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import javax.servlet.Filter; + +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; +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; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration(classes = { WebApp.class, WebMVCConfig.class, WebMVCSecurity.class, InitSecurity.class }) +public class FunctionCallIntegrationTest { + + @Autowired + WebApplicationContext wac; + @Autowired + MockHttpSession session; + + private MockMvc mockMvc; + + @Autowired + private Filter springSecurityFilterChain; + + private RequestPostProcessor testUser() { + return user("user1").password("user1Pass").roles("USER"); + } + + @Before + public void setup() { + mockMvc = MockMvcBuilders.webAppContextSetup(wac).addFilters(springSecurityFilterChain).build(); + } + + @Test + public void testGetDates() throws Exception { + mockMvc.perform(get("/function-call").with(testUser()).with(csrf())).andExpect(status().isOk()).andExpect(view().name("functionCall.html")); + } + +}