1 package de.dlr.shepard.context.semantic.daos;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.mockito.Mockito.verify;
5 import static org.mockito.Mockito.when;
6
7 import de.dlr.shepard.BaseTestCase;
8 import de.dlr.shepard.context.semantic.entities.SemanticAnnotation;
9 import java.util.Collections;
10 import java.util.List;
11 import org.junit.jupiter.api.Test;
12 import org.mockito.InjectMocks;
13 import org.mockito.Mock;
14 import org.neo4j.ogm.session.Session;
15
16 public class SemanticAnnotationDAOTest extends BaseTestCase {
17
18 @Mock
19 private Session session;
20
21 @InjectMocks
22 private SemanticAnnotationDAO dao;
23
24 @Test
25 public void getEntityTypeTest() {
26 var type = dao.getEntityType();
27 assertEquals(SemanticAnnotation.class, type);
28 }
29
30 @Test
31 public void findAllSemanticAnnotationsTest() {
32 var annotation = new SemanticAnnotation(1L);
33 annotation.setPropertyName("Test");
34
35 var query =
36 """
37 MATCH (e)-[ha:has_annotation]->(a:SemanticAnnotation) \
38 WHERE ID(e)=1 WITH a MATCH path=(a)-[*0..1]->(n) WHERE n.deleted = FALSE OR n.deleted IS NULL \
39 RETURN a, nodes(path), relationships(path)""";
40 when(session.query(SemanticAnnotation.class, query, Collections.emptyMap())).thenReturn(List.of(annotation));
41
42 var actual = dao.findAllSemanticAnnotationsByNeo4jId(1L);
43 verify(session).query(SemanticAnnotation.class, query, Collections.emptyMap());
44 assertEquals(List.of(annotation), actual);
45 }
46
47 @Test
48 public void findAllSemanticAnnotationsByShepardIdTest() {
49 var annotation = new SemanticAnnotation(1L);
50 annotation.setPropertyName("Test");
51
52 var query =
53 """
54 MATCH (e)-[ha:has_annotation]->(a:SemanticAnnotation) \
55 WHERE e.shepardId=11 WITH a MATCH path=(a)-[*0..1]->(n) WHERE n.deleted = FALSE OR n.deleted IS NULL \
56 RETURN a, nodes(path), relationships(path)""";
57 when(session.query(SemanticAnnotation.class, query, Collections.emptyMap())).thenReturn(List.of(annotation));
58
59 var actual = dao.findAllSemanticAnnotationsByShepardId(11L);
60 verify(session).query(SemanticAnnotation.class, query, Collections.emptyMap());
61 assertEquals(List.of(annotation), actual);
62 }
63 }