Skip to content

Commit 016face

Browse files
authored
Merge pull request #171 from UruruLab/test/170-seller
Seller 관련 테스트코드 작성을 위한 공통 테스트 데이터 및 유틸리티
2 parents 5c13ceb + ca71943 commit 016face

File tree

1 file changed

+354
-0
lines changed

1 file changed

+354
-0
lines changed
Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
package com.ururulab.ururu.seller.service;
2+
3+
import com.ururulab.ururu.global.domain.entity.BaseEntity;
4+
import com.ururulab.ururu.seller.domain.entity.Seller;
5+
import com.ururulab.ururu.seller.dto.request.SellerSignupRequest;
6+
7+
import java.lang.reflect.Field;
8+
import java.time.Instant;
9+
10+
/**
11+
* 판매자 테스트를 위한 공통 테스트 데이터 및 유틸리티 클래스.
12+
*
13+
* 테스트 데이터 중앙화를 통해 객체 생성 방식 변경 시 한 곳에서만 수정 가능하며,
14+
* 테스트 코드의 가독성과 일관성을 향상시킵니다.
15+
*/
16+
public class SellerTestFixture {
17+
18+
// === 정상 판매자 데이터 ===
19+
20+
/**
21+
* 기본 판매자 엔티티 생성
22+
*/
23+
public static Seller createSeller(Long id, String email, String name) {
24+
Seller seller = Seller.of(
25+
name,
26+
"우르르 뷰티(주)",
27+
"김태현",
28+
"1234567890",
29+
email,
30+
"encodedPassword123",
31+
"01012345678",
32+
"https://example.com/image.jpg",
33+
"서울시 강남구 테헤란로 123",
34+
"456호",
35+
"2024-서울강남-1234"
36+
);
37+
setSellerId(seller, id);
38+
return seller;
39+
}
40+
41+
/**
42+
* 기본 판매자 엔티티 생성 (ID 없음)
43+
*/
44+
public static Seller createSeller(String email, String name) {
45+
return Seller.of(
46+
name,
47+
"우르르 뷰티(주)",
48+
"김태현",
49+
"1234567890",
50+
email,
51+
"encodedPassword123",
52+
"01012345678",
53+
"https://example.com/image.jpg",
54+
"서울시 강남구 테헤란로 123",
55+
"456호",
56+
"2024-서울강남-1234"
57+
);
58+
}
59+
60+
/**
61+
* 유효한 회원가입 요청 생성
62+
*/
63+
public static SellerSignupRequest createValidSignupRequest() {
64+
return new SellerSignupRequest(
65+
"우르르 뷰티",
66+
"우르르 뷰티(주)",
67+
"김태현",
68+
"1234567890",
69+
"seller@ururu.shop",
70+
"Password123!",
71+
"01012345678",
72+
"https://example.com/image.jpg",
73+
"서울시 강남구 테헤란로 123",
74+
"456호",
75+
"2024-서울강남-1234"
76+
);
77+
}
78+
79+
/**
80+
* 이미지 없는 회원가입 요청 생성
81+
*/
82+
public static SellerSignupRequest createValidSignupRequestWithoutImage() {
83+
return new SellerSignupRequest(
84+
"우르르 뷰티",
85+
"우르르 뷰티(주)",
86+
"김태현",
87+
"1234567890",
88+
"seller@ururu.shop",
89+
"Password123!",
90+
"01012345678",
91+
null,
92+
"서울시 강남구 테헤란로 123",
93+
"456호",
94+
"2024-서울강남-1234"
95+
);
96+
}
97+
98+
// === 예외 케이스 데이터 ===
99+
100+
/**
101+
* 중복 이메일이 포함된 회원가입 요청 생성
102+
*/
103+
public static SellerSignupRequest createDuplicateEmailRequest() {
104+
return new SellerSignupRequest(
105+
"다른 브랜드",
106+
"다른 회사(주)",
107+
"이상민",
108+
"0987654321",
109+
"existing@ururu.shop", // 중복 이메일
110+
"Password123!",
111+
"01098765432",
112+
null,
113+
"부산시 해운대구 센텀로 456",
114+
"789호",
115+
"2024-부산해운대-5678"
116+
);
117+
}
118+
119+
/**
120+
* 중복 사업자등록번호가 포함된 회원가입 요청 생성
121+
*/
122+
public static SellerSignupRequest createDuplicateBusinessNumberRequest() {
123+
return new SellerSignupRequest(
124+
"다른 브랜드",
125+
"다른 회사(주)",
126+
"이상민",
127+
"1234567890", // 중복 사업자등록번호
128+
"different@ururu.shop",
129+
"Password123!",
130+
"01098765432",
131+
null,
132+
"부산시 해운대구 센텀로 456",
133+
"789호",
134+
"2024-부산해운대-5678"
135+
);
136+
}
137+
138+
/**
139+
* 중복 브랜드명이 포함된 회원가입 요청 생성
140+
*/
141+
public static SellerSignupRequest createDuplicateNameRequest() {
142+
return new SellerSignupRequest(
143+
"우르르 뷰티", // 중복 브랜드명
144+
"다른 회사(주)",
145+
"이상민",
146+
"0987654321",
147+
"different@ururu.shop",
148+
"Password123!",
149+
"01098765432",
150+
null,
151+
"부산시 해운대구 센텀로 456",
152+
"789호",
153+
"2024-부산해운대-5678"
154+
);
155+
}
156+
157+
// === 삭제된 판매자 데이터 ===
158+
159+
/**
160+
* 삭제된 판매자 엔티티 생성
161+
*/
162+
public static Seller createDeletedSeller(Long id, String email, String name) {
163+
Seller seller = createSeller(id, email, name);
164+
seller.delete();
165+
return seller;
166+
}
167+
168+
/**
169+
* 삭제된 판매자 엔티티 생성 (ID 없음)
170+
*/
171+
public static Seller createDeletedSeller(String email, String name) {
172+
Seller seller = createSeller(email, name);
173+
seller.delete();
174+
return seller;
175+
}
176+
177+
// === 경계 조건 데이터 ===
178+
179+
/**
180+
* 이메일 대소문자 변이가 포함된 회원가입 요청 생성
181+
*/
182+
public static SellerSignupRequest createRequestWithEmailCaseVariation() {
183+
return new SellerSignupRequest(
184+
"테스트 브랜드",
185+
"테스트 회사(주)",
186+
"테스트",
187+
"1111111111",
188+
"TEST@URURU.SHOP", // 대문자 이메일
189+
"Password123!",
190+
"01011111111",
191+
null,
192+
"서울시 강남구 테스트로 111",
193+
"111호",
194+
"2024-서울강남-1111"
195+
);
196+
}
197+
198+
/**
199+
* 공백이 포함된 회원가입 요청 생성
200+
*/
201+
public static SellerSignupRequest createRequestWithWhitespace() {
202+
return new SellerSignupRequest(
203+
" 우르르 뷰티 ", // 앞뒤 공백
204+
" 우르르 뷰티(주) ",
205+
" 김태현 ",
206+
" 1234567890 ",
207+
" seller@ururu.shop ",
208+
"Password123!",
209+
" 01012345678 ",
210+
null,
211+
" 서울시 강남구 테헤란로 123 ",
212+
" 456호 ",
213+
" 2024-서울강남-1234 "
214+
);
215+
}
216+
217+
/**
218+
* 최대 길이 경계값을 포함한 회원가입 요청 생성
219+
*/
220+
public static SellerSignupRequest createRequestWithMaxLength() {
221+
return new SellerSignupRequest(
222+
"A".repeat(50), // 최대 길이
223+
"B".repeat(100), // 최대 길이
224+
"C".repeat(50), // 최대 길이
225+
"1234567890",
226+
"maxlength@ururu.shop",
227+
"Password123!",
228+
"01012345678",
229+
null,
230+
"D".repeat(100), // 최대 길이
231+
"E".repeat(100), // 최대 길이
232+
"F".repeat(50) // 최대 길이
233+
);
234+
}
235+
236+
/**
237+
* 최소 길이 경계값을 포함한 회원가입 요청 생성
238+
*/
239+
public static SellerSignupRequest createRequestWithMinLength() {
240+
return new SellerSignupRequest(
241+
"A", // 최소 길이
242+
"B", // 최소 길이
243+
"C", // 최소 길이
244+
"1234567890",
245+
"min@ururu.shop",
246+
"Password123!",
247+
"01012345678",
248+
null,
249+
"D", // 최소 길이
250+
"E", // 최소 길이
251+
"F" // 최소 길이
252+
);
253+
}
254+
255+
// === 특수 케이스 데이터 ===
256+
257+
/**
258+
* 특수문자가 포함된 회원가입 요청 생성
259+
*/
260+
public static SellerSignupRequest createRequestWithSpecialCharacters() {
261+
return new SellerSignupRequest(
262+
"우르르 뷰티 & 코스메틱",
263+
"우르르 뷰티(주) - 서울지점",
264+
"김태현 (CEO)",
265+
"1234567890",
266+
"seller+test@ururu.shop",
267+
"Password123!",
268+
"01012345678",
269+
null,
270+
"서울시 강남구 테헤란로 123, 456동",
271+
"456호 (우르르빌딩)",
272+
"2024-서울강남-1234 (통신판매업)"
273+
);
274+
}
275+
276+
/**
277+
* 한글이 포함된 회원가입 요청 생성
278+
*/
279+
public static SellerSignupRequest createRequestWithKoreanCharacters() {
280+
return new SellerSignupRequest(
281+
"우르르 뷰티",
282+
"우르르 뷰티 주식회사",
283+
"김태현",
284+
"1234567890",
285+
"seller@우르르.shop",
286+
"Password123!",
287+
"01012345678",
288+
null,
289+
"서울특별시 강남구 테헤란로 123",
290+
"456호 (우르르빌딩)",
291+
"2024-서울강남-1234"
292+
);
293+
}
294+
295+
// === 유틸리티 메서드 ===
296+
297+
/**
298+
* 판매자 ID를 리플렉션을 통해 설정
299+
*/
300+
private static void setSellerId(Seller seller, Long id) {
301+
try {
302+
Field idField = Seller.class.getDeclaredField("id");
303+
idField.setAccessible(true);
304+
idField.set(seller, id);
305+
} catch (Exception e) {
306+
throw new RuntimeException("Failed to set seller id for test", e);
307+
}
308+
}
309+
310+
/**
311+
* 판매자 생성/수정 시간을 리플렉션을 통해 설정
312+
*/
313+
public static void setSellerTimestamps(Seller seller, Instant createdAt, Instant updatedAt) {
314+
try {
315+
// BaseEntity를 명시적으로 참조하여 안정성 향상
316+
Field createdAtField = BaseEntity.class.getDeclaredField("createdAt");
317+
createdAtField.setAccessible(true);
318+
createdAtField.set(seller, createdAt);
319+
320+
Field updatedAtField = BaseEntity.class.getDeclaredField("updatedAt");
321+
updatedAtField.setAccessible(true);
322+
updatedAtField.set(seller, updatedAt);
323+
} catch (Exception e) {
324+
throw new RuntimeException("Failed to set seller timestamps for test", e);
325+
}
326+
}
327+
328+
/**
329+
* 판매자 삭제 상태를 리플렉션을 통해 설정
330+
*/
331+
public static void setSellerDeleted(Seller seller, boolean isDeleted) {
332+
try {
333+
Field isDeletedField = Seller.class.getDeclaredField("isDeleted");
334+
isDeletedField.setAccessible(true);
335+
isDeletedField.set(seller, isDeleted);
336+
} catch (Exception e) {
337+
throw new RuntimeException("Failed to set seller deleted status for test", e);
338+
}
339+
}
340+
341+
/**
342+
* BaseEntity의 공통 필드를 설정하는 헬퍼 메서드
343+
* 향후 BaseEntity 구조 변경 시 이 메서드만 수정하면 됨
344+
*/
345+
public static void setBaseEntityField(Object entity, String fieldName, Object value) {
346+
try {
347+
Field field = BaseEntity.class.getDeclaredField(fieldName);
348+
field.setAccessible(true);
349+
field.set(entity, value);
350+
} catch (Exception e) {
351+
throw new RuntimeException("Failed to set BaseEntity field: " + fieldName, e);
352+
}
353+
}
354+
}

0 commit comments

Comments
 (0)