카테고리 없음
sssAndUpload
내이름효주
2024. 5. 22. 14:56
- t1 - 메인화면 출력
@Test
@DisplayName("메인화면에서는 안녕이 나와야 함")
void t1() throws Exception {
// WHEN
// GET /
ResultActions resultActions = mvc
.perform(get("/"))
.andDo(print());
// THEN
// 안녕
resultActions
.andExpect(status().is2xxSuccessful())
.andExpect(handler().handlerType(HomeController.class))
.andExpect(handler().methodName("main"))
.andExpect(content().string(containsString("안녕")));
}
- t2 - 회원 수
long count = memberService.count();
assertThat(count).isGreaterThan(0);
// ibatis
isNull : "널일경우"
isNotNull : "널이아닐경우"
isEmpty : "공백일경우"
isNotEmpty : "공백이아닐경우"
isGreaterTan : ">"
isGreaterEqual : ">="
isLessThan : "<"
isLessEqual : "<="
isEqual : "=="
isNotEqual : "!="
- t3 - 프로필 이메일
// mockMvc로 로그인 처리
// WHEN
// GET /
ResultActions resultActions = mvc
.perform(
get("/member/profile")
.with(user("user1").password("1234").roles("user"))
)
.andDo(print());

- 저장 폴더를 날짜로 세분화
private String getCurrentProfileImgDirName() {
return "member/" + Util.date.getCurrentDateFormatted("yyyy_MM_dd");
}
public Member join(String username, String password, String email, MultipartFile profileImg) {
String profileImgDirName = getCurrentProfileImgDirName();
String ext = Util.file.getExt(profileImg.getOriginalFilename());
String fileName = UUID.randomUUID() + "." + ext;
String profileImgDirPath = genFileDirPath + "/" + profileImgDirName;
String profileImgFilePath = profileImgDirPath + "/" + fileName;
new File(profileImgDirPath).mkdirs(); // 폴더가 혹시나 없다면 만들어준다.
try {
profileImg.transferTo(new File(profileImgFilePath));
} catch (IOException e) {
throw new RuntimeException(e);
}
String profileImgRelPath = profileImgDirName + "/" + fileName;
Member member = Member.builder()
.username(username)
.password(password)
.email(email)
.profileImg(profileImgRelPath)
.build();
memberRepository.save(member);
return member;
}
