20
20
21
21
class RoCrateMetadataGenerationTest {
22
22
23
+ private final String currentVersionId = new ProvenanceManager ().getLibraryId ();
24
+ private final String oldVersionId = new ProvenanceManager (() -> "1.0.0" ).getLibraryId ();
25
+ private final String newVersionId = new ProvenanceManager (() -> "2.5.3" ).getLibraryId ();
26
+
23
27
private final ObjectMapper objectMapper = new ObjectMapper ();
24
28
private Validator validator ;
25
29
@@ -55,7 +59,7 @@ void should_ContainRoCrateJavaEntities_When_WritingEmptyCrate(@TempDir Path temp
55
59
JsonNode graph = rootNode .get ("@graph" );
56
60
57
61
// Find ro-crate-java entity
58
- JsonNode roCrateJavaEntity = findEntityById (graph , "#ro-crate-java" );
62
+ JsonNode roCrateJavaEntity = findEntityById (graph , this . currentVersionId );
59
63
assertNotNull (roCrateJavaEntity , "ro-crate-java entity should exist" );
60
64
assertEquals ("SoftwareApplication" , roCrateJavaEntity .get ("@type" ).asText (),
61
65
"ro-crate-java should be of type SoftwareApplication" );
@@ -64,7 +68,7 @@ void should_ContainRoCrateJavaEntities_When_WritingEmptyCrate(@TempDir Path temp
64
68
JsonNode createActionEntity = findEntityByType (graph , "CreateAction" );
65
69
assertNotNull (createActionEntity , "CreateAction entity should exist" );
66
70
assertNotNull (createActionEntity .get ("startTime" ), "CreateAction should have startTime" );
67
- assertEquals ("#ro-crate-java" , createActionEntity .get ("agent" ).get ("@id" ).asText (),
71
+ assertEquals (this . currentVersionId , createActionEntity .get ("agent" ).get ("@id" ).asText (),
68
72
"CreateAction should reference ro-crate-java as agent" );
69
73
}
70
74
@@ -86,7 +90,7 @@ void should_HaveRequiredPropertiesInRoCrateJavaEntity_When_WritingCrate(@TempDir
86
90
87
91
// Parse metadata file
88
92
JsonNode rootNode = objectMapper .readTree (metadata );
89
- JsonNode roCrateJavaEntity = findEntityById (rootNode .get ("@graph" ), "#ro-crate-java" );
93
+ JsonNode roCrateJavaEntity = findEntityById (rootNode .get ("@graph" ), this . currentVersionId );
90
94
91
95
assertNotNull (roCrateJavaEntity , "ro-crate-java entity should exist" );
92
96
assertEquals ("ro-crate-java" , roCrateJavaEntity .get ("name" ).asText (),
@@ -119,7 +123,7 @@ void should_HaveBidirectionalRelation_Between_RoCrateJavaAndItsAction(@TempDir P
119
123
JsonNode graph = rootNode .get ("@graph" );
120
124
121
125
// Get both entities
122
- JsonNode roCrateJavaEntity = findEntityById (graph , "#ro-crate-java" );
126
+ JsonNode roCrateJavaEntity = findEntityById (graph , this . currentVersionId );
123
127
JsonNode createActionEntity = findEntityByType (graph , "CreateAction" );
124
128
125
129
assertNotNull (roCrateJavaEntity , "ro-crate-java entity should exist" );
@@ -128,7 +132,7 @@ void should_HaveBidirectionalRelation_Between_RoCrateJavaAndItsAction(@TempDir P
128
132
// Test CreateAction -> ro-crate-java reference
129
133
JsonNode agentRef = createActionEntity .get ("agent" );
130
134
assertNotNull (agentRef , "CreateAction should have agent property" );
131
- assertEquals ("#ro-crate-java" , agentRef .get ("@id" ).asText (),
135
+ assertEquals (this . currentVersionId , agentRef .get ("@id" ).asText (),
132
136
"CreateAction's agent should reference ro-crate-java" );
133
137
134
138
// Test ro-crate-java -> CreateAction reference
@@ -162,7 +166,7 @@ void should_AccumulateActions_When_WritingMultipleTimes(@TempDir Path tempDir) t
162
166
JsonNode graph = rootNode .get ("@graph" );
163
167
164
168
// Get ro-crate-java entity
165
- JsonNode roCrateJavaEntity = findEntityById (graph , "#ro-crate-java" );
169
+ JsonNode roCrateJavaEntity = findEntityById (graph , this . currentVersionId );
166
170
assertNotNull (roCrateJavaEntity , "ro-crate-java entity should exist" );
167
171
168
172
// Verify actions array exists and has three entries
@@ -183,14 +187,14 @@ void should_AccumulateActions_When_WritingMultipleTimes(@TempDir Path tempDir) t
183
187
184
188
// Verify CreateAction properties
185
189
assertNotNull (createAction .get ("startTime" ), "CreateAction should have startTime" );
186
- assertEquals ("#ro-crate-java" , createAction .get ("agent" ).get ("@id" ).asText (),
190
+ assertEquals (this . currentVersionId , createAction .get ("agent" ).get ("@id" ).asText (),
187
191
"CreateAction should reference ro-crate-java as agent" );
188
192
189
193
// Verify UpdateAction properties
190
194
for (JsonNode updateAction : updateActions ) {
191
195
assertNotNull (updateAction .get ("startTime" ),
192
196
"UpdateAction should have startTime" );
193
- assertEquals ("#ro-crate-java" , updateAction .get ("agent" ).get ("@id" ).asText (),
197
+ assertEquals (this . currentVersionId , updateAction .get ("agent" ).get ("@id" ).asText (),
194
198
"UpdateAction should reference ro-crate-java as agent" );
195
199
}
196
200
@@ -222,7 +226,7 @@ void should_HaveValidVersionFormat_When_WritingCrate(@TempDir Path tempDir) thro
222
226
223
227
// Parse metadata file
224
228
JsonNode rootNode = objectMapper .readTree (metadata );
225
- JsonNode roCrateJavaEntity = findEntityById (rootNode .get ("@graph" ), "#ro-crate-java" );
229
+ JsonNode roCrateJavaEntity = findEntityById (rootNode .get ("@graph" ), this . currentVersionId );
226
230
227
231
// Version format validation
228
232
@ SuppressWarnings ("DataFlowIssue" )
@@ -256,7 +260,7 @@ void should_HaveCompleteMetadata_When_WritingCrate(@TempDir Path tempDir) throws
256
260
257
261
// Parse metadata file
258
262
JsonNode rootNode = objectMapper .readTree (metadata );
259
- JsonNode roCrateJavaEntity = findEntityById (rootNode .get ("@graph" ), "#ro-crate-java" );
263
+ JsonNode roCrateJavaEntity = findEntityById (rootNode .get ("@graph" ), this . currentVersionId );
260
264
261
265
// Required properties with specific values
262
266
assertEquals ("ro-crate-java" , roCrateJavaEntity .get ("name" ).asText (),
@@ -301,7 +305,7 @@ void should_AddProvenanceInfo_When_ModifyingExistingCrateWithoutProvenance(@Temp
301
305
302
306
JsonNode originalRoot = objectMapper .readTree (originalMetadata );
303
307
JsonNode originalGraph = originalRoot .get ("@graph" );
304
- assertNull (findEntityById (originalGraph , "#ro-crate-java" ),
308
+ assertNull (findEntityById (originalGraph , this . currentVersionId ),
305
309
"Original crate should not have ro-crate-java entity" );
306
310
assertNull (findEntityByType (originalGraph , "CreateAction" ),
307
311
"Original crate should not have CreateAction" );
@@ -326,7 +330,7 @@ void should_AddProvenanceInfo_When_ModifyingExistingCrateWithoutProvenance(@Temp
326
330
JsonNode modifiedGraph = modifiedRoot .get ("@graph" );
327
331
328
332
// Verify ro-crate-java entity was added
329
- JsonNode roCrateJavaEntity = findEntityById (modifiedGraph , "#ro-crate-java" );
333
+ JsonNode roCrateJavaEntity = findEntityById (modifiedGraph , this . currentVersionId );
330
334
assertNotNull (roCrateJavaEntity , "ro-crate-java entity should be added" );
331
335
332
336
// Should only have UpdateAction, no CreateAction
@@ -339,7 +343,7 @@ void should_AddProvenanceInfo_When_ModifyingExistingCrateWithoutProvenance(@Temp
339
343
// Verify update action properties
340
344
assertNotNull (updateAction .get ("startTime" ),
341
345
"UpdateAction should have startTime" );
342
- assertEquals ("#ro-crate-java" ,
346
+ assertEquals (this . currentVersionId ,
343
347
updateAction .get ("agent" ).get ("@id" ).asText (),
344
348
"UpdateAction should reference ro-crate-java as agent" );
345
349
@@ -390,7 +394,7 @@ void should_PreserveExistingProvenance_When_ModifyingCrate(@TempDir Path tempDir
390
394
"Update should be after creation" );
391
395
392
396
// Verify ro-crate-java entity references both actions
393
- JsonNode roCrateJavaEntity = findEntityById (graph , "#ro-crate-java" );
397
+ JsonNode roCrateJavaEntity = findEntityById (graph , this . currentVersionId );
394
398
//noinspection DataFlowIssue
395
399
assertTrue (roCrateJavaEntity .get ("Action" ).isArray (),
396
400
"ro-crate-java should have an array of actions" );
0 commit comments