Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pfeil committed Jul 18, 2022
1 parent b76d99d commit 427bd2e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/main/java/edu/kit/datamanager/ro_crate/Crate.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface Crate {

ContextualEntity getContextualEntityById(java.lang.String id);

List<ContextualEntity> getAllContextualEntities();

AbstractEntity getEntityById(java.lang.String id);

void addDataEntity(DataEntity entity, Boolean toHasPart);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/edu/kit/datamanager/ro_crate/RoCrate.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public ContextualEntity getContextualEntityById(String id) {
return this.roCratePayload.getContextualEntityById(id);
}

@Override
public List<ContextualEntity> getAllContextualEntities() {
return this.roCratePayload.getAllContextualEntities();
}

@Override
public AbstractEntity getEntityById(String id) {
return this.roCratePayload.getEntityById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ void creationUrlTest() {
void creationFromPairsJsonTest() {
var objectMapper = MyObjectMapper.getMapper();

ObjectNode res = objectMapper.createObjectNode();
ObjectNode node = objectMapper.createObjectNode();
node.put("house", "www.example.con/house");
node.put("road", "www.example.con/road");

res.set("@context", node);
RoCrateMetadataContext newContext = new RoCrateMetadataContext(node);
HelpFunctions.compare(newContext.getContextJsonEntity(), res, true);
ObjectNode rawContext = objectMapper.createObjectNode();
rawContext.put("house", "www.example.con/house");
rawContext.put("road", "www.example.con/road");

ObjectNode rawCrate = objectMapper.createObjectNode();
rawCrate.set("@context", rawContext);
RoCrateMetadataContext newContext = new RoCrateMetadataContext(rawContext);
assertNotNull(newContext);

HelpFunctions.compare(newContext.getContextJsonEntity(), rawCrate, true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

public class TestRemoveAddEntity {
Expand All @@ -27,8 +29,12 @@ void testAddRemoveEntity() throws IOException {
.build();
HelpFunctions.compareCrateJsonToFileInResources(roCrate, "/json/crate/onlyOneFile.json");

assertEquals(0, roCrate.getAllContextualEntities().size());
assertEquals(1, roCrate.getAllDataEntities().size());

// remove entity and check if equals to the basic crate
roCrate.deleteEntityById("survey-responses-2019.csv");
assertEquals(0, roCrate.getAllDataEntities().size());
HelpFunctions.compareCrateJsonToFileInResources(roCrate, "/json/crate/simple.json");
}

Expand Down Expand Up @@ -64,10 +70,20 @@ void withTwoFiles() throws IOException {

HelpFunctions.compareCrateJsonToFileInResources(roCrate, "/json/crate/twoFiles.json");

assertEquals(2, roCrate.getAllDataEntities().size());
assertEquals(2, roCrate.getAllContextualEntities().size());

roCrate.deleteEntityById("data1.txt");
assertEquals(1, roCrate.getAllDataEntities().size());

roCrate.deleteEntityById("data2.txt");
assertEquals(0, roCrate.getAllDataEntities().size());

roCrate.deleteEntityById("#alice");
assertEquals(1, roCrate.getAllContextualEntities().size());

roCrate.deleteEntityById("http://sws.geonames.org/8152662/");
assertEquals(0, roCrate.getAllContextualEntities().size());

RoCrate roCrate2 = new RoCrate.RoCrateBuilder("Example RO-Crate",
"The RO-Crate Root Data Entity").build();
Expand Down Expand Up @@ -102,8 +118,15 @@ void removeOtherOccur() throws JsonProcessingException {
.addDataEntity(file)
.build();

assertEquals(1, roCrate.getAllDataEntities().size());
assertEquals(2, roCrate.getAllContextualEntities().size());

roCrate.deleteEntityById(person.getId());
assertEquals(1, roCrate.getAllContextualEntities().size());

roCrate.deleteEntityById(place.getId());
assertEquals(0, roCrate.getAllContextualEntities().size());
assertEquals(1, roCrate.getAllDataEntities().size());

FileEntity file2 = new FileEntity.FileEntityBuilder()
.setId("data1.txt")
Expand Down

0 comments on commit 427bd2e

Please sign in to comment.