Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed May 26, 2022
0 parents commit 5a8f7bc
Show file tree
Hide file tree
Showing 41 changed files with 400 additions and 0 deletions.
105 changes: 105 additions & 0 deletions pom.xml
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>
23 changes: 23 additions & 0 deletions src/main/java/com/njonecompany/web/WebInitializer.java
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 src/main/java/com/njonecompany/web/config/SpringConfig.java
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;
}
}
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";
}

}
22 changes: 22 additions & 0 deletions src/main/resources/logback.xml
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>
8 changes: 8 additions & 0 deletions src/main/webapp/WEB-INF/views/index.jsp
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>
7 changes: 7 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
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>
41 changes: 41 additions & 0 deletions src/test/java/com/njonecompany/web/TestWelcome.java
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 not shown.
22 changes: 22 additions & 0 deletions target/classes/logback.xml
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.
22 changes: 22 additions & 0 deletions target/hello-world/WEB-INF/classes/logback.xml
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 added target/hello-world/WEB-INF/lib/jstl-1.2.jar
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.
8 changes: 8 additions & 0 deletions target/hello-world/WEB-INF/views/index.jsp
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>
7 changes: 7 additions & 0 deletions target/hello-world/WEB-INF/web.xml
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>
4 changes: 4 additions & 0 deletions target/maven-archiver/pom.properties
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
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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com/njonecompany/web/TestWelcome.class
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
Loading

0 comments on commit 5a8f7bc

Please sign in to comment.