Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target/

.classpath
.project
.settings/

.idea/
*.impl

.vscode/
10 changes: 10 additions & 0 deletions java-multi-modules/web/src/main/webapp/WEB-INF/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">

<body>
<h1 th:text="'Input : ' + ${query}" />
<h1 th:text="'Algorithm : ' + ${algorithm}" />
<h3 th:text="${hash}" />
</body>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,29 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

//https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/testing.html#integration-testing-annotations-junit-jupiter
//@ExtendWith(SpringExtension.class)
//@WebAppConfiguration
//@ContextConfiguration(classes = SpringConfig.class)
@SpringJUnitWebConfig(SpringConfig.class)
@DisplayName("Test Spring MVC default view")
public class TestWelcome {

private MockMvc mockMvc;
private MockMvc mockMvc;

@Autowired
private WebApplicationContext webAppContext;
@Autowired
private WebApplicationContext webAppContext;

@BeforeEach
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build();
}
@BeforeEach
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build();
}

@Test
public void testDefault() throws Exception {
@Test
public void testDefault() throws Exception {

this.mockMvc.perform(
get("/"))
//.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("index"))
.andExpect(model().attribute("query", "123456"));
//.andExpect(model().attribute("sha256", "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92"))
//.andExpect(model().attribute("md5", "e10adc3949ba59abbe56e057f20f883e"));
this.mockMvc.perform(get("/")).andExpect(status().isOk()).andExpect(view().name("index"))
.andExpect(model().attribute("query", "123456"));
// .andExpect(model().attribute("sha256",
// "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92"))
// .andExpect(model().attribute("md5", "e10adc3949ba59abbe56e057f20f883e"));

}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mkyong.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

@EnableWebMvc
@Configuration
@ComponentScan({ "com.mkyong.web" })
public class SpringConfig implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mkyong.multi</groupId>
<artifactId>maven-examples</artifactId>
<packaging>pom</packaging>
<version>1.0</version>

<modules>
<module>java-multi-modules</module>
<module>java-project</module>
<module>java-web-project</module>
<module>maven-code-coverage</module>
<module>maven-mutation-testing</module>
<module>maven-profiles</module>
<module>maven-static-code-analysis</module>
<module>maven-unit-test</module>
</modules>

</project>