#9806: Move cleanup of handle provider to destroy in VersionedHandleIdentifierProviderIT

(cherry picked from commit f6cabe648d)
This commit is contained in:
Kim Shepherd
2024-09-06 17:58:23 +02:00
committed by github-actions[bot]
parent 8f86801796
commit ad7499f245
2 changed files with 20 additions and 25 deletions

View File

@@ -60,9 +60,6 @@ import org.dspace.content.virtual.VirtualMetadataConfiguration;
import org.dspace.content.virtual.VirtualMetadataPopulator;
import org.dspace.core.Constants;
import org.dspace.discovery.SolrSearchCore;
import org.dspace.identifier.IdentifierProvider;
import org.dspace.identifier.IdentifierServiceImpl;
import org.dspace.identifier.VersionedHandleIdentifierProvider;
import org.dspace.kernel.ServiceManager;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.versioning.Version;
@@ -84,7 +81,6 @@ public class VersioningWithRelationshipsIT extends AbstractIntegrationTestWithDa
ContentServiceFactory.getInstance().getItemService();
private final SolrSearchCore solrSearchCore =
DSpaceServicesFactory.getInstance().getServiceManager().getServicesByType(SolrSearchCore.class).get(0);
private IdentifierServiceImpl identifierService;
protected Community community;
protected Collection collection;
protected EntityType publicationEntityType;
@@ -101,22 +97,6 @@ public class VersioningWithRelationshipsIT extends AbstractIntegrationTestWithDa
protected RelationshipType isIssueOfJournalVolume;
protected RelationshipType isProjectOfPerson;
private void registerProvider(Class type) {
// Register our new provider
IdentifierProvider identifierProvider =
(IdentifierProvider) DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(type.getName(), type);
if (identifierProvider == null) {
DSpaceServicesFactory.getInstance().getServiceManager().registerServiceClass(type.getName(), type);
identifierProvider = (IdentifierProvider) DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(type.getName(), type);
}
// Overwrite the identifier-service's providers with the new one to ensure only this provider is used
identifierService = DSpaceServicesFactory.getInstance().getServiceManager()
.getServicesByType(IdentifierServiceImpl.class).get(0);
identifierService.setProviders(new ArrayList<>());
identifierService.setProviders(List.of(identifierProvider));
}
@Override
@Before
public void setUp() throws Exception {
@@ -124,9 +104,6 @@ public class VersioningWithRelationshipsIT extends AbstractIntegrationTestWithDa
context.turnOffAuthorisationSystem();
registerProvider(VersionedHandleIdentifierProvider.class);
community = CommunityBuilder.createCommunity(context)
.withName("community")
.build();

View File

@@ -24,6 +24,7 @@ import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.kernel.ServiceManager;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -57,13 +58,30 @@ public class VersionedHandleIdentifierProviderIT extends AbstractIntegrationTest
.build();
}
@After
@Override
public void destroy() throws Exception {
super.destroy();
// After this test has finished running, refresh application context and
// set the expected 'default' versioned handle provider back to ensure other tests don't fail
DSpaceServicesFactory.getInstance().getServiceManager().getApplicationContext().refresh();
}
private void registerProvider(Class type) {
// Register our new provider
serviceManager.registerServiceClass(type.getName(), type);
IdentifierProvider identifierProvider =
(IdentifierProvider) serviceManager.getServiceByName(type.getName(), type);
(IdentifierProvider) DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName(type.getName(), type);
if (identifierProvider == null) {
DSpaceServicesFactory.getInstance().getServiceManager().registerServiceClass(type.getName(), type);
identifierProvider = (IdentifierProvider) DSpaceServicesFactory.getInstance().getServiceManager()
.getServiceByName(type.getName(), type);
}
// Overwrite the identifier-service's providers with the new one to ensure only this provider is used
identifierService = DSpaceServicesFactory.getInstance().getServiceManager()
.getServicesByType(IdentifierServiceImpl.class).get(0);
identifierService.setProviders(new ArrayList<>());
identifierService.setProviders(List.of(identifierProvider));
}