78180: Create testIsOrgUnitOfPersonRelationshipMetadataViaREST

This commit is contained in:
Bruno Roemers
2021-04-07 10:28:38 +02:00
parent b30a086361
commit c4e96713f0
2 changed files with 88 additions and 1 deletions

View File

@@ -2841,6 +2841,11 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.andExpect(status().isNotFound());
}
/**
* Verify whether the relationship metadata appears correctly on both members.
* {@link #isAuthorOfPublicationRelationshipType} is tested again in
* {@link LeftTiltedRelationshipRestRepositoryIT} with tilted set to left.
*/
@Test
public void testIsAuthorOfPublicationRelationshipMetadataViaREST() throws Exception {
context.turnOffAuthorisationSystem();
@@ -2876,4 +2881,44 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
)));
}
/**
* Verify whether the relationship metadata appears correctly on both members.
* {@link #isOrgUnitOfPersonRelationshipType} is tested again in
* {@link RightTiltedRelationshipRestRepositoryIT} with tilted set to right.
*/
@Test
public void testIsOrgUnitOfPersonRelationshipMetadataViaREST() throws Exception {
context.turnOffAuthorisationSystem();
RelationshipBuilder.createRelationshipBuilder(
context, author1, orgUnit1, isOrgUnitOfPersonRelationshipType
).build();
context.restoreAuthSystemState();
String adminToken = getAuthToken(admin.getEmail(), password);
// get author metadata using REST
getClient(adminToken)
.perform(
get("/api/core/items/{uuid}", author1.getID())
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.metadata", matchMetadata(
String.format("%s.isOrgUnitOfPerson", MetadataSchemaEnum.RELATION.getName()),
orgUnit1.getID().toString()
)));
// get org unit metadata using REST
getClient(adminToken)
.perform(
get("/api/core/items/{uuid}", orgUnit1.getID())
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.metadata", matchMetadata(
String.format("%s.isPersonOfOrgUnit", MetadataSchemaEnum.RELATION.getName()),
author1.getID().toString()
)));
}
}

View File

@@ -7,8 +7,16 @@
*/
package org.dspace.app.rest;
import static org.dspace.app.rest.matcher.MetadataMatcher.matchMetadata;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.dspace.builder.RelationshipBuilder;
import org.dspace.content.MetadataSchemaEnum;
import org.dspace.content.RelationshipType;
import org.junit.Before;
import org.junit.Test;
public class RightTiltedRelationshipRestRepositoryIT extends RelationshipRestRepositoryIT {
@@ -25,6 +33,40 @@ public class RightTiltedRelationshipRestRepositoryIT extends RelationshipRestRep
context.restoreAuthSystemState();
}
// TODO create new test in parent class to test tilted right, then override here
@Override
@Test
public void testIsOrgUnitOfPersonRelationshipMetadataViaREST() throws Exception {
context.turnOffAuthorisationSystem();
RelationshipBuilder.createRelationshipBuilder(
context, author1, orgUnit1, isOrgUnitOfPersonRelationshipType
).build();
context.restoreAuthSystemState();
String adminToken = getAuthToken(admin.getEmail(), password);
// get author metadata using REST
getClient(adminToken)
.perform(
get("/api/core/items/{uuid}", author1.getID())
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.metadata", matchMetadata(
String.format("%s.isOrgUnitOfPerson", MetadataSchemaEnum.RELATION.getName()),
orgUnit1.getID().toString()
)));
// get org unit metadata using REST
getClient(adminToken)
.perform(
get("/api/core/items/{uuid}", orgUnit1.getID())
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.metadata", matchMetadata(
String.format("%s.isPersonOfOrgUnit", MetadataSchemaEnum.RELATION.getName()),
author1.getID().toString()
)));
}
}