Search in sources :

Example 1 with Account

use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method accountHasValidIdentifierInvalid.

@Test
public void accountHasValidIdentifierInvalid() {
    Account account = Account.create();
    account.setEnrollments(null);
    assertFalse(BridgeUtils.hasValidIdentifier(account));
    account = Account.create();
    Enrollment en1 = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
    account.setEnrollments(ImmutableSet.of(en1));
    assertFalse(BridgeUtils.hasValidIdentifier(account));
    account = Account.create();
    account.setEnrollments(ImmutableSet.of());
    assertFalse(BridgeUtils.hasValidIdentifier(account));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 2 with Account

use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method externalIdsVisibleToCaller.

@Test
public void externalIdsVisibleToCaller() {
    Set<String> callerStudies = ImmutableSet.of("studyA", "studyB", "studyD");
    RequestContext.set(new RequestContext.Builder().withCallerUserId(TEST_USER_ID).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).withOrgSponsoredStudies(callerStudies).build());
    Enrollment enA = Enrollment.create(TEST_APP_ID, "studyA", "id", "extA");
    Enrollment enB = Enrollment.create(TEST_APP_ID, "studyB", "id", "extB");
    Enrollment enC = Enrollment.create(TEST_APP_ID, "studyC", "id", "extC");
    Account account = Account.create();
    account.setId("id");
    account.setEnrollments(ImmutableSet.of(enA, enB, enC));
    Map<String, String> visibles = BridgeUtils.studyAssociationsVisibleToCaller(account).getExternalIdsVisibleToCaller();
    assertEquals(visibles, ImmutableMap.of("studyA", "extA", "studyB", "extB"));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 3 with Account

use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method participantEligibleForDeletion_affiliatedResearcherAllowed.

@Test
public void participantEligibleForDeletion_affiliatedResearcherAllowed() {
    RequestContext.set(new RequestContext.Builder().withOrgSponsoredStudies(USER_STUDY_IDS).withCallerRoles(ImmutableSet.of(RESEARCHER)).build());
    RequestInfoService mockService = mock(RequestInfoService.class);
    Account account = Account.create();
    account.setEnrollments(STUDY_A_AND_B_ENROLLMENT);
    assertTrue(participantEligibleForDeletion(mockService, account));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) RequestInfoService(org.sagebionetworks.bridge.services.RequestInfoService) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 4 with Account

use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method participantEligibleForDeletion_multipleEnrollmentsFail.

@Test
public void participantEligibleForDeletion_multipleEnrollmentsFail() {
    RequestContext.set(new RequestContext.Builder().withOrgSponsoredStudies(// mismatch
    ImmutableSet.of("studyA", "studyC")).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
    RequestInfoService mockService = mock(RequestInfoService.class);
    Account account = Account.create();
    account.setEnrollments(STUDY_A_AND_B_ENROLLMENT);
    assertFalse(participantEligibleForDeletion(mockService, account));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) RequestInfoService(org.sagebionetworks.bridge.services.RequestInfoService) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 5 with Account

use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method studyIdsVisibleToCallerFilters.

@Test
public void studyIdsVisibleToCallerFilters() {
    Set<String> callerStudies = ImmutableSet.of("studyA", "studyB", "studyD");
    RequestContext.set(new RequestContext.Builder().withCallerUserId("callerUserId").withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).withOrgSponsoredStudies(callerStudies).build());
    Enrollment enA = Enrollment.create(TEST_APP_ID, "studyA", "id");
    Enrollment enB = Enrollment.create(TEST_APP_ID, "studyB", "id");
    Enrollment enC = Enrollment.create(TEST_APP_ID, "studyC", "id");
    Account account = Account.create();
    account.setEnrollments(ImmutableSet.of(enA, enB, enC));
    Set<String> visibles = BridgeUtils.studyAssociationsVisibleToCaller(account).getStudyIdsVisibleToCaller();
    assertEquals(visibles, ImmutableSet.of("studyA", "studyB"));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Aggregations

Account (org.sagebionetworks.bridge.models.accounts.Account)401 Test (org.testng.annotations.Test)289 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)73 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)70 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)61 App (org.sagebionetworks.bridge.models.apps.App)58 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)53 RequestContext (org.sagebionetworks.bridge.RequestContext)47 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)33 AssessmentConfigValidatorTest (org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)29 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)23 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)22 GetMapping (org.springframework.web.bind.annotation.GetMapping)20 Study (org.sagebionetworks.bridge.models.studies.Study)19 DateTime (org.joda.time.DateTime)17 PostMapping (org.springframework.web.bind.annotation.PostMapping)17 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 PagedResourceList (org.sagebionetworks.bridge.models.PagedResourceList)15 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)14 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)13