forked from sdcodebase/cicd-web-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a8f7bc
Showing
41 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.njonecompany.web</groupId> | ||
<artifactId>web</artifactId> | ||
<packaging>war</packaging> | ||
<version>1.0</version> | ||
<name>cicd-web-project maven webapp</name> | ||
<url>http://maven.apache.org</url> | ||
<properties> | ||
<!-- https://maven.apache.org/general.html#encoding-warning --> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<spring.version>5.3.17</spring.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<!-- logging , spring 5 no more bridge, thanks spring-jcl --> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.3</version> | ||
</dependency> | ||
|
||
<!-- junit 5, unit test --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.3.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- unit test --> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-library</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- for web servlet --> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
</dependency> | ||
|
||
<!-- Some containers like Tomcat don't have jstl library --> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet.jsp</groupId> | ||
<artifactId>javax.servlet.jsp-api</artifactId> | ||
<version>2.3.1</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
<build> | ||
<finalName>hello-world</finalName> | ||
<plugins> | ||
<!-- http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html --> | ||
<plugin> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-maven-plugin</artifactId> | ||
<version>9.4.12.v20180830</version> | ||
</plugin> | ||
|
||
<!-- Default is too old, update to latest to run the latest Spring 5 + jUnit 5 --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.0</version> | ||
</plugin> | ||
|
||
<!-- Default 2.2 is too old, update to latest --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>3.2.2</version> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.njonecompany.web; | ||
|
||
import com.njonecompany.web.config.SpringConfig; | ||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; | ||
|
||
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { | ||
|
||
@Override | ||
protected Class<?>[] getRootConfigClasses() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getServletConfigClasses() { | ||
return new Class[]{SpringConfig.class}; | ||
} | ||
|
||
@Override | ||
protected String[] getServletMappings() { | ||
return new String[]{"/"}; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/njonecompany/web/config/SpringConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.njonecompany.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.njonecompany.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; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/njonecompany/web/controller/WelcomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.njonecompany.web.controller; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
import java.util.Date; | ||
|
||
@Controller | ||
public class WelcomeController { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(WelcomeController.class); | ||
|
||
@GetMapping("/") | ||
public String index(Model model) { | ||
logger.debug("Welcome to njonecompany.com..."); | ||
model.addAttribute("msg", getMessage()); | ||
model.addAttribute("today", new Date()); | ||
System.out.println(model.getAttribute("today")); | ||
return "index"; | ||
|
||
} | ||
|
||
private String getMessage() { | ||
return "Hello World"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
|
||
<Pattern> | ||
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n | ||
</Pattern> | ||
|
||
</layout> | ||
</appender> | ||
|
||
<logger name="com.njonecompany.web" level="debug" | ||
additivity="false"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
|
||
<root level="error"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%@ page isELIgnored="false" %> | ||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> | ||
<html> | ||
<body> | ||
<h1>${msg}</h1> | ||
<h2>Today is <fmt:formatDate value="${today}" pattern="yyyy-MM-dd" /></h2> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE web-app PUBLIC | ||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | ||
"http://java.sun.com/dtd/web-app_2_3.dtd" > | ||
|
||
<web-app> | ||
<display-name>Archetype Created Web Application</display-name> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.njonecompany.web; | ||
|
||
import com.njonecompany.web.config.SpringConfig; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@SpringJUnitWebConfig(SpringConfig.class) | ||
public class TestWelcome { | ||
|
||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private WebApplicationContext webAppContext; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext).build(); | ||
} | ||
|
||
@Test | ||
public void testWelcome() throws Exception { | ||
|
||
this.mockMvc.perform( | ||
get("/")) | ||
.andDo(print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(view().name("index")) | ||
.andExpect(forwardedUrl("/WEB-INF/views/index.jsp")) | ||
.andExpect(model().attribute("msg", "Hello World")); | ||
} | ||
|
||
} |
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.47 KB
target/classes/com/njonecompany/web/controller/WelcomeController.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
|
||
<Pattern> | ||
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n | ||
</Pattern> | ||
|
||
</layout> | ||
</appender> | ||
|
||
<logger name="com.njonecompany.web" level="debug" | ||
additivity="false"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
|
||
<root level="error"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
</configuration> |
Binary file added
BIN
+842 Bytes
target/hello-world/WEB-INF/classes/com/njonecompany/web/WebInitializer.class
Binary file not shown.
Binary file added
BIN
+1.89 KB
target/hello-world/WEB-INF/classes/com/njonecompany/web/config/SpringConfig.class
Binary file not shown.
Binary file added
BIN
+1.47 KB
target/hello-world/WEB-INF/classes/com/njonecompany/web/controller/WelcomeController.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
|
||
<Pattern> | ||
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n | ||
</Pattern> | ||
|
||
</layout> | ||
</appender> | ||
|
||
<logger name="com.njonecompany.web" level="debug" | ||
additivity="false"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
|
||
<root level="error"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
</configuration> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%@ page isELIgnored="false" %> | ||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> | ||
<html> | ||
<body> | ||
<h1>${msg}</h1> | ||
<h2>Today is <fmt:formatDate value="${today}" pattern="yyyy-MM-dd" /></h2> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE web-app PUBLIC | ||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | ||
"http://java.sun.com/dtd/web-app_2_3.dtd" > | ||
|
||
<web-app> | ||
<display-name>Archetype Created Web Application</display-name> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#Created by Apache Maven 3.6.3 | ||
groupId=com.njonecompany.web | ||
artifactId=web | ||
version=1.0 |
3 changes: 3 additions & 0 deletions
3
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
com/njonecompany/web/config/SpringConfig.class | ||
com/njonecompany/web/controller/WelcomeController.class | ||
com/njonecompany/web/WebInitializer.class |
3 changes: 3 additions & 0 deletions
3
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/Users/dowonlee_1/Desktop/git/hello-world/cicd-web-project/src/main/java/com/njonecompany/web/controller/WelcomeController.java | ||
/Users/dowonlee_1/Desktop/git/hello-world/cicd-web-project/src/main/java/com/njonecompany/web/config/SpringConfig.java | ||
/Users/dowonlee_1/Desktop/git/hello-world/cicd-web-project/src/main/java/com/njonecompany/web/WebInitializer.java |
1 change: 1 addition & 0 deletions
1
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com/njonecompany/web/TestWelcome.class |
1 change: 1 addition & 0 deletions
1
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Users/dowonlee_1/Desktop/git/hello-world/cicd-web-project/src/test/java/com/njonecompany/web/TestWelcome.java |
Oops, something went wrong.