Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step3리뷰 요청드립니다. #501

Open
wants to merge 25 commits into
base: sang-eun
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8ba6868
first commit
sang-eun Jul 7, 2022
2c883bb
[add] api 테스트 추가
sang-eun Jul 10, 2022
6e12f68
Merge branch 'sang-eun' into step1
sang-eun Jul 10, 2022
b4e2282
[add] 테스트 리스트
sang-eun Jul 10, 2022
5aed214
[add] create api 및 테스트 추가
sang-eun Jul 10, 2022
599824c
[modify] line 테스트 beforeAll 추가해서 자원공유하도록 수정
sang-eun Jul 10, 2022
325e5ab
[modify] step1 코드리뷰 반영
sang-eun Jul 12, 2022
2594684
[add] get api 테스트
sang-eun Jul 12, 2022
489e81a
[add] get lines api
sang-eun Jul 12, 2022
8beeb22
[add] get line api
sang-eun Jul 12, 2022
e094936
[add] update line api
sang-eun Jul 12, 2022
15ae19d
[add] delete line api
sang-eun Jul 12, 2022
3ecd092
[add] controllerAdvice 추가하려고 했으나 제대로 동작하지 않음. 캐치하고 204에러를 리턴해야 하는데, 계…
sang-eun Jul 12, 2022
3007872
Merge branch 'step1' of github.com:sang-eun/atdd-subway-map into step2
sang-eun Jul 12, 2022
47b5e09
[modify] 불필요한 부분 수정
sang-eun Jul 12, 2022
112e8c0
Merge remote-tracking branch 'upstream/sang-eun' into step2
sang-eun Jul 12, 2022
1d49dc3
코드리뷰 반영
sang-eun Jul 24, 2022
6181976
[add] 섹션 기반 코드 작성
sang-eun Jul 30, 2022
b992dd1
[add] 섹션 추가 api
sang-eun Jul 30, 2022
bcc0eb3
[modify] Line과 section 관계
sang-eun Jul 31, 2022
b5bb1d9
[add] 구간 삭제 테스트 추가
sang-eun Jul 31, 2022
4b11cea
[add] 구간 삭제 api 추가
sang-eun Jul 31, 2022
44a6707
[modify] section 저장 로직 수정
sang-eun Aug 1, 2022
b74b646
코드리뷰 반영
sang-eun Aug 6, 2022
33c993d
Merge branch 'sang-eun' of https://github.com/next-step/atdd-subway-m…
sang-eun Aug 6, 2022
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
Prev Previous commit
Next Next commit
[add] api 테스트 추가
  • Loading branch information
sang-eun committed Jul 10, 2022
commit 2c883bbeca03c794c010b460e6fdfd52ea2d4f54
33 changes: 33 additions & 0 deletions src/test/java/nextstep/subway/acceptance/AcceptanceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package nextstep.subway.acceptance;

import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;

import java.util.Map;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class AcceptanceTest {

ExtractableResponse<Response> get(String path) {
return RestAssured.given().log().all()
.when().get(path)
.then().log().all().extract();
}

ExtractableResponse<Response> post(String path, Map<String, String> params) {
return RestAssured.given().log().all()
.body(params)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when().post(path)
.then().log().all().extract();
}

ExtractableResponse<Response> delete(String path) {
return RestAssured.given().log().all()
.when().delete(path)
.then().log().all().extract();
}
}
142 changes: 75 additions & 67 deletions src/test/java/nextstep/subway/acceptance/StationAcceptanceTest.java
Original file line number Diff line number Diff line change
@@ -6,10 +6,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import java.util.HashMap;
import java.util.List;
@@ -18,69 +16,79 @@
import static org.assertj.core.api.Assertions.assertThat;

@DisplayName("지하철역 관련 기능")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class StationAcceptanceTest {
@LocalServerPort
int port;

@BeforeEach
public void setUp() {
RestAssured.port = port;
}

/**
* When 지하철역을 생성하면
* Then 지하철역이 생성된다
* Then 지하철역 목록 조회 시 생성한 역을 찾을 수 있다
*/
@DisplayName("지하철역을 생성한다.")
@Test
void createStation() {
// when
Map<String, String> params = new HashMap<>();
params.put("name", "강남역");

ExtractableResponse<Response> response =
RestAssured.given().log().all()
.body(params)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.when().post("/stations")
.then().log().all()
.extract();

// then
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value());

// then
List<String> stationNames =
RestAssured.given().log().all()
.when().get("/stations")
.then().log().all()
.extract().jsonPath().getList("name", String.class);
assertThat(stationNames).containsAnyOf("강남역");
}

/**
* Given 2개의 지하철역을 생성하고
* When 지하철역 목록을 조회하면
* Then 2개의 지하철역을 응답 받는다
*/
// TODO: 지하철역 목록 조회 인수 테스트 메서드 생성
@DisplayName("지하철역을 조회한다.")
@Test
void getStations() {

}

/**
* Given 지하철역을 생성하고
* When 그 지하철역을 삭제하면
* Then 그 지하철역 목록 조회 시 생성한 역을 찾을 수 없다
*/
// TODO: 지하철역 제거 인수 테스트 메서드 생성
@DisplayName("지하철역을 제거한다.")
@Test
void deleteStation() {

}
public class StationAcceptanceTest extends AcceptanceTest {
@LocalServerPort
int port;

@BeforeEach
public void setUp() {
RestAssured.port = port;
}

/**
* When 지하철역을 생성하면
* Then 지하철역이 생성된다
* Then 지하철역 목록 조회 시 생성한 역을 찾을 수 있다
*/
@DisplayName("지하철역을 생성한다.")
@Test
void createStation() {
// when
ExtractableResponse<Response> response = createStation("강남역");
String location = response.header("Location");

// then
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value());
assertThat(location).matches("^/stations/[0-9]+");

}

/**
* Given 2개의 지하철역을 생성하고
* When 지하철역 목록을 조회하면
* Then 2개의 지하철역을 응답 받는다
*/
@DisplayName("지하철역을 조회한다.")
@Test
void getStations() {
//given
createStation("방배역");
createStation("삼성역");

//when
ExtractableResponse<Response> response = get("/stations");
List<String> stationNames = response.jsonPath().getList("name", String.class);

//then
assertThat(stationNames).containsAnyOf("방배역", "삼성역");
}

/**
* Given 지하철역을 생성하고
* When 그 지하철역을 삭제하면
* Then 그 지하철역 목록 조회 시 생성한 역을 찾을 수 없다
*/
@DisplayName("지하철역을 제거한다.")
@Test
void deleteStation() {
//given
Integer id = createStation("녹번역").jsonPath().get("id");

//when
ExtractableResponse<Response> response = delete("/stations/" + id);

//then
assertThat(response.statusCode()).isEqualTo(HttpStatus.NO_CONTENT.value());

//then
List<String> stations = get("/stations").response().jsonPath().getList("name", String.class);
assertThat(stations).doesNotContain("녹번역");
}

ExtractableResponse<Response> createStation(String name) {
Map<String, String> params = new HashMap<>();
params.put("name", name);

return post("/stations", params);
}
}