-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from theMomentTeam/feature/improve-hotfix
Feature/improve hotfix
- Loading branch information
Showing
2 changed files
with
91 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/com/moment/the/improvement/service/ImprovementServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.moment.the.improvement.service; | ||
|
||
import com.moment.the.admin.AdminDomain; | ||
import com.moment.the.admin.dto.AdminDto; | ||
import com.moment.the.admin.repository.AdminRepository; | ||
import com.moment.the.admin.service.AdminService; | ||
import com.moment.the.improvement.dto.ImprovementDto; | ||
import com.moment.the.improvement.repository.ImprovementRepository; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.awt.*; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
class ImprovementServiceTest { | ||
@Autowired | ||
private ImprovementRepository improvementRepository; | ||
@Autowired | ||
private ImprovementService improvementService; | ||
@Autowired | ||
private AdminService adminService; | ||
@Autowired | ||
private AdminRepository adminRepository; | ||
@AfterEach | ||
void deleteData(){ | ||
improvementRepository.deleteAll(); | ||
} | ||
|
||
// test 편의를 위한 회원가입 매서드 | ||
void adminSignUp(String adminId, String password, String adminName) throws Exception { | ||
AdminDto adminDto = new AdminDto(adminId, password, adminName); | ||
adminService.signUp(adminDto); | ||
} | ||
|
||
// test 편의를 위한 로그인 매서드 | ||
AdminDomain adminLogin(String adminId, String password) throws Exception { | ||
AdminDomain adminDomain = adminRepository.findByAdminId(adminId); | ||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( | ||
adminDomain.getAdminId(), | ||
adminDomain.getAdminPwd(), | ||
List.of(new SimpleGrantedAuthority("ROLE_USER"))); | ||
SecurityContext context = SecurityContextHolder.getContext(); | ||
context.setAuthentication(token); | ||
|
||
return adminDomain; | ||
} | ||
|
||
@Test | ||
void 실제개선사례작성() throws Exception { | ||
//Given admin | ||
String email = "asdf@gsm"; | ||
String pw = "1234"; | ||
String name = "jihwan"; | ||
adminSignUp(email, pw, name); | ||
adminLogin(email, pw); | ||
|
||
//Given improvement | ||
ImprovementDto improvementDto = new ImprovementDto(); | ||
improvementDto.setImproveContent("Hello world"); | ||
improvementDto.setImproveContent("it's jihwan"); | ||
|
||
//when | ||
improvementService.save(improvementDto); | ||
|
||
//then | ||
assertEquals(false, improvementRepository.findByImproveContent("it's jihwan") == null); | ||
assertEquals(true, improvementRepository.findByImproveContent("it's jihwan").getAdminDomain().getAdminId().equals("asdf@gsm")); | ||
} | ||
|
||
} |