Skip to content

Commit

Permalink
Revert "feat: JPA로 리팩토링 (#273)" (#287)
Browse files Browse the repository at this point in the history
This reverts commit f28c979.
  • Loading branch information
gracefulBrown authored Aug 23, 2021
1 parent d4f10b8 commit b170317
Show file tree
Hide file tree
Showing 130 changed files with 1,485 additions and 2,759 deletions.
1 change: 0 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
// spring
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@Component
@Scope(scopeName = "cucumber-glue")
public class AcceptanceContext {

public RequestSpecification request;
public Response response;
public String accessToken;
Expand All @@ -35,41 +34,40 @@ public void invokeHttpGet(String path, Object... pathParams) {

public void invokeHttpPost(String path, Object data) {
request = RestAssured
.given().log().all()
.body(data).contentType(ContentType.JSON);
.given().log().all()
.body(data).contentType(ContentType.JSON);
response = request.post(path);
response.then().log().all();
}

public void invokeHttpGetWithToken(String path, Object... pathParams) {
request = RestAssured.given().log().all()
.auth().oauth2(accessToken);
.auth().oauth2(accessToken);;
response = request.when().get(path, pathParams);
response.then().log().all();
}

public void invokeHttpPutWithToken(String path, Object data) {
request = RestAssured
.given().log().all()
.body(data).contentType(ContentType.JSON)
.auth().oauth2(accessToken);
.given().log().all()
.body(data).contentType(ContentType.JSON)
.auth().oauth2(accessToken);
response = request.put(path);
response.then().log().all();
}

public void invokeHttpPostWithToken(String path, Object data) {
request = RestAssured
.given().log().all()
.body(data).contentType(ContentType.JSON)
.auth().oauth2(accessToken);
.given().log().all()
.body(data).contentType(ContentType.JSON)
.auth().oauth2(accessToken);
response = request.post(path);
response.then().log().all();
}

public void invokeHttpDeleteWithToken(String path) {
request = RestAssured
.given().log().all()
.auth().oauth2(accessToken);
.given().log().all()
.auth().oauth2(accessToken);
response = request.delete(path);
response.then().log().all();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@CucumberContextConfiguration
public class AcceptanceHooks {

@LocalServerPort
private int port;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

@Profile("acceptance")
public class AcceptanceSteps {

@Autowired
public AcceptanceContext context;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

@Cucumber
public class AcceptanceTestRunnerIT {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public enum GithubResponses {
웨지("2", "access_token_2", "웨지", "sihyung92", "222222", "https://avatars.githubusercontent.com/u/51393021?v=4"),
서니("3", "access_token_3", "서니", "sunhpark42", "333333", "https://avatars.githubusercontent.com/u/67677561?v=4"),
엘라("4", "access_token_4", "엘라", "HyuuunjuKim", "444444", "https://avatars.githubusercontent.com/u/43339385?v=4"),
브라운("5", "access_token_5", "브라운", "gracefulBrown", "555555", "https://avatars.githubusercontent.com/u/46308949?v=4"),
현구막("6", "access_token_6", "현구막", "Hyeon9mak", "666666", "https://avatars.githubusercontent.com/u/37354145?v=4");
브라운("5", "access_token_5", "브라운", "gracefulBrown", "555555", "https://avatars.githubusercontent.com/u/46308949?v=4");

private String code;
private String accessToken;
Expand Down Expand Up @@ -54,22 +53,22 @@ public String getAvatarUrl() {

public static GithubResponses findByName(String member) {
return Arrays.stream(values())
.filter(it -> StringUtils.equals(it.name, member))
.findFirst()
.orElseThrow(RuntimeException::new);
.filter(it -> StringUtils.equals(it.name, member))
.findFirst()
.orElseThrow(RuntimeException::new);
}

public static GithubResponses findByCode(String code) {
return Arrays.stream(values())
.filter(it -> StringUtils.equals(it.code, code))
.findFirst()
.orElseThrow(RuntimeException::new);
.filter(it -> StringUtils.equals(it.code, code))
.findFirst()
.orElseThrow(RuntimeException::new);
}

public static GithubResponses findByToken(String accessToken) {
return Arrays.stream(values())
.filter(it -> StringUtils.equals(it.accessToken, accessToken))
.findFirst()
.orElseThrow(RuntimeException::new);
.filter(it -> StringUtils.equals(it.accessToken, accessToken))
.findFirst()
.orElseThrow(RuntimeException::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@
@Profile("acceptance")
@RestController
public class GithubTestController {

@PostMapping("/github/login/oauth/access_token")
public ResponseEntity<GithubAccessTokenResponse> accessToken(
@RequestBody GithubAccessTokenRequest tokenRequest) {
public ResponseEntity<GithubAccessTokenResponse> accessToken(@RequestBody GithubAccessTokenRequest tokenRequest) {
String accessToken = GithubResponses.findByCode(tokenRequest.getCode()).getAccessToken();
GithubAccessTokenResponse response = new GithubAccessTokenResponse(accessToken, "", "", "");
return ResponseEntity.ok(response);
}

@GetMapping("/github/user")
public ResponseEntity<GithubProfileResponse> user(
@RequestHeader("Authorization") String authorization) {
public ResponseEntity<GithubProfileResponse> user(@RequestHeader("Authorization") String authorization) {
String accessToken = authorization.split(" ")[1];
GithubResponses githubResponse = GithubResponses.findByToken(accessToken);
GithubProfileResponse response = new GithubProfileResponse(githubResponse.getName(),
githubResponse.getLogin(), githubResponse.getId(), githubResponse.getAvatarUrl());
GithubProfileResponse response = new GithubProfileResponse(githubResponse.getName(), githubResponse.getLogin(), githubResponse.getId(), githubResponse.getAvatarUrl());
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import wooteco.prolog.mission.application.dto.MissionRequest;

public class MissionAcceptanceFixture {

public static MissionRequest mission1 = new MissionRequest("backend 지하철 3차 미션");
public static MissionRequest mission2 = new MissionRequest("FRONTEND 지하철 3차 미션");
}
Original file line number Diff line number Diff line change
@@ -1,87 +1,29 @@
package wooteco.prolog.fixtures;

import static java.util.stream.Collectors.toList;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG1;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG2;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG3;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG4;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG5;
import static wooteco.prolog.fixtures.TagAcceptanceFixture.TAG6;

import java.util.List;
import java.util.stream.Collectors;
import wooteco.prolog.post.application.dto.PostRequest;
import wooteco.prolog.tag.dto.TagRequest;

import java.util.Arrays;

public enum PostAcceptanceFixture {
POST1(
"[자바][옵셔널] 학습log 제출합니다.",
"옵셔널은 NPE를 배제하기 위해 만들어진 자바8에 추가된 라이브러리입니다. \n " +
"다양한 메소드를 호출하여 원하는 대로 활용할 수 있습니다",
1L,
TAG1,
TAG2
),
POST2(
"[자바스크립트][비동기] 학습log 제출합니다.",
"모던 JS의 fetch문, ajax라이브러리인 axios등을 통해 비동기 요청을 \n " +
"편하게 할 수 있습니다. 자바 최고",
2L,
TAG3,
TAG4
),
POST3(
"[자료구조] 자료구조는 어려워요",
"진짜 어려움",
1L,
TAG1,
TAG5
),
POST4(
"[DOM] DOM DOM Dance",
"덤덤 댄스 아니고",
2L
),
POST5(
"[알고리즘] 자료구조의 big O에 관하여",
"big O는 small O보다 크다",
2L,
TAG5,
TAG6
public class PostAcceptanceFixture {
public static PostRequest firstPost = new PostRequest(
"[자바][옵셔널] 학습log 제출합니다.",
"옵셔널은 NPE를 배제하기 위해 만들어진 자바8에 추가된 라이브러리입니다. \n " +
"다양한 메소드를 호출하여 원하는 대로 활용할 수 있습니다",
1L,
Arrays.asList(
new TagRequest("자바"),
new TagRequest("Optional")
)
);

PostAcceptanceFixture(
String title,
String content,
Long missionId,
TagAcceptanceFixture... tags) {
this.tags = Arrays.asList(tags);
List<TagRequest> tagRequests = Arrays.stream(tags)
.map(TagAcceptanceFixture::getTagRequest)
.collect(toList());
this.postRequest = new PostRequest(title, content, missionId, tagRequests);
}

private final PostRequest postRequest;
private final List<TagAcceptanceFixture> tags;

public PostRequest getPostRequest() {
return postRequest;
}

public static List<PostRequest> findByMissionNumber(Long missionId) {
return Arrays.stream(PostAcceptanceFixture.values())
.map(PostAcceptanceFixture::getPostRequest)
.filter(it -> it.getMissionId().equals(missionId))
.collect(toList());
}

public static List<PostRequest> findByTagNumber(Long tagId) {
return Arrays.stream(PostAcceptanceFixture.values())
.filter(it -> it.tags.stream().anyMatch(tag -> tag.getTagId().equals(tagId)))
.map(PostAcceptanceFixture::getPostRequest)
.collect(toList());
}
public static PostRequest secondPost = new PostRequest("[자바스크립트][비동기] 학습log 제출합니다.",
"모던 JS의 fetch문, ajax라이브러리인 axios등을 통해 비동기 요청을 \n " +
"편하게 할 수 있습니다. 자바 최고",
2L,
Arrays.asList(
new TagRequest("자바스크립트"),
new TagRequest("비동기")
)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@

import java.util.Arrays;

public enum TagAcceptanceFixture {
TAG1(1L, "자바"),
TAG2(2L, "Optional"),
TAG3(3L, "자바스크립트"),
TAG4(4L, "비동기"),
TAG5(5L, "자료구조"),
TAG6(6L, "알고리즘");
public class TagAcceptanceFixture {
public static PostRequest firstPost = new PostRequest(
"[자바][옵셔널] 학습log 제출합니다.",
"옵셔널은 NPE를 배제하기 위해 만들어진 자바8에 추가된 라이브러리입니다. \n " +
"다양한 메소드를 호출하여 원하는 대로 활용할 수 있습니다",
1L,
Arrays.asList(
new TagRequest("자바"),
new TagRequest("비동기")
)
);

TagAcceptanceFixture(Long id, String name) {
this.tagId = id;
this.tagRequest = new TagRequest(name);
}

private Long tagId;
private TagRequest tagRequest;

public TagRequest getTagRequest() {
return tagRequest;
}

public Long getTagId() {
return tagId;
}
public static PostRequest secondPost = new PostRequest("[자바스크립트][비동기] 학습log 제출합니다.",
"모던 JS의 fetch문, ajax라이브러리인 axios등을 통해 비동기 요청을 \n " +
"편하게 할 수 있습니다. 자바 최고",
2L,
Arrays.asList(
new TagRequest("자바스크립트"),
new TagRequest("비동기")
)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import static org.assertj.core.api.Assertions.assertThat;

public class LoginStepDefinitions extends AcceptanceSteps {

@Given("{string}(이)(가) 로그인을 하고")
public void 멤버로그인을하고(String member) {
HashMap<String, Object> data = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import static org.assertj.core.api.Assertions.assertThat;

public class MemberStepDefinitions extends AcceptanceSteps {

@When("{string}의 멤버 정보를 조회하면")
public void 멤버정보를조회하면(String member) {
String username = GithubResponses.findByName(member).getLogin();
Expand All @@ -29,21 +28,22 @@ public class MemberStepDefinitions extends AcceptanceSteps {
assertThat(member.getImageUrl()).isNotNull();
}

@When("자신의 닉네임을 {string}(로)(으로) 수정하면")
public void 자신의닉네임을수정하면(String updatedNickname) {
@When("{string}(이)(이가) 자신의 닉네임을 {string}(로)(으로) 수정하면")
public void 자신의닉네임을수정하면(String member, String updatedNickname) {
String originUsername = GithubResponses.findByName(member).getLogin();

MemberUpdateRequest updateRequest = new MemberUpdateRequest(
updatedNickname, ""
updatedNickname, ""
);

context.invokeHttpPutWithToken("/members/me", updateRequest);
context.invokeHttpPutWithToken("/members/" + originUsername, updateRequest);
}

@Then("{string}의 닉네임이 {string}(로)(으로) 수정")
public void 닉네임이으로수정(String member, String nickname) {
String username = GithubResponses.findByName(member).getLogin();
@Then("유저네임이 {string}(로)(으로) 수정")
public void 유저네임이으로수정(String username) {
context.invokeHttpGetWithToken("/members/" + username);
String updatedNickname = context.response.as(MemberResponse.class).getNickname();
MemberResponse member = context.response.as(MemberResponse.class);

assertThat(updatedNickname).isEqualTo(nickname);
assertThat(member.getUsername()).isEqualTo(username);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static org.assertj.core.api.Assertions.assertThat;

public class MissionStepDefinitions extends AcceptanceSteps {

@Given("미션 여러개를 생성하고")
public void 미션여러개를생성하고() {
context.invokeHttpPost("/missions", MissionAcceptanceFixture.mission1);
Expand Down Expand Up @@ -47,8 +46,7 @@ public class MissionStepDefinitions extends AcceptanceSteps {
public void 미션목록을받는다() {
assertThat(context.response.statusCode()).isEqualTo(HttpStatus.OK.value());
List<MissionResponse> missions = context.response.jsonPath()
.getList(".", MissionResponse.class);
List<MissionResponse> missions = context.response.jsonPath().getList(".", MissionResponse.class);
assertThat(missions).isNotEmpty();
}
}
Loading

0 comments on commit b170317

Please sign in to comment.