/
GraphTemplateInheritanceTest.java
167 lines (125 loc) · 5.47 KB
/
GraphTemplateInheritanceTest.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.eclipse.jnosql.mapping.graph;
import jakarta.inject.Inject;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.assertj.core.api.Assertions;
import org.eclipse.jnosql.communication.Condition;
import org.eclipse.jnosql.mapping.core.Converters;
import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension;
import org.eclipse.jnosql.mapping.graph.entities.inheritance.EmailNotification;
import org.eclipse.jnosql.mapping.graph.entities.inheritance.Notification;
import org.eclipse.jnosql.mapping.graph.entities.inheritance.SmsNotification;
import org.eclipse.jnosql.mapping.graph.spi.GraphExtension;
import org.eclipse.jnosql.mapping.reflection.Reflections;
import org.jboss.weld.junit5.auto.AddExtensions;
import org.jboss.weld.junit5.auto.AddPackages;
import org.jboss.weld.junit5.auto.EnableAutoWeld;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import java.util.List;
import java.util.stream.Stream;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
@EnableAutoWeld
@AddPackages(value = {Converters.class, Transactional.class})
@AddPackages(BookRepository.class)
@AddPackages(Reflections.class)
@AddExtensions({EntityMetadataExtension.class, GraphExtension.class})
class GraphTemplateInheritanceTest {
@Inject
private GraphTemplate graphTemplate;
@Inject
private Graph graph;
protected Graph getGraph() {
return graph;
}
@AfterEach
void after() {
getGraph().traversal().V().toList().forEach(Vertex::remove);
getGraph().traversal().E().toList().forEach(Edge::remove);
}
@Test
void shouldSelectFindAllFilter(){
var emailNotification = new EmailNotification();
emailNotification.setName("email");
var smsNotification = new SmsNotification();
smsNotification.setName("notification");
this.graphTemplate.insert(List.of(emailNotification, smsNotification));
var notifications = graphTemplate.findAll(EmailNotification.class).toList();
assertSoftly(soft -> soft.assertThat(notifications)
.hasSize(1)
.containsExactly(emailNotification));
}
@Test
void shouldSelectFindAllNoFilter(){
var emailNotification = new EmailNotification();
emailNotification.setName("email");
var smsNotification = new SmsNotification();
smsNotification.setName("notification");
this.graphTemplate.insert(List.of(emailNotification, smsNotification));
var notifications = graphTemplate.findAll(Notification.class).toList();
assertSoftly(soft -> soft.assertThat(notifications)
.hasSize(2)
.containsExactly(emailNotification, smsNotification));
}
@Test
void shouldDeleteAllFilter(){
var emailNotification = new EmailNotification();
emailNotification.setName("email");
var smsNotification = new SmsNotification();
smsNotification.setName("notification");
this.graphTemplate.insert(List.of(emailNotification, smsNotification));
graphTemplate.deleteAll(EmailNotification.class);
var notifications = graphTemplate.findAll(Notification.class).toList();
assertSoftly(soft -> soft.assertThat(notifications)
.hasSize(1)
.containsExactly(smsNotification));
}
@Test
void shouldDeleteAllNoFilter(){
var emailNotification = new EmailNotification();
emailNotification.setName("email");
var smsNotification = new SmsNotification();
smsNotification.setName("notification");
this.graphTemplate.insert(List.of(emailNotification, smsNotification));
graphTemplate.deleteAll(Notification.class);
var notifications = graphTemplate.findAll(Notification.class).toList();
assertSoftly(soft -> soft.assertThat(notifications).isEmpty());
}
@Test
void shouldCountAllFilter(){
var emailNotification = new EmailNotification();
emailNotification.setName("email");
var smsNotification = new SmsNotification();
smsNotification.setName("notification");
this.graphTemplate.insert(List.of(emailNotification, smsNotification));
var count = graphTemplate.count(EmailNotification.class);
Assertions.assertThat(count).isEqualTo(1);
}
@Test
void shouldCountAlNolFilter(){
var emailNotification = new EmailNotification();
emailNotification.setName("email");
var smsNotification = new SmsNotification();
smsNotification.setName("notification");
this.graphTemplate.insert(List.of(emailNotification, smsNotification));
var count = graphTemplate.count(Notification.class);
Assertions.assertThat(count).isEqualTo(2);
}
}