-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support draft features on existing crates
- Loading branch information
Showing
5 changed files
with
176 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 58 additions & 4 deletions
62
src/test/java/edu/kit/datamanager/ro_crate/crate/BuilderSpec12Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,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.BuilderV1p2Draft() | ||
.alsoConformsTo(new URI("https://w3id.org/ro/wfrun/process/0.1")) | ||
.alsoConformsTo(new URI("https://example.com/myprofile/1.0")) | ||
.build(); | ||
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() | ||
); | ||
} | ||
} |