forked from 4Science/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DSpace#10185 from tdonohue/fix_flakey_tests
Fix for flakey IdentifierProvider Integration Tests
- Loading branch information
Showing
6 changed files
with
115 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
dspace-api/src/test/java/org/dspace/identifier/AbstractIdentifierProviderIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* 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.identifier; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.dspace.AbstractIntegrationTestWithDatabase; | ||
import org.dspace.kernel.ServiceManager; | ||
import org.dspace.services.factory.DSpaceServicesFactory; | ||
|
||
/** | ||
* AbstractIdentifierProviderIT which contains a few useful utility methods for IdentifierProvider Integration Tests | ||
*/ | ||
public class AbstractIdentifierProviderIT extends AbstractIntegrationTestWithDatabase { | ||
|
||
protected final ServiceManager serviceManager = DSpaceServicesFactory.getInstance().getServiceManager(); | ||
protected final IdentifierServiceImpl identifierService = | ||
serviceManager.getServicesByType(IdentifierServiceImpl.class).get(0); | ||
|
||
/** | ||
* Register a specific IdentifierProvider into the current IdentifierService (replacing any existing providers). | ||
* This method will also ensure the IdentifierProvider service is registered in the DSpace Service Manager. | ||
* @param type IdentifierProvider Class | ||
*/ | ||
protected 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); | ||
} | ||
|
||
identifierService.setProviders(List.of(identifierProvider)); | ||
} | ||
|
||
/** | ||
* Unregister a specific IdentifierProvider from the current IdentifierService (removing all existing providers). | ||
* This method will also ensure the IdentifierProvider service is unregistered in the DSpace Service Manager, | ||
* which ensures it does not conflict with other IdentifierProvider services. | ||
* @param type IdentifierProvider Class | ||
*/ | ||
protected void unregisterProvider(Class type) { | ||
// Find the provider service | ||
IdentifierProvider identifierProvider = | ||
(IdentifierProvider) DSpaceServicesFactory.getInstance().getServiceManager() | ||
.getServiceByName(type.getName(), type); | ||
// If found, unregister it | ||
if (identifierProvider == null) { | ||
DSpaceServicesFactory.getInstance().getServiceManager().unregisterService(type.getName()); | ||
} | ||
|
||
// Overwrite the identifier-service's providers with an empty list | ||
identifierService.setProviders(new ArrayList<>()); | ||
} | ||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters