-
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.
* ✏️ Rename NangmanLetterTests * ✨ NangmanLetterRepository 테스트 * ✨ ModelMapper 설정
- Loading branch information
Showing
6 changed files
with
112 additions
and
40 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
21 changes: 21 additions & 0 deletions
21
src/main/java/aromanticcat/umcproject/config/AppConfig.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,21 @@ | ||
package aromanticcat.umcproject.config; | ||
|
||
import org.modelmapper.ModelMapper; | ||
import org.modelmapper.convention.MatchingStrategies; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class AppConfig { | ||
|
||
@Bean | ||
public ModelMapper getMapper(){ | ||
ModelMapper modelMapper = new ModelMapper(); | ||
modelMapper.getConfiguration() | ||
.setFieldMatchingEnabled(true) | ||
.setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE) | ||
.setMatchingStrategy(MatchingStrategies.STRICT); | ||
|
||
return modelMapper; | ||
} | ||
} |
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
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
84 changes: 84 additions & 0 deletions
84
src/test/java/aromanticcat/umcproject/repository/NangmanLetterRepositoryTests.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,84 @@ | ||
package aromanticcat.umcproject.repository; | ||
|
||
import aromanticcat.umcproject.entity.Member; | ||
import aromanticcat.umcproject.entity.NangmanLetter; | ||
import org.hibernate.Hibernate; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import javax.transaction.Transactional; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
|
||
@SpringBootTest | ||
@Transactional | ||
public class NangmanLetterRepositoryTests { | ||
|
||
@Autowired | ||
private NangmanLetterRepository nangmanLetterRepository; | ||
|
||
@Autowired | ||
private MemberRepository memberRepository; | ||
|
||
|
||
@Test | ||
public void testInsertNangmanLetter(){ | ||
|
||
Member member1 = Member.builder() | ||
.email("[email protected]") | ||
.nickname("member1") | ||
.coin(0) | ||
.build(); | ||
memberRepository.save(member1); | ||
|
||
NangmanLetter nangmanLetter = NangmanLetter.builder() | ||
.is_public(false) | ||
.sender_nickname("낭만적인 고양이") | ||
.content("제 고민을 들어주세요") | ||
.member(member1) | ||
.build(); | ||
NangmanLetter result = nangmanLetterRepository.save(nangmanLetter); | ||
|
||
System.out.println(result); | ||
} | ||
|
||
@Test | ||
public void testSelectById(){ | ||
Long id = 3L; | ||
|
||
Optional<NangmanLetter> result = nangmanLetterRepository.findById(id); | ||
NangmanLetter nangmanLetter = result.orElseThrow(); | ||
|
||
// 프록시 초기화 | ||
Hibernate.initialize(nangmanLetter.getMember().getNangmanLetters()); | ||
|
||
// 영속성 컨텍스트에서 엔티티를 가져오는 것을 확인 | ||
assertNotNull(nangmanLetter.getId()); | ||
|
||
// 출력 | ||
System.out.println(nangmanLetter); | ||
} | ||
|
||
@Test | ||
public void testUpdateHasResponse(){ | ||
Long id = 1L; | ||
|
||
Optional<NangmanLetter> result = nangmanLetterRepository.findById(id); | ||
|
||
NangmanLetter nangmanLetter = result.orElseThrow(); | ||
|
||
nangmanLetter.change(true); | ||
|
||
nangmanLetterRepository.save(nangmanLetter); | ||
} | ||
|
||
@Test | ||
public void testDeleteNangmanLetter(){ | ||
Long id = 1L; | ||
|
||
nangmanLetterRepository.deleteById(id); | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
src/test/java/aromanticcat/umcproject/repository/NangmanLetterTests.java
This file was deleted.
Oops, something went wrong.