-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed notifyCustodiansOfApprovedDatasets()
- Loading branch information
Showing
4 changed files
with
179 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.google.gson.Gson; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.broadinstitute.consent.http.enumeration.PropertyType; | ||
import org.broadinstitute.consent.http.models.dataset_registration_v1.ConsentGroup.AccessManagement; | ||
import org.broadinstitute.consent.http.util.gson.GsonUtil; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class DatasetTests { | ||
|
@@ -176,4 +178,62 @@ void testIsDatasetMatchControlledAccess() { | |
assertTrue(ds.isDatasetMatch(value, AccessManagement.CONTROLLED)); | ||
assertFalse(ds.isDatasetMatch(RandomStringUtils.randomAlphanumeric(25), AccessManagement.OPEN)); | ||
} | ||
|
||
@Test | ||
void testGetDataDepositorEmails() { | ||
Dataset ds = new Dataset(); | ||
|
||
assertTrue(ds.getDataDepositorEmails().isEmpty()); | ||
|
||
DatasetProperty depositorProp = new DatasetProperty(); | ||
depositorProp.setPropertyName("Data Depositor"); | ||
depositorProp.setPropertyValue("[email protected]"); | ||
depositorProp.setSchemaProperty("dataDepositorEmail"); | ||
depositorProp.setPropertyType(PropertyType.String); | ||
ds.setProperties(Set.of(depositorProp)); | ||
|
||
assertTrue(ds.getDataDepositorEmails().size() == 1); | ||
assertEquals(ds.getDataDepositorEmails(), List.of("[email protected]")); | ||
|
||
Gson gson = GsonUtil.getInstance(); | ||
DatasetProperty custodianProp = new DatasetProperty(); | ||
custodianProp.setSchemaProperty("dataCustodianEmail"); | ||
custodianProp.setPropertyName("Custodian Email"); | ||
custodianProp.setPropertyType(PropertyType.Json); | ||
custodianProp.setPropertyValue(gson.toJson(List.of("[email protected]"))); | ||
ds.setProperties(Set.of(depositorProp, custodianProp)); | ||
|
||
assertTrue(ds.getDataDepositorEmails().size() == 1); | ||
assertEquals(ds.getDataDepositorEmails(), List.of("[email protected]")); | ||
|
||
} | ||
|
||
@Test | ||
void testGetDataCustodianEmails() { | ||
Dataset ds = new Dataset(); | ||
|
||
assertTrue(ds.getDataCustodianEmails().isEmpty()); | ||
|
||
Gson gson = GsonUtil.getInstance(); | ||
DatasetProperty custodianProp = new DatasetProperty(); | ||
custodianProp.setSchemaProperty("dataCustodianEmail"); | ||
custodianProp.setPropertyName("Custodian Email"); | ||
custodianProp.setPropertyType(PropertyType.Json); | ||
custodianProp.setPropertyValue(gson.toJson(List.of("[email protected]"))); | ||
ds.setProperties(Set.of(custodianProp)); | ||
|
||
assertTrue(ds.getDataCustodianEmails().size() == 1); | ||
assertEquals(ds.getDataCustodianEmails(), List.of("[email protected]")); | ||
|
||
DatasetProperty depositorProp = new DatasetProperty(); | ||
depositorProp.setPropertyName("Data Depositor"); | ||
depositorProp.setPropertyValue("[email protected]"); | ||
depositorProp.setSchemaProperty("dataDepositorEmail"); | ||
depositorProp.setPropertyType(PropertyType.String); | ||
ds.setProperties(Set.of(depositorProp, custodianProp)); | ||
|
||
assertTrue(ds.getDataCustodianEmails().size() == 1); | ||
assertEquals(ds.getDataCustodianEmails(), List.of("[email protected]")); | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
import static org.mockito.Mockito.when; | ||
import static org.mockito.MockitoAnnotations.openMocks; | ||
|
||
import com.google.gson.Gson; | ||
import org.broadinstitute.consent.http.util.gson.GsonUtil; | ||
import jakarta.ws.rs.NotFoundException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
@@ -781,6 +783,7 @@ public void testNotifyCustodiansOfApprovedDatasets() { | |
DatasetProperty depositorProp = new DatasetProperty(); | ||
depositorProp.setPropertyName("Data Depositor"); | ||
depositorProp.setPropertyValue("[email protected]"); | ||
depositorProp.setSchemaProperty("dataDepositorEmail"); | ||
depositorProp.setPropertyType(PropertyType.String); | ||
|
||
Dataset d1 = new Dataset(); | ||
|
@@ -836,8 +839,68 @@ public void testNotifyCustodiansOfApprovedDatasets() { | |
} | ||
|
||
@Test | ||
public void testNotifyCustodiansOfApprovedDatasetsNoSubmitterOrDepositorOrCustodians() | ||
throws Exception { | ||
public void testNotifyCustodiansOfApprovedDatasetsWithCustodianProps() { | ||
User submitter = new User(); | ||
submitter.setEmail("[email protected]"); | ||
submitter.setDisplayName("submitter"); | ||
submitter.setUserId(4); | ||
|
||
Gson gson = GsonUtil.getInstance(); | ||
DatasetProperty custodianProp = new DatasetProperty(); | ||
custodianProp.setSchemaProperty("dataCustodianEmail"); | ||
custodianProp.setPropertyName("Custodian Email"); | ||
custodianProp.setPropertyType(PropertyType.Json); | ||
custodianProp.setPropertyValue(gson.toJson(List.of("[email protected]"))); | ||
|
||
Dataset d1 = new Dataset(); | ||
d1.setDataSetId(1); | ||
d1.setName(RandomStringUtils.random(50, true, false)); | ||
d1.setAlias(1); | ||
d1.setDataUse(new DataUseBuilder().setGeneralUse(false).setCommercialUse(true).build()); | ||
d1.setProperties(Set.of(custodianProp)); | ||
d1.setCreateUserId(submitter.getUserId()); | ||
|
||
Dataset d2 = new Dataset(); | ||
d2.setDataSetId(2); | ||
d2.setName(RandomStringUtils.random(50, true, false)); | ||
d2.setAlias(2); | ||
d2.setDataUse(new DataUseBuilder().setGeneralUse(false).setHmbResearch(true).build()); | ||
d2.setProperties(Set.of(custodianProp)); | ||
d2.setCreateUserId(submitter.getUserId()); | ||
|
||
User researcher = new User(); | ||
researcher.setEmail("[email protected]"); | ||
researcher.setDisplayName("Researcher"); | ||
researcher.setUserId(1); | ||
|
||
User custodian = new User(); | ||
custodian.setEmail("[email protected]"); | ||
custodian.setDisplayName("custodian"); | ||
custodian.setUserId(3); | ||
|
||
when(userDAO.findUserById(submitter.getUserId())).thenReturn(submitter); | ||
when(userDAO.findUsersByEmailList(List.of(custodian.getEmail()))).thenReturn( | ||
List.of(custodian)); | ||
when(userDAO.findUsers(List.of(3))).thenReturn(List.of(custodian)); | ||
|
||
initService(); | ||
try { | ||
service.notifyCustodiansOfApprovedDatasets(List.of(d1, d2), researcher, "Dar Code"); | ||
verify(emailService, times(2)).sendDataCustodianApprovalMessage( | ||
any(), | ||
any(), | ||
any(), | ||
any(), | ||
any() | ||
); | ||
} catch (Exception e) { | ||
fail(e.getMessage()); | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void testNotifyCustodiansOfApprovedDatasetsNoSubmitterOrDepositorOrCustodians() throws Exception { | ||
User submitterNotFound = new User(); | ||
submitterNotFound.setEmail("[email protected]"); | ||
submitterNotFound.setDisplayName("submitter"); | ||
|