14
14
15
15
import javax .inject .Inject ;
16
16
17
+ import org .apache .tinkerpop .gremlin .process .traversal .P ;
17
18
import org .apache .tinkerpop .gremlin .process .traversal .dsl .graph .GraphTraversal ;
18
19
import org .apache .tinkerpop .gremlin .process .traversal .dsl .graph .GraphTraversalSource ;
19
20
import org .apache .tinkerpop .gremlin .structure .Edge ;
24
25
import org .carlspring .strongbox .janusgraph .domain .ArtifactEntry ;
25
26
import org .janusgraph .core .JanusGraph ;
26
27
import org .junit .jupiter .api .Test ;
27
- import org .neo4j .ogm .session .Session ;
28
28
import org .neo4j .ogm .session .SessionFactory ;
29
29
import org .slf4j .Logger ;
30
30
import org .slf4j .LoggerFactory ;
@@ -39,12 +39,15 @@ public class ArtifactEntryRepositoryTest
39
39
@ Inject
40
40
private ArtifactEntryRepository artifactEntryRepository ;
41
41
42
+ @ Inject
43
+ private ArtifactCoordinatesRepository artifactCoordinatesRepository ;
44
+
42
45
@ Inject
43
46
private JanusGraph janusGraph ;
44
47
45
48
@ Inject
46
49
private SessionFactory sessionFactory ;
47
-
50
+
48
51
@ Test
49
52
public void crudShouldWork ()
50
53
{
@@ -66,6 +69,12 @@ public void crudShouldWork()
66
69
ArtifactEntry artifactEntrySaved = artifactEntryRepository .save (artifactEntry );
67
70
assertEquals (artifactEntrySaved .getUuid (), artifactEntry .getUuid ());
68
71
72
+ ArtifactDependency artifactDependency = new ArtifactDependency ();
73
+ artifactDependency .setUuid (UUID .randomUUID ().toString ());
74
+ artifactDependency .setSubject (artifactEntry );
75
+ artifactDependency .setDependency (artifactCoordinates );
76
+ sessionFactory .openSession ().save (artifactDependency );
77
+
69
78
artifactEntrySaved = artifactEntryRepository .findByPath ("org/carlspring/test-artifact-3.0.0.jar" );
70
79
assertNotNull (artifactEntrySaved );
71
80
assertEquals (artifactEntrySaved .getUuid (), artifactEntry .getUuid ());
@@ -81,26 +90,28 @@ public void crudShouldWork()
81
90
@ Test
82
91
public void manyToOneRelationShouldWork ()
83
92
{
84
- String artifactCoordinatesUuid = UUID .randomUUID ().toString ();
85
- ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates ();
86
- artifactCoordinates .setPath ("org/carlspring/test-artifact-4.0.0.jar" );
87
- artifactCoordinates .setUuid (artifactCoordinatesUuid );
88
- artifactCoordinates .setVersion ("4.0.0" );
89
-
90
93
String artifactEntryUuid = UUID .randomUUID ().toString ();
91
- ArtifactEntry artifactEntry = new ArtifactEntry ();
92
- artifactEntry .setUuid (artifactEntryUuid );
93
- artifactEntry .setStorageId ("storage0" );
94
- artifactEntry .setRepositoryId ("releases" );
95
- artifactEntry .setSizeInBytes (123L );
96
- artifactEntry .setTags (new HashSet <>(Arrays .asList ("release" , "stabile" )));
97
- artifactEntry .setArtifactCoordinates (artifactCoordinates );
98
- artifactEntry .setCreated (new Date ());
99
-
100
- ArtifactEntry artifactEntrySaved = artifactEntryRepository .save (artifactEntry );
101
- assertEquals (artifactEntrySaved .getUuid (), artifactEntry .getUuid ());
94
+ String artifactCoordinatesUuid = UUID .randomUUID ().toString ();
102
95
103
96
GraphTraversalSource g = janusGraph .traversal ();
97
+ g .addV (ArtifactCoordinates .LABEL )
98
+ .property ("uuid" , artifactCoordinatesUuid )
99
+ .property ("path" ,
100
+ "org/carlspring/test-artifact-4.0.0.jar" )
101
+ .property ("version" ,
102
+ "4.0.0" )
103
+ .as ("ac" )
104
+ .addV (ArtifactEntry .LABEL )
105
+ .property ("uuid" , artifactEntryUuid )
106
+ .property ("storageId" , "storage0" )
107
+ .property ("repositoryId" , "releases" )
108
+ .property ("sizeInBytes" , 123L )
109
+ .property ("tags" , new HashSet <>(Arrays .asList ("release" , "stabile" )))
110
+ .property ("created" , new Date ())
111
+ .as ("ae" )
112
+ .addE ("ArtifactEntry_ArtifactCoordinates" )
113
+ .to ("ac" )
114
+ .next ();
104
115
105
116
// Relation should exists
106
117
GraphTraversal <Vertex , Edge > edgeQuery = g .V ()
@@ -110,7 +121,7 @@ public void manyToOneRelationShouldWork()
110
121
assertTrue (edgeQuery .hasNext ());
111
122
Edge artifactEntry2ArtifactCoordinatesEdge = edgeQuery .next ();
112
123
logger .info (String .valueOf (artifactEntry2ArtifactCoordinatesEdge ));
113
- assertEquals (ArtifactEntry .class .getSimpleName () + "# " + ArtifactCoordinates .class .getSimpleName (),
124
+ assertEquals (ArtifactEntry .class .getSimpleName () + "_ " + ArtifactCoordinates .class .getSimpleName (),
114
125
artifactEntry2ArtifactCoordinatesEdge .label ());
115
126
116
127
// ArtifactCoordinates should exists
@@ -136,43 +147,58 @@ public void manyToOneRelationShouldWork()
136
147
Vertex artifactEntryAnotherVertex = vertexQuery .next ();
137
148
assertEquals (artifactCoordinatesUuid , artifactCoordinatesVertex .property ("uuid" ).value ());
138
149
assertEquals (ArtifactEntry .class .getSimpleName (), artifactEntryAnotherVertex .label ());
150
+
151
+ g .tx ().rollback ();
139
152
}
140
-
153
+
141
154
@ Test
142
- public void artifactDependencyTreeShouldWork () {
143
- String subjectUuid = UUID .randomUUID ().toString ();
144
-
145
- ArtifactEntry artifactEntrySubject = new ArtifactEntry ();
146
- artifactEntrySubject .setUuid (subjectUuid );
147
- artifactEntrySubject .setStorageId ("storage0" );
148
- artifactEntrySubject .setRepositoryId ("releases" );
149
- artifactEntrySubject .setSizeInBytes (123L );
150
- artifactEntrySubject .setTags (new HashSet <>(Arrays .asList ("release" , "stabile" )));
151
- //artifactEntry.setArtifactCoordinates(artifactCoordinates);
152
- artifactEntrySubject .setCreated (new Date ());
153
-
154
- String dependencyUuid = UUID .randomUUID ().toString ();
155
- ArtifactEntry artifactEntryDependency = new ArtifactEntry ();
156
- artifactEntryDependency .setUuid (dependencyUuid );
157
- artifactEntryDependency .setStorageId ("storage0" );
158
- artifactEntryDependency .setRepositoryId ("releases" );
159
- artifactEntryDependency .setSizeInBytes (123L );
160
- artifactEntryDependency .setTags (new HashSet <>(Arrays .asList ("release" , "stabile" )));
161
- //artifactEntry.setArtifactCoordinates(artifactCoordinates);
162
- artifactEntryDependency .setCreated (new Date ());
163
-
164
- ArtifactDependency artifactDependency = new ArtifactDependency ();
165
- artifactDependency .setUuid (UUID .randomUUID ().toString ());
166
- artifactDependency .setSubject (artifactEntrySubject );
167
- artifactDependency .setDependency (artifactEntryDependency );
168
-
169
- Session session = sessionFactory .openSession ();
170
- session .save (artifactEntrySubject );
171
- session .save (artifactEntryDependency );
172
- session .save (artifactDependency );
155
+ public void artifactDependencyTreeShouldWork ()
156
+ {
157
+ GraphTraversalSource g = janusGraph .traversal ();
173
158
174
- List <ArtifactEntry > dependencies = artifactEntryRepository .findAllDependentArtifactEntries (dependencyUuid );
175
- assertEquals (1 , dependencies .size ());
159
+ // ArtifactEntry->ArtifactDependency\
160
+ // ..................................->ArtifactCoordinates
161
+ // ArtifactEntry->ArtifactDependency/
162
+ // .............\
163
+ // ..............>ArtifactDependency->ArtifactCoordinates
164
+ g .addV (ArtifactCoordinates .LABEL )
165
+ .property ("uuid" , UUID .randomUUID ().toString ())
166
+ .property ("path" ,
167
+ "org/carlspring/test/dependency.jar" )
168
+ .property ("version" ,
169
+ "777" )
170
+ .as ("adc1" )
171
+ .addV (ArtifactEntry .LABEL )
172
+ .property ("uuid" , UUID .randomUUID ().toString ())
173
+ .property ("storageId" , "storage0" )
174
+ .property ("repositoryId" , "releases" )
175
+ .as ("ae1" )
176
+ .addE (ArtifactDependency .LABEL )
177
+ .to ("adc1" )
178
+ .addV (ArtifactEntry .LABEL )
179
+ .property ("uuid" , UUID .randomUUID ().toString ())
180
+ .property ("storageId" , "storage0" )
181
+ .property ("repositoryId" , "releases" )
182
+ .as ("ae2" )
183
+ .addE (ArtifactDependency .LABEL )
184
+ .to ("adc1" )
185
+ .addV (ArtifactCoordinates .LABEL )
186
+ .property ("uuid" , UUID .randomUUID ().toString ())
187
+ .property ("path" ,
188
+ "org/carlspring/test/another-dependency.jar" )
189
+ .property ("version" ,
190
+ "1.2.3" )
191
+ .as ("adc2" )
192
+ .addE (ArtifactDependency .LABEL )
193
+ .from ("ae2" )
194
+ .to ("adc2" )
195
+ .next ();
196
+
197
+ g .tx ().commit ();
198
+
199
+ ArtifactCoordinates adc1 = artifactCoordinatesRepository .findByPath ("org/carlspring/test/dependency.jar" );
200
+ List <ArtifactEntry > dependencies = artifactEntryRepository .findAllDependentArtifactEntries (adc1 .getUuid ());
201
+ assertEquals (2 , dependencies .size ());
176
202
}
177
203
178
204
}
0 commit comments