[CST-5669] Fixed ResearcherProfileRestRepositoryIT tests

This commit is contained in:
Luca Giamminonni
2022-04-29 11:15:21 +02:00
parent 58694eaed8
commit a7a49c81c6
2 changed files with 22 additions and 6 deletions

View File

@@ -16,14 +16,17 @@ import static org.dspace.eperson.Group.ANONYMOUS;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import javax.annotation.PostConstruct;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.dspace.app.exception.ResourceAlreadyExistsException; import org.dspace.app.exception.ResourceAlreadyExistsException;
import org.dspace.app.profile.service.AfterResearcherProfileCreationAction;
import org.dspace.app.profile.service.ResearcherProfileService; import org.dspace.app.profile.service.ResearcherProfileService;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService; import org.dspace.authorize.service.AuthorizeService;
@@ -86,6 +89,18 @@ public class ResearcherProfileServiceImpl implements ResearcherProfileService {
@Autowired @Autowired
private AuthorizeService authorizeService; private AuthorizeService authorizeService;
@Autowired(required = false)
private List<AfterResearcherProfileCreationAction> afterCreationActions;
@PostConstruct
public void postConstruct() {
if (afterCreationActions == null) {
afterCreationActions = Collections.emptyList();
}
}
@Override @Override
public ResearcherProfile findById(Context context, UUID id) throws SQLException, AuthorizeException { public ResearcherProfile findById(Context context, UUID id) throws SQLException, AuthorizeException {
Assert.notNull(id, "An id must be provided to find a researcher profile"); Assert.notNull(id, "An id must be provided to find a researcher profile");
@@ -111,15 +126,16 @@ public class ResearcherProfileServiceImpl implements ResearcherProfileService {
.orElseThrow(() -> new IllegalStateException("No collection found for researcher profiles")); .orElseThrow(() -> new IllegalStateException("No collection found for researcher profiles"));
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
try { Item item = createProfileItem(context, ePerson, collection);
context.restoreAuthSystemState();
Item item = createProfileItem(context, ePerson, collection); ResearcherProfile researcherProfile = new ResearcherProfile(item);
return new ResearcherProfile(item);
} finally { for (AfterResearcherProfileCreationAction afterCreationAction : afterCreationActions) {
context.restoreAuthSystemState(); afterCreationAction.perform(context, researcherProfile, ePerson);
} }
return researcherProfile;
} }
@Override @Override

View File

@@ -1891,7 +1891,7 @@ public class ResearcherProfileRestRepositoryIT extends AbstractControllerIntegra
getClient(authToken) getClient(authToken)
.perform(post("/api/eperson/profiles/").contentType(TEXT_URI_LIST) .perform(post("/api/eperson/profiles/").contentType(TEXT_URI_LIST)
.content("http://localhost:8080/server/api/core/items/" + id)) .content("http://localhost:8080/server/api/core/items/" + id))
.andExpect(status().isConflict()); .andExpect(status().isUnprocessableEntity());
} }
private Item createProfile(EPerson ePerson) throws Exception { private Item createProfile(EPerson ePerson) throws Exception {