forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pid): change business logic for DataverseServiceBean.wantsDatase…
…tVersionPids - Incorporate feedback from first review - Switch to model where admin sets limits but the collections can override but not exceed the limit - Use admin settings as defaults if collection chain does not provide a choice now - Also add unit testing for business logic See also IQSS#9462 (comment) See also IQSS#9462 (comment)
- Loading branch information
1 parent
0b51e1b
commit fa8d544
Showing
2 changed files
with
164 additions
and
27 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
119 changes: 119 additions & 0 deletions
119
src/test/java/edu/harvard/iq/dataverse/DataverseServiceBeanTest.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,119 @@ | ||
package edu.harvard.iq.dataverse; | ||
|
||
import edu.harvard.iq.dataverse.mocks.MocksFactory; | ||
import edu.harvard.iq.dataverse.settings.JvmSettings; | ||
import edu.harvard.iq.dataverse.util.testing.JvmSetting; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static edu.harvard.iq.dataverse.pidproviders.VersionPidMode.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class DataverseServiceBeanTest { | ||
|
||
DataverseServiceBean dataverseServiceBean = new DataverseServiceBean(); | ||
|
||
private static final Dataverse root = MocksFactory.makeDataverse(); | ||
private static final Dataverse intermediate = MocksFactory.makeDataverse(); | ||
private static final Dataverse child = MocksFactory.makeDataverse(); | ||
|
||
@BeforeAll | ||
static void setup() { | ||
intermediate.setOwner(root); | ||
child.setOwner(intermediate); | ||
} | ||
|
||
static Stream<Arguments> versionPidCombinationsForAdminMajor() { | ||
return Stream.of( | ||
Arguments.of(false, CollectionConduct.SKIP, false), | ||
Arguments.of(false, CollectionConduct.SKIP, true), | ||
Arguments.of(true, CollectionConduct.MAJOR, false), | ||
Arguments.of(false, CollectionConduct.MAJOR, true), | ||
Arguments.of(true, CollectionConduct.MINOR, false), | ||
Arguments.of(false, CollectionConduct.MINOR, true) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("versionPidCombinationsForAdminMajor") | ||
@JvmSetting(key = JvmSettings.PID_VERSIONS_MODE, value = "allow-major") | ||
void versionPidCollectionConductModesWithAdminMajorOnly(boolean expected, CollectionConduct rootConduct, boolean willBeMinor) { | ||
// given | ||
root.setDatasetVersionPidConduct(rootConduct); | ||
|
||
// when | ||
assertEquals(expected, dataverseServiceBean.wantsDatasetVersionPids(child, willBeMinor)); | ||
} | ||
|
||
static Stream<Arguments> versionPidCombinationsForAdminMinor() { | ||
return Stream.of( | ||
Arguments.of(false, CollectionConduct.SKIP, false), | ||
Arguments.of(false, CollectionConduct.SKIP, true), | ||
Arguments.of(true, CollectionConduct.MAJOR, false), | ||
Arguments.of(false, CollectionConduct.MAJOR, true), | ||
Arguments.of(true, CollectionConduct.MINOR, false), | ||
Arguments.of(true, CollectionConduct.MINOR, true) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("versionPidCombinationsForAdminMinor") | ||
@JvmSetting(key = JvmSettings.PID_VERSIONS_MODE, value = "allow-minor") | ||
void versionPidCollectionConductModesWithAdminMinor(boolean expected, CollectionConduct rootConduct, boolean willBeMinor) { | ||
// given | ||
root.setDatasetVersionPidConduct(rootConduct); | ||
|
||
// when | ||
assertEquals(expected, dataverseServiceBean.wantsDatasetVersionPids(child, willBeMinor)); | ||
} | ||
|
||
@Test | ||
void versionPidCollectionMayNotBeNull() { | ||
assertThrows(NullPointerException.class, () -> dataverseServiceBean.wantsDatasetVersionPids(null, false)); | ||
} | ||
|
||
@Test | ||
@JvmSetting(key = JvmSettings.PID_VERSIONS_MODE, value = "off") | ||
void versionPidCollectionAdminDisabled() { | ||
assertFalse(dataverseServiceBean.wantsDatasetVersionPids(child, false)); | ||
assertFalse(dataverseServiceBean.wantsDatasetVersionPids(child, true)); | ||
} | ||
|
||
@Test | ||
@JvmSetting(key = JvmSettings.PID_VERSIONS_MODE, value = "allow-major") | ||
void versionPidCollectionAdminMajorOnly() { | ||
assertFalse(dataverseServiceBean.wantsDatasetVersionPids(child, true)); | ||
} | ||
|
||
@Test | ||
@JvmSetting(key = JvmSettings.PID_VERSIONS_MODE, value = "allow-major") | ||
void versionPidNoCollectionConductButAdminMajorOnly() { | ||
// given | ||
Dataverse collection = MocksFactory.makeDataverse(); | ||
collection.setDatasetVersionPidConduct(CollectionConduct.INHERIT); | ||
|
||
// when & then | ||
assertTrue(dataverseServiceBean.wantsDatasetVersionPids(collection, false)); | ||
assertFalse(dataverseServiceBean.wantsDatasetVersionPids(collection, true)); | ||
} | ||
|
||
@Test | ||
@JvmSetting(key = JvmSettings.PID_VERSIONS_MODE, value = "allow-minor") | ||
void versionPidNoCollectionConductButAdminMinor() { | ||
// given | ||
Dataverse collection = MocksFactory.makeDataverse(); | ||
collection.setDatasetVersionPidConduct(CollectionConduct.INHERIT); | ||
|
||
// when & then | ||
assertTrue(dataverseServiceBean.wantsDatasetVersionPids(collection, false)); | ||
assertTrue(dataverseServiceBean.wantsDatasetVersionPids(collection, true)); | ||
} | ||
} |