Exception

Eureka Server 관련 ,@SpringBootTest 구동 실패

Jungsoomin :) 2020. 12. 11. 16:27

Eureka Client 의존 추가 시 @SpringBootTest 구동, -> 유레카 서버 안켜져있음! 이라는 메세지가 뜬다.

 

properties 에 eureka.client.enabled=false 걸어서 꺼놓자.

@SpringBootTest(properties = "eureka.client.enabled=false",webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class PostRepositoryTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(PostRepositoryTest.class);

    @Autowired
    private PostRepository postRepository;

    @Autowired
    private CommentRepository commentRepository;

    @Test
    @Rollback(false)
    public void test(){
        Post post = Post.builder().setTitle("Post Title").setContent("Post Content").build();
        Post savedPost = postRepository.save(post);

        Optional<Post> selectedPost_opt = postRepository.findById(savedPost.getId());


        assertThat(selectedPost_opt).isNotEmpty();
        assertThat(selectedPost_opt.get().getTitle()).isEqualTo("Post Title");
        assertThat(selectedPost_opt.get().getContent()).isEqualTo("Post Content");
    }

    @Test
    public void commentTest(){
        Comment comment = Comment.builder().setTitle("Comment Title").setContent("Comment Content").build();
        Comment savedComment = commentRepository.save(comment);

        Optional<Comment> selectedComment_opt = commentRepository.findById(savedComment.getId());

        assertThat(selectedComment_opt).isNotEmpty();
        assertThat(selectedComment_opt.get().getTitle()).isEqualTo("Comment Title");
        assertThat(selectedComment_opt.get().getContent()).isEqualTo("Comment Content");
    }
}