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

Step04 cucumber #418

Open
wants to merge 24 commits into
base: hiblue02
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
987b5ca
test(FarePoliciesTest): ParameterizedTest 적용
hiblue02 Feb 27, 2023
6ac30f4
refactor(Path): apply > applyFarePolicies
hiblue02 Feb 27, 2023
83ea5de
refactor(FarePolicies): 정책을 확정짓는 부분을 FarePolicies 내부로 이동
hiblue02 Feb 27, 2023
57838b9
doc(ReadMe): 요구사항 정의
hiblue02 Feb 27, 2023
c7f0460
refactor(PathServiceType): 사용하지 않는 클래스 삭제
hiblue02 Feb 27, 2023
50548ce
refactor(PathAcceptanceTest): 로그인 추가
hiblue02 Feb 27, 2023
d1d286e
refactor(PathController): 로그인 추가
hiblue02 Feb 27, 2023
0fc1048
refactor(Line): 추가요금 생성자 추가
hiblue02 Feb 28, 2023
5fd68ab
refactor(PathService): 비회원 조회 기능 추가, Optional 적용
hiblue02 Feb 28, 2023
7e37e37
feat(CalculateConditions): 요금 정책 적용 조건 클래스 생성
hiblue02 Feb 28, 2023
ac66ce7
feat(FareDiscountPolicy): 연령별 요금 할인 정책 추가
hiblue02 Feb 28, 2023
021855a
feat(LineSurchargeFarePolicy): 노선별 추가요금 정책 추가
hiblue02 Feb 28, 2023
208365e
test(FarePoliciesTest): 연령별 할인 요금, 노선 추가 요금 계산 테스트 추가
hiblue02 Feb 28, 2023
e383dbd
test(MemberController, FavoriteController): loginMember Optional 추가
hiblue02 Feb 28, 2023
68d991f
doc(ReadMe): 요구사항 구현 체크
hiblue02 Feb 28, 2023
6a2a9dd
refactor(AuthenticationPrincipal): required 속성 추가
hiblue02 Mar 1, 2023
1821e84
refactor(Path): path에서 맴버를 직접 찹조하지 않도록 수정.
hiblue02 Mar 1, 2023
f1c5c31
refactor(FarePolicy): FareDiscountPolicies를 추가
hiblue02 Mar 1, 2023
01d2d7c
test(FarePoliciesTest): given,when,then 추가
hiblue02 Mar 1, 2023
1e9192f
feat(FareCalculatorService): FareCalculatorService 추가
hiblue02 Mar 1, 2023
e6b82be
8th init
boorownie Jan 4, 2024
90092fe
feat(cucumber) : cucumber 지하철 경로 찾기 시나리오 추가
hiblue02 Jan 14, 2024
4be2f6d
Merge branch 'step04_cucumber' into step04_cucumber_test
hiblue02 Jan 16, 2024
ad3a62c
feat(cucumber) : PathDocumentation.java 삭제
hiblue02 Jan 16, 2024
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ out/

### VS Code ###
.vscode/
frontend/node_modules
frontend/node_modules

### OS ###
.DS_Store
._.DS_Store
**/.DS_Store
**/._.DS_Store
52 changes: 11 additions & 41 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
plugins {
id 'org.springframework.boot' version '2.7.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id "org.asciidoctor.jvm.convert" version "3.3.2"
id 'java'
}

configurations {
asciidoctorExt
}

group = 'nextstep'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
Expand All @@ -17,6 +12,7 @@ repositories {
mavenCentral()
}


dependencies {
// spring
implementation 'org.springframework.boot:spring-boot-starter-web'
Expand All @@ -31,49 +27,23 @@ dependencies {
// jwt
implementation 'io.jsonwebtoken:jjwt:0.9.1'

// rest docs
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor:2.0.5.RELEASE'
testImplementation 'org.springframework.restdocs:spring-restdocs-restassured:2.0.5.RELEASE'

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:4.5.1'

runtimeOnly 'com.h2database:h2'
}
// cucumber
testImplementation("io.cucumber:cucumber-java:7.14.0")
testImplementation("io.cucumber:cucumber-java8:7.14.0")
testImplementation("io.cucumber:cucumber-spring:7.14.0")
testImplementation("io.cucumber:cucumber-junit-platform-engine:7.14.0")
testImplementation("org.junit.platform:junit-platform-suite:1.10.0")
testImplementation("org.junit.platform:junit-platform-suite-api:1.10.0")
testImplementation("org.junit.platform:junit-platform-commons:1.10.0")
testImplementation("org.junit.platform:junit-platform-engine:1.10.0")

ext {
snippetsDir = file('build/generated-snippets')
runtimeOnly 'com.h2database:h2'
}

test {
useJUnitPlatform()
outputs.dir snippetsDir
}

task testDocument(type: Test) {
useJUnitPlatform()
filter {
includeTestsMatching "*.documentation.*"
}
}

asciidoctor {
inputs.dir snippetsDir
configurations 'asciidoctorExt'
dependsOn test
}

bootJar {
dependsOn asciidoctor
from("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}

task copyDocument(type: Copy) {
dependsOn asciidoctor

from file("build/docs/asciidoc")
into file("src/main/resources/static/docs")
}
2 changes: 1 addition & 1 deletion src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ security.jwt.token.expire-length= 3600000
github.client.id= test_id
github.client.secret= test_secret
github.url.access-token= http://localhost:8080/github/login/oauth/access_token
github.url.profile= http://localhost:8080/github/user
github.url.profile= http://localhost:8080/github/user
23 changes: 23 additions & 0 deletions src/test/java/nextstep/cucumber/CucumberTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package nextstep.cucumber;

import io.cucumber.spring.CucumberContextConfiguration;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;

@ActiveProfiles("test")
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "nextstep")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@CucumberContextConfiguration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class CucumberTest {
}
26 changes: 26 additions & 0 deletions src/test/java/nextstep/cucumber/steps/AcceptanceContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package nextstep.cucumber.steps;

import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class AcceptanceContext {
public Map<String, Long> store = new HashMap<>();
public ExtractableResponse<Response> response;

public void add(ExtractableResponse<Response> response) {
store.put(response.jsonPath().getString("name"),
response.jsonPath().getLong("id"));
}

public Long get(String name) {
return store.get(name);
}
}


74 changes: 74 additions & 0 deletions src/test/java/nextstep/cucumber/steps/PathStepDef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package nextstep.cucumber.steps;

import io.cucumber.datatable.DataTable;
import io.cucumber.java8.En;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import nextstep.subway.acceptance.PathSteps;
import nextstep.subway.domain.PathRequestType;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static nextstep.subway.acceptance.LineSteps.지하철_노선_생성_요청;
import static nextstep.subway.acceptance.LineSteps.지하철_노선에_지하철_구간_생성_요청;
import static nextstep.subway.acceptance.StationSteps.지하철역_생성_요청;
import static org.assertj.core.api.Assertions.assertThat;


public class PathStepDef implements En {


@Autowired
Copy link
Contributor

Choose a reason for hiding this comment

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

@Autowired 에 컴파일 에러가 뜨다니.. 확인해봐야겠네요
제 로컬에서는 안 뜨는데 플러그인 이슈일 수 있을 것 같기도..;;

큐컴버 사용 시 의존성 관리를 스프링으로 하는 방법으로 샘플을 작성했는데
pico-container라는 도구를 사용하는 방식도 있어요.
큐컴버가 스프링에 의존적이지 않게 하려면 이런 도구를 써야할 수 도 있겠네요.

private AcceptanceContext context;
ExtractableResponse<Response> response;

public PathStepDef() {

Given("지하철역들을 생성하고", (DataTable table) -> {
List<String> names = table.asList();
names.forEach(name -> context.add(지하철역_생성_요청(name)));
});

Given("지하철 노선들을 생성하고", (DataTable table) -> {
List<Map<String, String>> lines = table.asMaps();
lines.forEach(this::createLine);
});

Given("{string}에 지하철 역을 추가하고", (String lineName, DataTable table) -> {
Long lineId = context.get(lineName);
table.asMaps().forEach(add -> addStationInLine(add, lineId));
});
When("{string}과 {string} 사이 경로를 조회하면", (String upStation, String downStation)
-> response = PathSteps.두_역의_거리_경로_조회를_요청(
context.get(upStation), context.get(downStation), PathRequestType.DISTANCE
));
Comment on lines +44 to +47
Copy link
Contributor

Choose a reason for hiding this comment

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

기존 스텝 메서드를 재활용 잘 해주셨네요 👍
실제로 제가 저희 팀에서 큐컴버로 마이그레이션 할 때 했던 방식이에요!

Then("{string}-{string}-{string} 경로가 조회된다", (String upStation, String middleStation, String downStation)
-> assertThat(response.jsonPath().getList("stations.name", String.class))
.containsExactly(upStation, middleStation, downStation));
}

private void addStationInLine(Map<String, String> add, Long lineId) {
Map<String, String> params = new HashMap<>();
params.put("upStationId", context.get(add.get("upStation")) + "");
params.put("downStationId", context.get(add.get("downStation")) + "");
params.put("distance", add.get("distance"));
params.put("duration", add.get("duration"));
지하철_노선에_지하철_구간_생성_요청(lineId, params);
}

private void createLine(Map<String, String> line) {
Map<String, String> params = new HashMap<>();
params.put("name", line.get("name"));
params.put("color", line.get("color"));
params.put("upStationId", context.get(line.get("upStation")) + "");
params.put("downStationId", context.get(line.get("downStation")) + "");
params.put("distance", line.get("distance"));
params.put("duration", line.get("duration"));
params.put("surcharge", line.get("surcharge"));
var response = 지하철_노선_생성_요청(params);
context.add(response);
}
}
48 changes: 48 additions & 0 deletions src/test/java/nextstep/cucumber/steps/StationStepDef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package nextstep.cucumber.steps;

import io.cucumber.java8.En;
import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

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


public class StationStepDef implements En {
ExtractableResponse<Response> response;

public StationStepDef() {
When("지하철역을 생성하면", () -> {
Map<String, String> params = new HashMap<>();
params.put("name", "강남역");
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("강남역");
});

}

}
57 changes: 0 additions & 57 deletions src/test/java/nextstep/study/JgraphtTest.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/test/java/nextstep/subway/documentation/Documentation.java

This file was deleted.

Loading