-
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.
Showing
8 changed files
with
111 additions
and
2 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
rootProject.name = 'freelec-springboot2-webservice' | ||
rootProject.name = ' -springboot2-webservice' | ||
|
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,11 @@ | ||
package com.spring.book.springboot; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
public static void main(String[] args){ | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/spring/book/springboot/web/HelloController.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,21 @@ | ||
package com.spring.book.springboot.web; | ||
|
||
import com.spring.book.springboot.web.dto.HelloResponseDto; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HelloController { | ||
@GetMapping("/hello") | ||
public String hello() { | ||
return "hello"; | ||
} | ||
|
||
@GetMapping("/hello/dto") | ||
public HelloResponseDto helloDto(@RequestParam("name") String name, | ||
@RequestParam("age") int age) { | ||
return new HelloResponseDto(name, age); | ||
} | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
src/main/java/com/spring/book/springboot/web/dto/HelloResponseDto.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,11 @@ | ||
package com.spring.book.springboot.web.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class HelloResponseDto { | ||
private final String name; | ||
private final int age; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/java/com/spring/book/springboot/HelloControllerTest.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,44 @@ | ||
package com.spring.book.springboot; | ||
|
||
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.hamcrest.Matchers.is; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
//@WebMvcTest(controllers = HelloController.class) | ||
@RunWith(SpringRunner.class) | ||
@WebMvcTest | ||
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)); | ||
} | ||
|
||
@Test | ||
public void helloDto가_리턴된다() throws Exception { | ||
String name = "Gimquokka"; | ||
int age = 26; | ||
|
||
mvc.perform( | ||
get("/hello/dto") // 아... /hello 구나...ㅜㅜ | ||
.param("name", name) | ||
.param("age", String.valueOf(age))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.name", is(name))) | ||
.andExpect(jsonPath("$.age", is(age))); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/spring/book/springboot/dto/HelloResponseDtoTest.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,21 @@ | ||
package com.spring.book.springboot.dto; | ||
|
||
import com.spring.book.springboot.web.dto.HelloResponseDto; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class HelloResponseDtoTest { | ||
|
||
@Test | ||
public void 롬북_기능_테스트(){ | ||
String name = "Gimquokka"; | ||
int age = 26; | ||
|
||
HelloResponseDto dto = new HelloResponseDto(name, age); | ||
|
||
assertThat(dto.getName()).isEqualTo(name); | ||
assertThat(dto.getAge()).isEqualTo(age); | ||
} | ||
|
||
} |