๐ Spring
2020.12.12
JUnit์ด๋? ์๋ฐ์ฉ ๋จ์ ํ
์คํธ(Unit Test) ๋๊ตฌ ์ฅ์ ํ
์คํธ๋ฅผ ํ๊ธฐ ์ํด ์ผ์ผํ System.out.prinlnt ๋ก ์ฐ์ด๋ณผ ํ์๊ฐ ์๋ค. @Test ๋ฉ์๋๊ฐ ํธ์ถ๋ ๋ ๋ง๋ค ์๋ก์ด ์ธ์คํด์ค๊ฐ ์์ฑ๋์ด ๋
๋ฆฝ์ ์ธ ํ
์คํธ๊ฐ ์ด๋ฃจ์ด์ง๋ค. ๋จ์ (assert) ๋ฉ์๋๋ก ํ
์คํธ ์ผ์ด์ค์ ์ํ ๊ฒฐ๊ณผ๋ฅผ ํ๋ณํ ์ ์๋ค. TDD(ํ
์คํธ ์ฃผ๋ ๊ฐ๋ฐ)์ด ๊ฐ๋ฅํ๋ค. ์์ ํ๊ธฐ ๊ฐ๋ฐ ํ๊ฒฝ IntelliJ IDEA (2020.2.4) JDK 1.8 JUnit 5 Maven Dependency org.junit.jupiter junit-jupiter-api 5.7.0 test mvnrepository.com/search?q=junit Maven Repository: junit Module "junit-jupiter-a..
๐ Spring
2020.12.12
Personal Access Token Github ์ ์ - profile - Settings Settings / Developer settings / Personal access tokens ์ค๋ฅธ์ชฝ ์๋จ์ Generate new token์ ํด๋ฆญํด์ค๋ค. Note ์๋ ์ด ํ ํฐ์ ๋ฌด์์ ์ํด ์ฌ์ฉํ๋์ง๋ฅผ ๋ฉ๋ชจํ๋ ๊ฒ์ด๊ตฌ, ์๋ scopes๋ repo๋ง ์ฒดํฌํด์ฃผ๊ณ ์๋์ Generate Token์ ๋๋ฌ์ค๋ค. ์ด๋ฌ๋ฉด ๋! ์ด์ ํ ํฐ์ ๋ณต์ฌํด์ ์ฌ์ฉํ๋ฉด ๋๋ค. ์ด ํ ํฐ์ ๋ค์ ๋ณผ ์ ์์ผ๋ ์บก์ฒํ๊ฑฐ๋ ์ด๋ ์ ์ด๋๊ธฐ๋ฅผ ๋ฐ๋๋ค.
๐ Spring
2020.12.11
Github API ์ฌ์ฉ ํ๊ธฐ github-api.kohsuke.org/index.html GitHub API for Java – What is this? This library defines an object oriented representation of the GitHub API. By "object oriented" we mean there are classes that correspond to the domain model of GitHub (such as GHUser and GHRepository), operations that act on them as defined a github-api.kohsuke.org ์ ํ์ด์ง๋ฅผ ๋ค์ด๊ฐ๋ณด๋ฉด, ์....... ์์๋ถํฐ ๋ง๋งํ๋ค. ์์์ ์์ Down..
๐ Spring/Spring REST API
2020.09.12
๋น์ฆ๋์ค ๋ก์ง ์ ์ฉ ๋๋์ง ์๋ต ๋ฉ์์ง ํ์ธ offline ๊ณผ free ๊ฐ ํ์ธ ๋น์ฆ๋์ค ๋ก์ง ์ผ๋จ offline์ location์ ๊ฐ์ด ๋ค์ด์์ผ๋ฉด ์คํ๋ผ์ธ์ด๊ณ , ๊ฐ์ด ์์ผ๋ฉด ์จ๋ผ์ธ์ผ๋ก ์งํ์ด ๋๋ค. free๊ฐ์ basePrice์, MaxPrice๊ฐ ๋ ๋ค 0์ผ๋ , free ์ด๋ค. Event.class ๋๋ฉ์ธ ํด๋์ค์๋ค๊ฐ ๋น์ฆ๋์ค ๋ก์ง์ ์ ์ฉ์์ผ์ค๋ค. public void update() { this.free = (basePrice == 0) && (maxPrice == 0); this.offline = location != null; } EventTests.class @Test public void testOffine() { // Given Event event = Event.builder() ...
๐ Spring/Spring REST API
2020.09.12
์ด๋ฒ์ ํ ๊ฒ์ Bad Request ์๋ต ๋ณธ๋ฌธ ๋ง๋ค๊ธฐ ์ด๋ค. EventController ์ฝ๋๋ฅผ ์ดํด๋ณด๋ฉด, @PostMapping public ResponseEntity createEvent(@RequestBody @Valid EventDto eventDto, Errors errors) { //@Valid ์ค๋ฅ๊ฐ ๋๋ค๋ฉด, ์์กด์ฑ ์ถ๊ฐ : spring-boot-starter-validation ์ ํด์ค๋ค. if (errors.hasErrors()) { return ResponseEntity.badRequest().build(); } eventValidator.validate(eventDto, errors); if (errors.hasErrors()) { return ResponseEntity.badReq..
๐ Spring/Spring REST API
2020.09.10
@Valid ์ BindingResult (๋๋ Errors) BindingResult ๋ ํญ์ @Valid ๋ฐ๋ก ๋ค์ ์ธ์๋ก ์ฌ์ฉํด์ผ ํจ (์คํ๋ง MVC) @NotNull, @NotEmpty, @Min, @Max ... ์ฌ์ฉํด์ ์
๋ ฅ๊ฐ ๋ฐ์ธ๋ฉ ํ ๋ ์๋ฌ ํ์ธ์ด ๊ฐ๋ฅํ๋ค ๋๋ฉ์ธ Validator ๋ง๋ค๊ธฐ Validator ์ธํฐํ์ด์ค ์์ด ๋ง๋ค์ด๋ ์๊ด์๋ค. @Component public class EventValidator { public void validate(EventDto eventDto, Errors errors) { if (eventDto.getBasePrice() > eventDto.getMaxPrice() && eventDto.getMaxPrice() != 0) { errors.reject..