forked from lmlopezmagana/Spring-Boot-Blog-REST-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerifyDataJpaTest.java
More file actions
51 lines (36 loc) · 1.43 KB
/
VerifyDataJpaTest.java
File metadata and controls
51 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.sopromadze.blogapi;
import com.sopromadze.blogapi.model.Album;
import com.sopromadze.blogapi.repository.AlbumRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import java.time.Instant;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@DataJpaTest
@ActiveProfiles("test")
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class VerifyDataJpaTest {
@Autowired
private AlbumRepository repository;
@Autowired
private TestEntityManager testEntityManager;
@Test
void testRepoNotNull() {
assertNotNull(repository);
}
@Test
void test_findAll() {
Album album = new Album();
album.setTitle("Título");
album.setCreatedAt(Instant.now());
album.setUpdatedAt(Instant.now());
testEntityManager.persist(album);
assertNotEquals(0, repository.findAll().size());
}
}