From f32626e5f78bf1698035b9badcd3eddb2b1400d6 Mon Sep 17 00:00:00 2001 From: devAon Date: Sun, 26 Jul 2020 02:06:59 +0900 Subject: [PATCH] =?UTF-8?q?[ADD]=20HelloController=20=EB=B0=8F=20TDD=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executionHistory/executionHistory.bin | Bin 20135 -> 0 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 0 bytes .gradle/5.2.1/fileChanges/last-build.bin | Bin 1 -> 0 bytes .gradle/5.2.1/fileHashes/fileHashes.bin | Bin 18697 -> 0 bytes .gradle/5.2.1/fileHashes/fileHashes.lock | Bin 17 -> 0 bytes .gradle/5.2.1/gc.properties | 0 .../buildOutputCleanup.lock | Bin 17 -> 0 bytes .gradle/buildOutputCleanup/cache.properties | 2 - .gradle/buildOutputCleanup/outputFiles.bin | Bin 18659 -> 0 bytes .gradle/vcs-1/gc.properties | 0 .idea/gradle.xml | 4 - .idea/jarRepositories.xml | 25 ------ .idea/misc.xml | 7 -- .idea/vcs.xml | 6 -- README.md | 74 +++++++++++++++++- gradle/wrapper/gradle-wrapper.properties | 2 +- .../devAon/aoneemall/web/HelloController.java | 18 +++++ .../aoneemall/web/HelloControllerTest.java | 35 +++++++++ 18 files changed, 125 insertions(+), 48 deletions(-) delete mode 100644 .gradle/5.2.1/executionHistory/executionHistory.bin delete mode 100644 .gradle/5.2.1/executionHistory/executionHistory.lock delete mode 100644 .gradle/5.2.1/fileChanges/last-build.bin delete mode 100644 .gradle/5.2.1/fileHashes/fileHashes.bin delete mode 100644 .gradle/5.2.1/fileHashes/fileHashes.lock delete mode 100644 .gradle/5.2.1/gc.properties delete mode 100644 .gradle/buildOutputCleanup/buildOutputCleanup.lock delete mode 100644 .gradle/buildOutputCleanup/cache.properties delete mode 100644 .gradle/buildOutputCleanup/outputFiles.bin delete mode 100644 .gradle/vcs-1/gc.properties delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/vcs.xml create mode 100644 src/main/java/com/devAon/aoneemall/web/HelloController.java create mode 100644 src/test/java/com/devAon/aoneemall/web/HelloControllerTest.java diff --git a/.gradle/5.2.1/executionHistory/executionHistory.bin b/.gradle/5.2.1/executionHistory/executionHistory.bin deleted file mode 100644 index a948eaa5a36f900f8d223031477af987400dadb5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20135 zcmeI(PiWIn90%~E(b2hyMNtM`JWN5b>Hkf3nJcZ^V4bpB|51r)^4ezWn)s5gv1%o@ z4KYlc<5%TiR*s!3O|&2Y0SG_<0uX=z1Rwwb2tWV=5P$##AOHafKmY;|_+JEKW+7Xw zV%iSaN{wxKhH#6>JP`#S>_gj59LjVF0fB*y_009U<00Izz z00bZa0SG_<0uX=z1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz00bcLF9`S; zrs<6NGXF2o6uT+vnUP{q8VzKLnAHlybR?gY#|*jXx7NxoGxt=Q;!{+VGlUm4g*QZf zMCbEV)HFi*6V_D-5lN+@L1afuWPGn2efz%q&JEx7v&|9PUq@hGutG4WWaOws70nRZ z1)9qWQbyHtlz7^!Ew3PZB)7NoVAAX9^acDrw?7f^5i!}}@q3c8Pf9qRFFfw;YGpqB zDDYXbfu;q2;!(X{9dbVPHb%$jM(3L3FLSXa%VRm(3;n+Wy~ zUR#|aMl;-_v|(s^m&>ISI;KcOukIQ%MVX-rpu4Q?| zcd6XTY??}lhLpD6dG>y&E1pt}A)=|eVyLtbk7`uOrh=+!ID6DAArUc?iCdBKyg8L~ zoF5oHG5PNMw{uH}a<)$`n>P?-15;|!P7aIou#zF{OSYaO;+1_=smWRW+?mlhhiCT5 z>EZ=8ochwtJ!3yUZCvceMXFikRgJ3VlfzJmUiMgSh{sA$&M`lD+1s@1XK?P-=eylY zJNB`SPSNmyHA}vtmmhUypv8LjOP+JgK76wf-*bEWSNp_Vy!YZbTVH@Whu5YvzgQB# E0gS$o=>Px# diff --git a/.gradle/5.2.1/executionHistory/executionHistory.lock b/.gradle/5.2.1/executionHistory/executionHistory.lock deleted file mode 100644 index ab4a0c58258b0ed5a4d96d97228470fb0837d5b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17 UcmZR+@T2K=$ND@81_)pV06`N3=>Px# diff --git a/.gradle/5.2.1/fileChanges/last-build.bin b/.gradle/5.2.1/fileChanges/last-build.bin deleted file mode 100644 index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1 IcmZPo000310RR91 diff --git a/.gradle/5.2.1/fileHashes/fileHashes.bin b/.gradle/5.2.1/fileHashes/fileHashes.bin deleted file mode 100644 index c030f51dc96a89664f3b772e101df135065468bf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 18697 zcmeI(KS%;m0LSrn_6Pd|NmkfaME@wlYH2e=sX^LG2=}H2u?V6vA|hMbZfY^msUc{R z;K0DanrcWWTq0^{YmV$4_a1UMw#E0syLu3={Z}ea>0IAso^o@z&n5Ju{FSbg{}yjA(ol)Eu)7T0#tMs)qXt*K@0|c-E05aF03nS6-~a#s diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties deleted file mode 100644 index f3ca522..0000000 --- a/.gradle/buildOutputCleanup/cache.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Sat Jul 25 22:24:13 KST 2020 -gradle.version=5.2.1 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin deleted file mode 100644 index 374c594a97e39ee9c9ac87f26d22cddc28686de7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 18659 zcmeI&u}cC`9Ki8sn)TV3zG-!F+aNBKT@?;hXd4&GKRud_FaQ7m diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties deleted file mode 100644 index e69de29..0000000 diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 3e3960b..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index b3e9cbd..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index bc8d0a3..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index e32e662..04916a0 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,15 @@ Git Tools : Git Bash OS : Window SpringBoot 2.1.9 Java8 -Gradle +Gradle 4.10.2 ๐Ÿ‘‰ springBootVersion 2.1.7 / 2.1.8 / 2.1.9 ๋ชจ๋‘ ๊ดœ์ฐฎ์œผ๋‚˜, 2.2 ์ด์ƒ ๋ฒ„์ „์—์„œ๋Š” ์ •์ƒ์ž‘๋™ ํ•˜์ง€ ์•Š๋Š”๋‹ค. + ๐Ÿ‘‰ Gradle 5.x์—์„œ๋Š” ์ •์ƒ์ž‘๋™ ํ•˜์ง€ ์•Š๋Š”๋‹ค. + `Gradle 4.10.2 ` ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ• ? + +โ€‹ ์ธํ…”๋ฆฌ์ œ์ด์—์„œ `alt+F12` ๋ˆŒ๋Ÿฌ ๐Ÿ‘‰ ํ„ฐ๋ฏธ๋„์—์„œ `gradlew wrapper --gradle-version 4.10.2` ๋ช…๋ น์–ด ์‹คํ–‰ +
@@ -152,7 +157,7 @@ public class Application { ๐Ÿฅ **๋‚ด์žฅ WAS ๋ž€ ?** * ์™ธ๋ถ€์— WAS๋ฅผ ๋‘์ง€ ์•Š๊ณ  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•  ๋•Œ ๋‚ด๋ถ€์—์„œ WAS๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธ - * ์™œ ? + * ๋‚ด์žฅ WAS ์‚ฌ์šฉ ์ด์œ  ? ํ•ญ์ƒ ์„œ๋ฒ„์— ํ†ฐ์บฃ์„ ์„ค์น˜ํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค. ์Šคํ”„๋ง ๋ถ€ํŠธ๋กœ ๋งŒ๋“ค์–ด์ง„ Jar ํŒŒ์ผ (์‹คํ–‰ ๊ฐ€๋Šฅํ•œ Java ํŒจํ‚ค์ง• ํŒŒ์ผ)๋กœ ์‹คํ–‰ํ•˜๋ฉด ๋œ๋‹ค. * `์–ธ์ œ ์–ด๋””์„œ๋‚˜ ๊ฐ™์€ ํ™˜๊ฒฝ์—์„œ ์Šคํ”„๋ง ๋ถ€ํŠธ๋ฅผ ๋ฐฐํฌ` ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‚ด์žฅ WAS ์‚ฌ์šฉ ๊ถŒ์žฅ @@ -161,11 +166,27 @@ public class Application { +
+ + +### ๐Ÿ“ API ์ž‘์„ฑ +* **@RestController** + : JSON์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ๋กœ ๋งŒ๋“ค์–ด์ค€๋‹ค +* **@GetMapping** + : HTTP Method์ธ Get์˜ ์š”์ฒญ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” API๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค + +* **@PostMapping, @PutMapping, @DeleteMapping** + + + + + +
@@ -226,5 +247,52 @@ public class Application { -### +### ๐Ÿ“ TDD ์ž‘์„ฑ + +* **@RunWith(SpringRunner.class)** + + : ์Šคํ”„๋ง ๋ถ€ํŠธ ํ…Œ์ŠคํŠธ์™€ JUnit ์‚ฌ์ด์— ์—ฐ๊ฒฐ์ž ์—ญํ•  + ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•  ๋•Œ JUnit์— ๋‚ด์žฅ๋œ ์‹คํ–‰์ž ์™ธ์— ๋‹ค๋ฅธ ์‹คํ–‰์ž๋ฅผ ์‹คํ–‰์‹œํ‚จ๋‹ค. + ์‹คํ–‰์ž : SpringRunner + +* **@WebMvcTest** + + : ์—ฌ๋Ÿฌ ์Šคํ”„๋ง ํ…Œ์ŠคํŠธ ์–ด๋…ธํ…Œ์ด์…˜ ์ค‘, Web (Spring MVC)์— ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๋Š” ์–ด๋…ธํ…Œ์ด์…˜ + + ์‚ฌ์šฉ ๊ฐ€๋Šฅ - @Controller, @ControllerAdvice + + ์‚ฌ์šฉ ๋ถˆ๊ฐ€๋Šฅ - @Service, @Component, @Repository + +* **@Autowired** + + : ์Šคํ”„๋ง์ด ๊ด€๋ฆฌํ•˜๋Š” ๋นˆ(Bean)์„ ์ฃผ์ž… ๋ฐ›๋Š”๋‹ค. + +* **private MockMvc mvc** + + : ์›น API ๋ฅผ ํ…Œ์ŠคํŠธํ•  ๋•Œ ์‚ฌ์šฉ + + ์Šคํ”„๋ง MVC ํ…Œ์ŠคํŠธ์˜ ์‹œ์ž‘์  + + ์ด ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด HTTP GET, POST ๋“ฑ์— ๋Œ€ํ•œ API ํ…Œ์ŠคํŠธ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋‹ค. + +* **mvc.perform(get("/hello"))** + + : MockMvc๋ฅผ ํ†ตํ•ด /hello ์ฃผ์†Œ๋กœ HTTP GET ์š”์ฒญ์„ ํ•œ๋‹ค + + ์ฒด์ด๋‹์ด ์ง€์›๋˜์–ด ์—ฌ๋Ÿฌ ๊ฒ€์ฆ ๊ธฐ๋Šฅ์„ ์ด์–ด์„œ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋‹ค. + +* **.andExpect(status().isOk())** + + : mvc.perform ์˜ ๊ฒฐ๊ณผ๋ฅผ ๊ฒ€์ฆํ•œ๋‹ค. + + HTTP Header์˜ `Status๋ฅผ ๊ฒ€์ฆ`ํ•œ๋‹ค. + + Status์ธ 200,404, 500 ๋“ฑ ์ƒํƒœ ์ค‘ 200์ธ์ง€ ๊ฒ€์ฆํ•œ๋‹ค + +* **.andExpect(content().string(hello))** + + : mvc.perform ์˜ ๊ฒฐ๊ณผ๋ฅผ ๊ฒ€์ฆํ•œ๋‹ค. + + `์‘๋‹ต ๋ณธ๋ฌธ์˜ ๋‚ด์šฉ์„ ๊ฒ€์ฆ`ํ•œ๋‹ค. + Controller์—์„œ ๋ฆฌํ„ดํ•˜๋Š” "hello"์™€ ๋‚ด์šฉ์ด ์ผ์น˜ํ•˜๋Š”์ง€ ๊ฒ€์ฆํ•œ๋‹ค. \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 44e7c4d..e0b3fb8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/devAon/aoneemall/web/HelloController.java b/src/main/java/com/devAon/aoneemall/web/HelloController.java new file mode 100644 index 0000000..8f6548d --- /dev/null +++ b/src/main/java/com/devAon/aoneemall/web/HelloController.java @@ -0,0 +1,18 @@ +package com.devAon.aoneemall.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Created by qwone4@gmail.com on 2020-07-26 + * Blog : https://velog.io/@aonee + * Github : http://github.com/devAon + */ + +@RestController +public class HelloController { + @GetMapping("/hello") + public String hello(){ + return "hello"; + } +} diff --git a/src/test/java/com/devAon/aoneemall/web/HelloControllerTest.java b/src/test/java/com/devAon/aoneemall/web/HelloControllerTest.java new file mode 100644 index 0000000..dc76cba --- /dev/null +++ b/src/test/java/com/devAon/aoneemall/web/HelloControllerTest.java @@ -0,0 +1,35 @@ +package com.devAon.aoneemall.web; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * Created by qwone4@gmail.com on 2020-07-26 + * Blog : https://velog.io/@aonee + * Github : http://github.com/devAon + */ + + +@RunWith(SpringRunner.class) +@WebMvcTest(controllers = HelloController.class) +public class HelloControllerTest { + @Autowired + private MockMvc mvc; + + @Test + public void hello๊ฐ€_๋ฆฌํ„ด๋œ๋‹ค() throws Exception{ + String hello = "hello"; + + mvc.perform(get("/hello")) + .andExpect(status().isOk()) + .andExpect(content().string(hello)); + } +}