-
Notifications
You must be signed in to change notification settings - Fork 3
/
BuilderSpec12Test.java
82 lines (71 loc) · 3.45 KB
/
BuilderSpec12Test.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
package edu.kit.datamanager.ro_crate.crate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.JsonNode;
import edu.kit.datamanager.ro_crate.Crate;
import edu.kit.datamanager.ro_crate.RoCrate;
import edu.kit.datamanager.ro_crate.entities.contextual.ContextualEntity;
import edu.kit.datamanager.ro_crate.reader.FolderReader;
import edu.kit.datamanager.ro_crate.reader.RoCrateReader;
import edu.kit.datamanager.ro_crate.special.CrateVersion;
import edu.kit.datamanager.ro_crate.validation.JsonSchemaValidation;
import edu.kit.datamanager.ro_crate.validation.Validator;
class BuilderSpec12Test {
private URI profile1;
private URI profile2;
@Test
void testAppendConformsTo() throws URISyntaxException {
Crate crate = new RoCrate.BuilderWithDraftFeatures()
.alsoConformsTo(new URI("https://w3id.org/ro/wfrun/process/0.1"))
.alsoConformsTo(new URI("https://example.com/myprofile/1.0"))
.build();
JsonNode conformsTo = crate.getJsonDescriptor().getProperty("conformsTo");
assertTrue(conformsTo.isArray());
// one version and two profiles
assertEquals(1 + 2, conformsTo.size());
}
@Test
void testModificationOfDraftCrate() throws URISyntaxException {
String path = this.getClass().getResource("/crates/spec-1.2-DRAFT/minimal-with-conformsTo-Array").getPath();
RoCrate crate = new RoCrateReader(new FolderReader()).readCrate(path);
Collection<String> existingProfiles = crate.getProfiles();
profile1 = new URI("https://example.com/myprofile/1.0");
profile2 = new URI("https://example.com/myprofile/2.0");
// the loaded crate has at least one profile
assertFalse(existingProfiles.isEmpty());
// and the ones we will add later are not part of it
assertFalse(existingProfiles.contains(profile1.toString()));
assertFalse(existingProfiles.contains(profile2.toString()));
// add profiles
RoCrate modifiedCrate = new RoCrate.BuilderWithDraftFeatures(crate)
.alsoConformsTo(profile1)
.alsoConformsTo(profile2)
.addContextualEntity(new ContextualEntity.ContextualEntityBuilder()
.addType("CreativeWork")
.build())
.build();
// sanity checks
Validator defaultValidation = new Validator(new JsonSchemaValidation());
assertTrue(defaultValidation.validate(modifiedCrate));
assertEquals(CrateVersion.LATEST_UNSTABLE, crate.getVersion().get());
assertEquals(CrateVersion.LATEST_UNSTABLE, modifiedCrate.getVersion().get());
// number of profiles increased by 2
Collection<String> newProfileState = modifiedCrate.getProfiles();
assertEquals(existingProfiles.size() + 2, newProfileState.size());
// new profiles are present
newProfileState.contains(profile1.toString());
newProfileState.contains(profile2.toString());
// old profiles are present
assertEquals(
0,
existingProfiles.stream()
.filter(txt -> !newProfileState.contains(txt))
.count()
);
}
}