From 6d0b3132893fa0c09a9ff8012d8af955abca7583 Mon Sep 17 00:00:00 2001 From: SeoJin Kim Date: Sat, 8 Aug 2020 00:03:02 +0900 Subject: [PATCH] =?UTF-8?q?spring-test/lombok/log4j/Junit=20=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 라이브러리추가(pom.xml) -spring-test -lombok -log4j - 라이브러리 버전 변경(pom.xml) -Junit 4.7 => 4.12 - 의존성 주입 테스트 - com.vam.sample 패키지 생성 - Chef.java / Restaurant.java 생성 - 테스트 위한 클래스 생성 - SampleTests.java 생성 --- VamPa/pom.xml | 31 +++++++++++++++-- VamPa/src/main/java/com/vam/sample/Chef.java | 11 +++++++ .../main/java/com/vam/sample/Restaurant.java | 16 +++++++++ .../webapp/WEB-INF/spring/root-context.xml | 7 ++-- .../test/java/com/vam/sample/SampleTests.java | 32 ++++++++++++++++++ .../maven/com.vam/controller/pom.properties | 4 +-- .../META-INF/maven/com.vam/controller/pom.xml | 31 +++++++++++++++-- VamPa_MySQL/pom.xml | 31 +++++++++++++++-- .../src/main/java/com/vam/sample/Chef.java | 11 +++++++ .../main/java/com/vam/sample/Restaurant.java | 16 +++++++++ .../webapp/WEB-INF/spring/root-context.xml | 6 ++-- .../test/java/com/vam/sample/SampleTests.java | 33 +++++++++++++++++++ .../maven/com.vam/controller/pom.properties | 4 +-- .../META-INF/maven/com.vam/controller/pom.xml | 31 +++++++++++++++-- 14 files changed, 248 insertions(+), 16 deletions(-) create mode 100644 VamPa/src/main/java/com/vam/sample/Chef.java create mode 100644 VamPa/src/main/java/com/vam/sample/Restaurant.java create mode 100644 VamPa/src/test/java/com/vam/sample/SampleTests.java create mode 100644 VamPa_MySQL/src/main/java/com/vam/sample/Chef.java create mode 100644 VamPa_MySQL/src/main/java/com/vam/sample/Restaurant.java create mode 100644 VamPa_MySQL/src/test/java/com/vam/sample/SampleTests.java diff --git a/VamPa/pom.xml b/VamPa/pom.xml index b0d5e8e..fe6d6ec 100644 --- a/VamPa/pom.xml +++ b/VamPa/pom.xml @@ -58,7 +58,7 @@ ${org.slf4j-version} runtime - + + + + + + log4j + log4j + 1.2.17 + + + + + + + org.springframework + spring-test + ${org.springframework-version} + test + + + + + + org.projectlombok + lombok + 1.18.12 + provided @@ -113,7 +140,7 @@ junit junit - 4.7 + 4.12 test diff --git a/VamPa/src/main/java/com/vam/sample/Chef.java b/VamPa/src/main/java/com/vam/sample/Chef.java new file mode 100644 index 0000000..e7ca37e --- /dev/null +++ b/VamPa/src/main/java/com/vam/sample/Chef.java @@ -0,0 +1,11 @@ +package com.vam.sample; + +import org.springframework.stereotype.Component; + +import lombok.Data; + +@Component +@Data +public class Chef { + +} diff --git a/VamPa/src/main/java/com/vam/sample/Restaurant.java b/VamPa/src/main/java/com/vam/sample/Restaurant.java new file mode 100644 index 0000000..49a972c --- /dev/null +++ b/VamPa/src/main/java/com/vam/sample/Restaurant.java @@ -0,0 +1,16 @@ +package com.vam.sample; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import lombok.Data; +import lombok.Setter; + +@Component +@Data +public class Restaurant { + + @Setter(onMethod_=@Autowired) + private Chef chef; + +} diff --git a/VamPa/src/main/webapp/WEB-INF/spring/root-context.xml b/VamPa/src/main/webapp/WEB-INF/spring/root-context.xml index e071144..8c2b519 100644 --- a/VamPa/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/VamPa/src/main/webapp/WEB-INF/spring/root-context.xml @@ -1,8 +1,11 @@ + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> + + - diff --git a/VamPa/src/test/java/com/vam/sample/SampleTests.java b/VamPa/src/test/java/com/vam/sample/SampleTests.java new file mode 100644 index 0000000..f05b011 --- /dev/null +++ b/VamPa/src/test/java/com/vam/sample/SampleTests.java @@ -0,0 +1,32 @@ +package com.vam.sample; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import lombok.extern.log4j.Log4j; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml") +@Log4j +public class SampleTests { + + @Autowired + private Restaurant restaurant; + + @Test + public void textExit() { + + assertNotNull(restaurant); + + log.info(restaurant);; + log.info("-------------------------------"); + log.info(restaurant.getChef()); + + } + +} diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index 650a469..eea623b 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,7 +1,7 @@ #Generated by Maven Integration for Eclipse -#Fri Aug 07 23:14:14 KST 2020 +#Fri Aug 07 23:47:48 KST 2020 version=1.0.0-BUILD-SNAPSHOT groupId=com.vam m2e.projectName=VamPa -m2e.projectLocation=D\:\\Blog_Project\\VamPa +m2e.projectLocation=C\:\\Users\\sjinj\\git\\blog_project\\VamPa artifactId=controller diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml index b0d5e8e..fe6d6ec 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml @@ -58,7 +58,7 @@ ${org.slf4j-version} runtime - + + + + + + log4j + log4j + 1.2.17 + + + + + + + org.springframework + spring-test + ${org.springframework-version} + test + + + + + + org.projectlombok + lombok + 1.18.12 + provided @@ -113,7 +140,7 @@ junit junit - 4.7 + 4.12 test diff --git a/VamPa_MySQL/pom.xml b/VamPa_MySQL/pom.xml index 26845fe..20657d6 100644 --- a/VamPa_MySQL/pom.xml +++ b/VamPa_MySQL/pom.xml @@ -58,7 +58,7 @@ ${org.slf4j-version} runtime - + + + + + + log4j + log4j + 1.2.17 + + + + + + + org.springframework + spring-test + ${org.springframework-version} + test + + + + + + org.projectlombok + lombok + 1.18.12 + provided @@ -113,7 +140,7 @@ junit junit - 4.7 + 4.12 test diff --git a/VamPa_MySQL/src/main/java/com/vam/sample/Chef.java b/VamPa_MySQL/src/main/java/com/vam/sample/Chef.java new file mode 100644 index 0000000..e7ca37e --- /dev/null +++ b/VamPa_MySQL/src/main/java/com/vam/sample/Chef.java @@ -0,0 +1,11 @@ +package com.vam.sample; + +import org.springframework.stereotype.Component; + +import lombok.Data; + +@Component +@Data +public class Chef { + +} diff --git a/VamPa_MySQL/src/main/java/com/vam/sample/Restaurant.java b/VamPa_MySQL/src/main/java/com/vam/sample/Restaurant.java new file mode 100644 index 0000000..c4fa0d6 --- /dev/null +++ b/VamPa_MySQL/src/main/java/com/vam/sample/Restaurant.java @@ -0,0 +1,16 @@ +package com.vam.sample; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import lombok.Data; +import lombok.Setter; + +@Component +@Data +public class Restaurant { + + @Setter(onMethod_=@Autowired) + private Chef chef; + +} diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/spring/root-context.xml b/VamPa_MySQL/src/main/webapp/WEB-INF/spring/root-context.xml index e071144..f04d217 100644 --- a/VamPa_MySQL/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/spring/root-context.xml @@ -1,8 +1,10 @@ + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> - + diff --git a/VamPa_MySQL/src/test/java/com/vam/sample/SampleTests.java b/VamPa_MySQL/src/test/java/com/vam/sample/SampleTests.java new file mode 100644 index 0000000..fba3f23 --- /dev/null +++ b/VamPa_MySQL/src/test/java/com/vam/sample/SampleTests.java @@ -0,0 +1,33 @@ +package com.vam.sample; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import lombok.extern.log4j.Log4j; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml") +@Log4j +public class SampleTests { + + @Autowired + private Restaurant restaurant; + + @Test + public void textExit() { + + assertNotNull(restaurant); + + log.info(restaurant); + log.info("-----------------------------------"); + log.info(restaurant.getChef()); + + } + + +} diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index d728907..7ede2d5 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,7 +1,7 @@ #Generated by Maven Integration for Eclipse -#Fri Aug 07 23:14:53 KST 2020 +#Fri Aug 07 23:49:01 KST 2020 version=1.0.0-BUILD-SNAPSHOT groupId=com.vam m2e.projectName=VamPa_MySQL -m2e.projectLocation=D\:\\Blog_Project\\VamPa_MySQL +m2e.projectLocation=C\:\\Users\\sjinj\\git\\blog_project\\VamPa_MySQL artifactId=controller diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml index 26845fe..20657d6 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.xml @@ -58,7 +58,7 @@ ${org.slf4j-version} runtime - + + + + + + log4j + log4j + 1.2.17 + + + + + + + org.springframework + spring-test + ${org.springframework-version} + test + + + + + + org.projectlombok + lombok + 1.18.12 + provided @@ -113,7 +140,7 @@ junit junit - 4.7 + 4.12 test