-
Notifications
You must be signed in to change notification settings - Fork 0
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
[OMCT-347] 아이템 추가 통합 테스트 #175
Changes from 8 commits
31cc1d0
e9463cf
29dd259
6e6c37b
e9b1fdd
f600b8a
1df200e
f2ddfa0
b9b3cfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.programmers.bucketback; | ||
|
||
import org.junit.jupiter.api.Disabled; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
@Disabled | ||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
@Sql(scripts = {"classpath:truncate.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 이게 통합테스트를 위한 세팅인가요??! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저 부분은 다같이 다양한 방법을 찾아보고 회의해서 결정하는 것은 어떤가요!? |
||
public class IntegrationTest { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.programmers.bucketback.domains.item.application; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import com.programmers.bucketback.IntegrationTest; | ||
import com.programmers.bucketback.common.model.ItemIdRegistry; | ||
import com.programmers.bucketback.common.model.ItemIdRegistryBuilder; | ||
import com.programmers.bucketback.domains.item.application.dto.ItemAddServiceResponse; | ||
import com.programmers.bucketback.domains.item.domain.setup.ItemSetup; | ||
import com.programmers.bucketback.domains.item.implementation.MemberItemValidator; | ||
import com.programmers.bucketback.global.util.MemberUtils; | ||
|
||
class ItemServiceTest extends IntegrationTest { | ||
|
||
@Autowired | ||
private ItemSetup itemSetup; | ||
|
||
@Autowired | ||
private ItemService itemService; | ||
|
||
@MockBean | ||
private MemberUtils memberUtils; | ||
|
||
@MockBean | ||
private MemberItemValidator memberItemValidator; | ||
|
||
@Test | ||
@DisplayName("나의 아이템을 추가한다.") | ||
public void addItemTest() { | ||
// given | ||
given(memberUtils.getCurrentMemberId()).willReturn(1L); | ||
|
||
// memberSetup이 만들어지면 변경할 예정 | ||
doNothing().when(memberItemValidator).validateExistMemberItem(any(), any()); | ||
|
||
ItemIdRegistry itemIdRegistry = ItemIdRegistryBuilder.build(); | ||
ItemAddServiceResponse expectedResponse = new ItemAddServiceResponse(itemIdRegistry.itemIds()); | ||
|
||
itemIdRegistry.itemIds() | ||
.forEach(itemId -> itemSetup.saveOne(itemId)); | ||
|
||
// when | ||
ItemAddServiceResponse actualResponse = itemService.addItem(itemIdRegistry); | ||
|
||
// then | ||
assertThat(actualResponse) | ||
.usingRecursiveComparison() | ||
.isEqualTo(expectedResponse); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
set | ||
FOREIGN_KEY_CHECKS = 0; | ||
TRUNCATE TABLE bucket_items; | ||
TRUNCATE TABLE feed_items; | ||
TRUNCATE TABLE feed_likes; | ||
TRUNCATE TABLE inventory_items; | ||
TRUNCATE TABLE members_items; | ||
TRUNCATE TABLE voters; | ||
TRUNCATE TABLE buckets; | ||
TRUNCATE TABLE comments; | ||
TRUNCATE TABLE feeds; | ||
TRUNCATE TABLE inventories; | ||
TRUNCATE TABLE reviews; | ||
TRUNCATE TABLE votes; | ||
TRUNCATE TABLE items; | ||
TRUNCATE TABLE members; | ||
set | ||
FOREIGN_KEY_CHECKS = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.programmers.bucketback.domains.item.domain.setup; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.programmers.bucketback.domains.item.domain.Item; | ||
import com.programmers.bucketback.domains.item.domain.ItemBuilder; | ||
import com.programmers.bucketback.domains.item.repository.ItemRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ItemSetup { | ||
|
||
private final ItemRepository itemRepository; | ||
|
||
public Item saveOne(final Long itemId) { | ||
Item item = ItemBuilder.build(itemId); | ||
|
||
return itemRepository.save(item); | ||
} | ||
} |
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.
p5;
activeProfile을 사용하지 않고 test 하위 resource 폴더에 테스트만을 위한 yml을 두는 건 어떤가용 ?? 이거는 다같이 회의해보면 좋을 것 같아요!!
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.
active profile을 사용할 경우 로그 설정, 관련 빈 설정 등 환경 관리를 할 수 있어서 적용하였습니다.