Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spring-mvc-1/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ resources/static 아래의 경로에 위치한 파일은 접근이 가능합니
정적 페이지 설정을 연습하는 학습 테스트 입니다.
- 테스트 메서드: `cholog.ResponseStaticTest.responseStaticPage`
- 수행 방법
- `resources/templates/hello.html` 을 이용하여 학습 테스트를 성공시키세요.
- `resources/templates/static.html` 을 이용하여 학습 테스트를 성공시키세요.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

- 정적 페이지 설정을 위해 적절한 위치에 이동을 하거나 파일명을 변경해보세요.

<br>
Expand Down Expand Up @@ -108,4 +108,4 @@ Model 객체는 컨트롤러 메서드의 파라미터로 주입 받을 수 있

### 참고자료
- [Spring - @ResponseBody](https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-methods/responsebody.html#page-title)
- [Spring - Return Values > Other return values](https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-methods/return-types.html)
- [Spring - Return Values > Other return values](https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-methods/return-types.html)
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ResponseController {
@GetMapping("/template")
public String template(@RequestParam(name = "name", required = false, defaultValue = "World") String name, Model model) {
public class MemberController {
@GetMapping("/hello")
public String world(@RequestParam(name = "name", required = false, defaultValue = "World") String name, Model model) {
model.addAttribute("name", name);
return "template";
return "hello";
}

@GetMapping("/person")
@GetMapping("/json")
@ResponseBody
public Person person() {
return new Person("Brown", 20);
public Person json() {
return new Person("brown", 20);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<body>
Hello World!
</body>
</html>
</html>
15 changes: 7 additions & 8 deletions spring-mvc-1/complete/src/test/java/cholog/ResponseJsonTest.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package cholog;

import static org.assertj.core.api.Assertions.assertThat;

import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ResponseJsonTest {
class ResponseJsonTest {

@Test
void responseJson() {
var response = RestAssured
.given().log().all()
.when().get("/person")
.then().log().all().extract();
.given().log().all()
.when().get("/json")
.then().log().all().extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
assertThat(response.as(Person.class).getName()).isEqualTo("Brown");
assertThat(response.as(Person.class).getName()).isEqualTo("brown");
assertThat(response.as(Person.class).getAge()).isEqualTo(20);
}

}
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package cholog;

import static org.assertj.core.api.Assertions.assertThat;

import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ResponseStaticTest {
class ResponseStaticTest {

@Test
void responseIndexPage() {
var response = RestAssured
.given().log().all()
.when().get("/")
.then().log().all().extract();
.given().log().all()
.when().get("/")
.then().log().all().extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
}

@Test
void responseStaticPage() {
var response = RestAssured
.given().log().all()
.when().get("/hello.html")
.then().log().all().extract();
.given().log().all()
.when().get("/static.html")
.then().log().all().extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package cholog;

import static org.assertj.core.api.Assertions.assertThat;

import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ResponseTemplatesTest {
class ResponseTemplatesTest {

@Test
void responseTemplatesPage() {
void responseTemplatesHelloPage() {
var response = RestAssured
.given().log().all()
.when().get("/template?name=Brie")
.then().log().all().extract();
.given().log().all()
.when().get("/hello?name=Brie")
.then().log().all().extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
assertThat(response.asString()).contains("Hello, Brie!");
Expand Down
14 changes: 7 additions & 7 deletions spring-mvc-1/initial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<br>

스프링 부트는 정적 페이지와 템플릿 시작 페이지를 모두 지원합니다.
먼저 구성된 정적 콘텐츠 위치에서 index.html 파일을 찾습니다.
하나라도 없으면 index 템플릿을 찾습니다.
스프링 부트는 정적 페이지와 템플릿 시작 페이지를 모두 지원합니다.
먼저 구성된 정적 콘텐츠 위치에서 index.html 파일을 찾습니다.
하나라도 없으면 index 템플릿을 찾습니다.
둘 중 하나라도 찾으면 자동으로 응용 프로그램 시작 페이지로 사용됩니다.

<br>
Expand Down Expand Up @@ -43,7 +43,7 @@ welcome page 설정을 연습하는 학습 테스트 입니다.

<br>

resources/static 아래의 경로에 위치한 파일은 접근이 가능합니다.
resources/static 아래의 경로에 위치한 파일은 접근이 가능합니다.
서비스에서 필요한 정적 자원들을 해당 경로에 위치시킨 후 활용할 수 있습니다.

<br>
Expand All @@ -52,7 +52,7 @@ resources/static 아래의 경로에 위치한 파일은 접근이 가능합니
정적 페이지 설정을 연습하는 학습 테스트 입니다.
- 테스트 메서드: `cholog.ResponseStaticTest.responseStaticPage`
- 수행 방법
- `resources/templates/hello.html` 을 이용하여 학습 테스트를 성공시키세요.
- `resources/templates/static.html` 을 이용하여 학습 테스트를 성공시키세요.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

- 정적 페이지 설정을 위해 적절한 위치에 이동을 하거나 파일명을 변경해보세요.

<br>
Expand All @@ -78,7 +78,7 @@ Model 객체는 컨트롤러 메서드의 파라미터로 주입 받을 수 있
- 테스트 메서드: `cholog.ResponseTemplatesTest.responseTemplatesPage`
- 수행 방법
- `cholog.MemberController.world` 메서드를 작성하여 학습 테스트를 성공시키세요.
- `/hello` 요청 시 `resources/templates/hello.html` 페이지가 응답할 수 있도록 설정하세요.
- `/hello` 요청 시 `resources/templates/hello.html` 페이지가 응답할 수 있도록 설정하세요.

<br>

Expand Down Expand Up @@ -108,4 +108,4 @@ Model 객체는 컨트롤러 메서드의 파라미터로 주입 받을 수 있

### 참고자료
- [Spring - @ResponseBody](https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-methods/responsebody.html#page-title)
- [Spring - Return Values > Other return values](https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-methods/return-types.html)
- [Spring - Return Values > Other return values](https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-methods/return-types.html)
18 changes: 18 additions & 0 deletions spring-mvc-1/initial/src/main/java/cholog/MemberController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cholog;

import org.springframework.stereotype.Controller;

@Controller
public class MemberController {

public String world() {
// TODO: /hello 요청 시 resources/templates/static.html 페이지가 응답할 수 있도록 설정하세요.
// TODO: 쿼리 파라미터로 name 요청이 들어왔을 때 해당 값을 hello.html에서 사용할 수 있도록 하세요.
return null;
}

public Person json() {
// TODO: /json 요청 시 {"name": "brown", "age": 20} 데이터를 응답할 수 있도록 설정하세요.
return null;
}
}
22 changes: 0 additions & 22 deletions spring-mvc-1/initial/src/main/java/cholog/ResponseController.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<body>
Welcome!
</body>
</html>
</html>
15 changes: 7 additions & 8 deletions spring-mvc-1/initial/src/test/java/cholog/ResponseJsonTest.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package cholog;

import static org.assertj.core.api.Assertions.assertThat;

import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ResponseJsonTest {
class ResponseJsonTest {

@Test
void responseJson() {
var response = RestAssured
.given().log().all()
.when().get("/person")
.then().log().all().extract();
.given().log().all()
.when().get("/json")
.then().log().all().extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
assertThat(response.as(Person.class).getName()).isEqualTo("Brown");
assertThat(response.as(Person.class).getName()).isEqualTo("brown");
assertThat(response.as(Person.class).getAge()).isEqualTo(20);
}

}
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package cholog;

import static org.assertj.core.api.Assertions.assertThat;

import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ResponseStaticTest {
class ResponseStaticTest {

@Test
void responseIndexPage() {
var response = RestAssured
.given().log().all()
.when().get("/")
.then().log().all().extract();
.given().log().all()
.when().get("/")
.then().log().all().extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
}

@Test
void responseStaticPage() {
var response = RestAssured
.given().log().all()
.when().get("/hello.html")
.then().log().all().extract();
.given().log().all()
.when().get("/static.html")
.then().log().all().extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package cholog;

import static org.assertj.core.api.Assertions.assertThat;

import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ResponseTemplatesTest {
class ResponseTemplatesTest {

@Test
void responseTemplatesPage() {
void responseTemplatesHelloPage() {
var response = RestAssured
.given().log().all()
.when().get("/template?name=Brie")
.then().log().all().extract();
.given().log().all()
.when().get("/hello?name=Brie")
.then().log().all().extract();

assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
assertThat(response.asString()).contains("Hello, Brie!");
Expand Down