mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Added IT for the updated InitializeEntities script
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE relationships SYSTEM "relationship-types.dtd">
|
||||
|
||||
<relationships>
|
||||
<type>
|
||||
<leftType>Publication</leftType>
|
||||
<rightType>Person</rightType>
|
||||
<leftLabel>isAuthorOfPublication</leftLabel>
|
||||
<rightLabel>isPublicationOfAuthor</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>10</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>0</min>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>Publication</leftType>
|
||||
<rightType>Project</rightType>
|
||||
<leftLabel>isProjectOfPublication</leftLabel>
|
||||
<rightLabel>isPublicationOfProject</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>0</min>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>Publication</leftType>
|
||||
<rightType>OrgUnit</rightType>
|
||||
<leftLabel>isOrgUnitOfPublication</leftLabel>
|
||||
<rightLabel>isPublicationOfOrgUnit</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>0</min>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>Person</leftType>
|
||||
<rightType>Project</rightType>
|
||||
<leftLabel>isProjectOfPerson</leftLabel>
|
||||
<rightLabel>isPersonOfProject</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>0</min>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>Person</leftType>
|
||||
<rightType>OrgUnit</rightType>
|
||||
<leftLabel>isOrgUnitOfPerson</leftLabel>
|
||||
<rightLabel>isPersonOfOrgUnit</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>0</min>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>Project</leftType>
|
||||
<rightType>OrgUnit</rightType>
|
||||
<leftLabel>isOrgUnitOfProject</leftLabel>
|
||||
<rightLabel>isProjectOfOrgUnit</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>0</min>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>Journal</leftType>
|
||||
<rightType>JournalVolume</rightType>
|
||||
<leftLabel>isVolumeOfJournal</leftLabel>
|
||||
<rightLabel>isJournalOfVolume</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>1</min>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>JournalVolume</leftType>
|
||||
<rightType>JournalIssue</rightType>
|
||||
<leftLabel>isIssueOfJournalVolume</leftLabel>
|
||||
<rightLabel>isJournalVolumeOfIssue</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>1</min>
|
||||
<max>1</max>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>Publication</leftType>
|
||||
<rightType>OrgUnit</rightType>
|
||||
<leftLabel>isAuthorOfPublication</leftLabel>
|
||||
<rightLabel>isPublicationOfAuthor</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>0</min>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
<type>
|
||||
<leftType>JournalIssue</leftType>
|
||||
<rightType>Publication</rightType>
|
||||
<leftLabel>isPublicationOfJournalIssue</leftLabel>
|
||||
<rightLabel>isJournalIssueOfPublication</rightLabel>
|
||||
<leftCardinality>
|
||||
<min>0</min>
|
||||
</leftCardinality>
|
||||
<rightCardinality>
|
||||
<min>0</min>
|
||||
<max>1</max>
|
||||
</rightCardinality>
|
||||
</type>
|
||||
</relationships>
|
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
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 java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.matcher.RelationshipTypeMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.EntityType;
|
||||
import org.dspace.content.Relationship;
|
||||
import org.dspace.content.RelationshipType;
|
||||
import org.dspace.content.service.EntityTypeService;
|
||||
import org.dspace.content.service.RelationshipService;
|
||||
import org.dspace.content.service.RelationshipTypeService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class InitializeEntitiesIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private RelationshipTypeService relationshipTypeService;
|
||||
|
||||
@Autowired
|
||||
private EntityTypeService entityTypeService;
|
||||
|
||||
@Autowired
|
||||
private RelationshipService relationshipService;
|
||||
|
||||
@Autowired
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
|
||||
//Set up the database for the next test
|
||||
String pathToFile = configurationService.getProperty("dspace.dir") +
|
||||
File.separator + "config" + File.separator + "entities" + File.separator + "relationship-types.xml";
|
||||
runDSpaceScript("initialize-entities", "-f", pathToFile);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() throws Exception {
|
||||
//Clean up the database for the next test
|
||||
context.turnOffAuthorisationSystem();
|
||||
List<RelationshipType> relationshipTypeList = relationshipTypeService.findAll(context);
|
||||
List<EntityType> entityTypeList = entityTypeService.findAll(context);
|
||||
List<Relationship> relationships = relationshipService.findAll(context);
|
||||
|
||||
Iterator<Relationship> relationshipIterator = relationships.iterator();
|
||||
while (relationshipIterator.hasNext()) {
|
||||
Relationship relationship = relationshipIterator.next();
|
||||
relationshipIterator.remove();
|
||||
relationshipService.delete(context, relationship);
|
||||
}
|
||||
|
||||
Iterator<RelationshipType> relationshipTypeIterator = relationshipTypeList.iterator();
|
||||
while (relationshipTypeIterator.hasNext()) {
|
||||
RelationshipType relationshipType = relationshipTypeIterator.next();
|
||||
relationshipTypeIterator.remove();
|
||||
relationshipTypeService.delete(context, relationshipType);
|
||||
}
|
||||
|
||||
Iterator<EntityType> entityTypeIterator = entityTypeList.iterator();
|
||||
while (entityTypeIterator.hasNext()) {
|
||||
EntityType entityType = entityTypeIterator.next();
|
||||
entityTypeIterator.remove();
|
||||
entityTypeService.delete(context, entityType);
|
||||
}
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
|
||||
|
||||
List<RelationshipType> relationshipTypes = relationshipTypeService.findAll(context);
|
||||
|
||||
getClient().perform(get("/api/core/relationshiptypes"))
|
||||
|
||||
//We expect a 200 OK status
|
||||
.andExpect(status().isOk())
|
||||
//The type has to be 'discover'
|
||||
.andExpect(jsonPath("$.page.totalElements", is(10)))
|
||||
//There needs to be a self link to this endpoint
|
||||
.andExpect(jsonPath("$._links.self.href", containsString("api/core/relationshiptypes")))
|
||||
//We have 4 facets in the default configuration, they need to all be present in the embedded section
|
||||
.andExpect(jsonPath("$._embedded.relationshiptypes", containsInAnyOrder(
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(0)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(1)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(2)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(3)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(4)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(5)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(6)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(7)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(8)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(9)))
|
||||
));
|
||||
|
||||
getClient().perform(get("/api/core/relationshiptypes/" + relationshipTypes.get(0).getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.leftMinCardinality", is(0)));
|
||||
String pathToFile = configurationService.getProperty("dspace.dir") +
|
||||
File.separator + "config" + File.separator + "entities" + File.separator + "relationship-types-update.xml";
|
||||
runDSpaceScript("initialize-entities", "-f", pathToFile);
|
||||
|
||||
RelationshipType alteredRelationshipType = relationshipTypes.get(0);
|
||||
alteredRelationshipType.setLeftMinCardinality(10);
|
||||
getClient().perform(get("/api/core/relationshiptypes"))
|
||||
|
||||
//We expect a 200 OK status
|
||||
.andExpect(status().isOk())
|
||||
//The type has to be 'discover'
|
||||
.andExpect(jsonPath("$.page.totalElements", is(10)))
|
||||
//There needs to be a self link to this endpoint
|
||||
.andExpect(jsonPath("$._links.self.href", containsString("api/core/relationshiptypes")))
|
||||
//We have 4 facets in the default configuration, they need to all be present in the embedded section
|
||||
.andExpect(jsonPath("$._embedded.relationshiptypes", containsInAnyOrder(
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(alteredRelationshipType),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(1)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(2)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(3)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(4)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(5)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(6)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(7)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(8)),
|
||||
RelationshipTypeMatcher.matchRelationshipTypeEntry(relationshipTypes.get(9)))
|
||||
));
|
||||
|
||||
getClient().perform(get("/api/core/relationshiptypes/" + relationshipTypes.get(0).getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.leftMinCardinality", is(10)));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user