-
Notifications
You must be signed in to change notification settings - Fork 280
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
๐ 1๋จ๊ณ - ์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ ๊ธฐ๋ฅ ๊ฐ์ #606
base: jjisun
Are you sure you want to change the base?
Conversation
* step1: ์งํ์ฒ ๋ชฉ๋ก ์กฐํ, ์ ๊ฑฐ ์ธ์ ํ ์คํธ ์์ฑ * 2๋จ๊ณ ์งํ์ฒ ๋ ธ์ ๊ด๋ฆฌ
# Conflicts: # src/test/java/subway/acceptance/SectionAcceptanceTest.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋
ํ์ธ์! 1๋จ๊ณ ๋ฏธ์
์งํํด์ฃผ์ ๋ถ๋ถ ํ์ธํ์ต๋๋ค!
0๋จ๊ณ ์ค์ต์ ๋์น๊ณ ๊ณ์ ๊ฒ ๊ฐ์์ ์ ๋ถ๋ถ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค ๐
์ถ๊ฐ๋ก 2์ฃผ์ฐจ ์ค์ต์ ์ธ์ํ
์คํธ์ ๋จ์ํ
์คํธ๋ฅผ ํจ๊ป ํ๋ฉด์ ๊ฐ์์ค์ ๋ค๋ค๋ Outside In, Inside Out์ด ๊ฐ๊ฐ ์ด๋ค ์ฅ๋จ์ ์ด ์๋์ง, ์ด๋ค ๋ฐฉ์์ด ๋ ์ ํธํ๋ ๋ฐฉ์์ ๋ง๋์ง ์๊ฐํด๋ณด์๋ฉด์ ์งํํด๋ณด์๋ฉด ๋ ์ข๋ต๋๋ค ๐
1๋จ๊ณ ๋ฏธ์
์ ๋ํ ์ฝ๋ฉํธ๋ ๋จ๊ฒผ์ผ๋ ํด๋น ๋ถ๋ถ + 0๋จ๊ณ ์ค์ต ํ์ธ ํ ๋ค์ ์์ฒญ ๋ถํ๋๋ฆฝ๋๋ค!
์ถ๊ฐ๋ก ์ดํด๊ฐ ์๋๋ ๋ถ๋ถ์ด๋ ์๋
ผํด๋ณด๊ณ ์ถ์ ๋ถ๋ถ์ด ์์ผ๋ฉด ํธํ๊ฒ dm์ด๋ ์ฑ๋์ ๋ฉ์์ง ์ฃผ์ธ์!
@Transactional | ||
public void execute() { | ||
entityManager.flush(); | ||
entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY FALSE").executeUpdate(); | ||
|
||
for (String tableName : tableNames) { | ||
entityManager.createNativeQuery("TRUNCATE TABLE " + tableName).executeUpdate(); | ||
} | ||
|
||
entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY TRUE").executeUpdate(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ธ์ํ ์คํธ ๊ฒฉ๋ฆฌ ๐
import subway.fixture.StationFixture; | ||
|
||
@DisplayName("์งํ์ฒ ๊ตฌ๊ฐ ๊ด๋ จ ๊ธฐ๋ฅ") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RANDOM_PORT๋ฅผ ํ์ฉํด๋ณด๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์์~
@LocalServerPort | ||
int port; | ||
|
||
@Autowired | ||
DatabaseCleaner databaseCleaner; | ||
|
||
Long lineId; | ||
|
||
Map<String, Long> stationMaps = new HashMap<>(); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
RestAssured.port = port; | ||
databaseCleaner.execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ ๋ถ๋ถ๋ค์ด ์ธ์ํ ์คํธ ํด๋์ค๋ง๋ค ๋ชจ๋ ์ค๋ณต์ด ๋ฐ์ํ๊ณ ์๋๋ฐ ์ค๋ณต์ ์ค์ผ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์๊น์?
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@LocalServerPort
int port;
@Autowired
DatabaseCleaner databaseCleaner;
@BeforeEach์ RestAssured.port = port;
databaseCleaner.execute();
var lineResponse = response.as(LineResponse.class); | ||
assertThat(lineResponse.getStations().stream().map(StationResponse::getName)).containsAnyOf("์ ์์ญ"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ธ์ ํ
์คํธ๋ ๋ธ๋๋ฐ์ค ํ
์คํธ๋ก ๋ณด๊ณ ์งํํ๋, ์ง์ ์ ์ธ ๊ตฌํ์ ์์กด๋๋ as(LineResponse.class)
๋ณด๋ค๋ jsonPath
์์ฃผ๋ก ํ์ฉํด๋ณด์๊ธธ ๊ถํด๋๋ฆฝ๋๋ค!
๋ฌผ๋ก ๊ฐ์ธ ์ ํธ์ ๋ฐ๋ผ ์ง๊ธ์ฒ๋ผ ๋ฐ๋ก ํด๋์ค์ ๋งคํํด์ ํ์ฉํด์ฃผ์
๋ ์ข์ต๋๋ค :)
|
||
// then | ||
var lineResponse = response.as(LineResponse.class); | ||
assertThat(lineResponse.getStations().stream().map(StationResponse::getName)).containsAnyOf("๋ ผํ์ญ"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ต์ ๋ ผํ์ญ์ด ์๋์ง๋ง ํ์ธํ๊ธฐ๋ณด๋ค ์์๋ ์ฒดํฌํด์ฃผ์๋ฉด ๋ ์ข๊ฒ ์ต๋๋ค!
if(o.getUpStation().equals(section.getUpStation())) { | ||
replaceSections.add(section); | ||
var distance = o.getDistance() - section.getDistance(); | ||
replaceSections.add(Section.builder() | ||
.upStation(section.getDownStation()) | ||
.downStation(o.getDownStation()) | ||
.distance(distance) | ||
.build()); | ||
} else if(o.getDownStation().equals(section.getDownStation())) { | ||
var distance = o.getDistance() - section.getDistance(); | ||
replaceSections.add(Section.builder() | ||
.upStation(o.getUpStation()) | ||
.downStation(section.getUpStation()) | ||
.distance(distance) | ||
.build()); | ||
replaceSections.add(section); | ||
} else { | ||
replaceSections.add(o); | ||
} | ||
}); | ||
|
||
return replaceSections; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ถ๋ถ ๊ฐ๋
์ฑ์ ๊ฐ์ ํด๋ณผ ์ ์์๊น์?
๊ฐ์ฒด์งํฅ ์ํ์ฒด์กฐ 2๋ฒ else์์ฝ์ด๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค๋ ์ฐธ๊ณ ํ๋ฉด ๋์์ด ๋๊ฒ ๋ค์!
public Section lastSection() { | ||
return sections.get(sections.size() - 1); | ||
} | ||
|
||
public Section firstSection() { | ||
return sections.get(0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
public List<Station> stations() { | ||
return this.sections.stream().map(o -> Arrays.asList(o.getUpStation(), o.getDownStation())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public class ApiException extends RuntimeException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ปค์คํ ์์ธ ์ฒ๋ฆฌ ๐
|
||
@ExceptionHandler(ApiException.class) | ||
public ResponseEntity<ErrorResponse> handleSubwayException(ApiException apiException) { | ||
return new ResponseEntity<>(ErrorResponse.builder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ ๐
์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ ๊ธฐ๋ฅ ๊ฐ์ ๊ตฌํ
๋ฆฌ๋ทฐ ์๋ถํ๋๋ฆฝ๋๋ค :)