1
1
package no.nav.klage.document.repositories
2
2
3
+ import no.nav.klage.document.domain.Comment
3
4
import no.nav.klage.document.domain.Document
4
5
import org.assertj.core.api.Assertions.assertThat
5
6
import org.junit.jupiter.api.Test
@@ -16,7 +17,7 @@ import java.time.LocalDateTime
16
17
@DataJpaTest
17
18
@Testcontainers
18
19
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase .Replace .NONE )
19
- class DocumentRepositoryTest {
20
+ class RepositoryTest {
20
21
21
22
companion object {
22
23
@Container
@@ -30,8 +31,11 @@ class DocumentRepositoryTest {
30
31
@Autowired
31
32
lateinit var documentRepository: DocumentRepository
32
33
34
+ @Autowired
35
+ lateinit var commentRepository: CommentRepository
36
+
33
37
@Test
34
- fun `add documents works ` () {
38
+ fun `add document and comments work ` () {
35
39
36
40
val now = LocalDateTime .now()
37
41
@@ -48,6 +52,30 @@ class DocumentRepositoryTest {
48
52
49
53
val foundDocument = documentRepository.findById(document.id).get()
50
54
assertThat(foundDocument).isEqualTo(document)
55
+
56
+ val comment1 = Comment (
57
+ documentId = document.id,
58
+ text = " my comment 1" ,
59
+ created = now.plusDays(1 ),
60
+ modified = now.plusDays(1 )
61
+ )
62
+
63
+ val comment2 = Comment (
64
+ documentId = document.id,
65
+ text = " my comment 2" ,
66
+ created = now.plusDays(2 ),
67
+ modified = now.plusDays(2 )
68
+ )
69
+
70
+ commentRepository.save(comment1)
71
+ commentRepository.save(comment2)
72
+
73
+ testEntityManager.flush()
74
+ testEntityManager.clear()
75
+
76
+ val comments = commentRepository.findByDocumentId(document.id)
77
+
78
+ assertThat(comments).hasSize(2 )
51
79
}
52
80
53
81
}
0 commit comments