use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderStudyMigrationTest method subpopulationWithStudyIdentifier.
@Test
public void subpopulationWithStudyIdentifier() throws Exception {
String json = TestUtils.createJson("{'studyIdentifier':'" + TEST_APP_ID + "','type':'Subpopulation'}");
CacheKey key = CacheKey.subpop(SubpopulationGuid.create("subpopGuid"), TEST_APP_ID);
when(mockJedisOps.get(key.toString())).thenReturn(json);
Subpopulation subpop = provider.getObject(key, Subpopulation.class);
assertEquals(subpop.getAppId(), TEST_APP_ID);
}
use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderStudyMigrationTest method subpopulationWithAppId.
@Test
public void subpopulationWithAppId() throws Exception {
String json = TestUtils.createJson("{'appId':'" + TEST_APP_ID + "','type':'Subpopulation'}");
CacheKey key = CacheKey.subpop(SubpopulationGuid.create("subpopGuid"), TEST_APP_ID);
when(mockJedisOps.get(key.toString())).thenReturn(json);
Subpopulation subpop = provider.getObject(key, Subpopulation.class);
assertEquals(subpop.getAppId(), TEST_APP_ID);
}
use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.
the class IntentServiceTest method registerIntentToParticipateWithMultipleConsents.
@Test
public void registerIntentToParticipateWithMultipleConsents() {
Subpopulation subpopA = Subpopulation.create();
subpopA.setGuidString("AAA");
Subpopulation subpopB = Subpopulation.create();
subpopB.setGuidString("BBB");
IntentToParticipate intentAAA = new IntentToParticipate.Builder().withOsName("Android").withPhone(TestConstants.PHONE).withScope(SharingScope.NO_SHARING).withAppId(TEST_APP_ID).withSubpopGuid("AAA").withConsentSignature(new ConsentSignature.Builder().withName("Test Name").withBirthdate("1975-01-01").build()).build();
IntentToParticipate intentBBB = new IntentToParticipate.Builder().withOsName("Android").withPhone(TestConstants.PHONE).withScope(SharingScope.NO_SHARING).withAppId(TEST_APP_ID).withSubpopGuid("BBB").withConsentSignature(new ConsentSignature.Builder().withName("Test Name").withBirthdate("1975-01-01").build()).build();
Account account = Account.create();
account.setId("id");
account.setPhone(TestConstants.PHONE);
StudyParticipant participant = new StudyParticipant.Builder().build();
CacheKey keyAAA = CacheKey.itp(SubpopulationGuid.create("AAA"), TEST_APP_ID, TestConstants.PHONE);
CacheKey keyBBB = CacheKey.itp(SubpopulationGuid.create("BBB"), TEST_APP_ID, TestConstants.PHONE);
when(mockApp.getIdentifier()).thenReturn(TEST_APP_ID);
when(mockSubpopService.getSubpopulations(TEST_APP_ID, false)).thenReturn(Lists.newArrayList(subpopA, subpopB));
when(mockCacheProvider.getObject(keyAAA, IntentToParticipate.class)).thenReturn(intentAAA);
when(mockCacheProvider.getObject(keyBBB, IntentToParticipate.class)).thenReturn(intentBBB);
when(mockParticipantService.getParticipant(mockApp, "id", true)).thenReturn(participant);
service.registerIntentToParticipate(mockApp, account);
verify(mockSubpopService).getSubpopulations(TEST_APP_ID, false);
verify(mockCacheProvider).removeObject(keyAAA);
verify(mockCacheProvider).removeObject(keyBBB);
verify(mockConsentService).consentToResearch(eq(mockApp), eq(SubpopulationGuid.create("AAA")), any(), eq(intentAAA.getConsentSignature()), eq(intentAAA.getScope()), eq(true));
verify(mockConsentService).consentToResearch(eq(mockApp), eq(SubpopulationGuid.create("BBB")), any(), eq(intentBBB.getConsentSignature()), eq(intentBBB.getScope()), eq(true));
// Only loaded the participant once...
verify(mockParticipantService, times(1)).getParticipant(mockApp, "id", true);
}
use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.
the class IntentServiceTest method noIntentDoesNothing.
@Test
public void noIntentDoesNothing() {
Subpopulation subpopA = Subpopulation.create();
subpopA.setGuidString("AAA");
Subpopulation subpopB = Subpopulation.create();
subpopB.setGuidString("BBB");
Account account = Account.create();
account.setPhone(TestConstants.PHONE);
CacheKey key = CacheKey.itp(SubpopulationGuid.create("BBB"), TEST_APP_ID, PHONE);
when(mockApp.getIdentifier()).thenReturn(TEST_APP_ID);
when(mockSubpopService.getSubpopulations(TEST_APP_ID, false)).thenReturn(Lists.newArrayList(subpopA, subpopB));
service.registerIntentToParticipate(mockApp, account);
verify(mockSubpopService).getSubpopulations(TEST_APP_ID, false);
verify(mockCacheProvider, never()).removeObject(key);
verifyNoMoreInteractions(mockConsentService);
}
use of org.sagebionetworks.bridge.models.subpopulations.Subpopulation in project BridgeServer2 by Sage-Bionetworks.
the class ConsentServiceTest method setupWithdrawTest.
private void setupWithdrawTest(boolean subpop1Required, boolean subpop2Required) {
// two consents, withdrawing one does not turn sharing entirely off.
account.setSharingScope(SharingScope.ALL_QUALIFIED_RESEARCHERS);
account.setHealthCode(PARTICIPANT.getHealthCode());
Subpopulation subpop1 = Subpopulation.create();
subpop1.setName(SUBPOP_GUID.getGuid());
subpop1.setGuid(SUBPOP_GUID);
subpop1.setRequired(subpop1Required);
Subpopulation subpop2 = Subpopulation.create();
subpop2.setName(SECOND_SUBPOP.getGuid());
subpop2.setGuid(SECOND_SUBPOP);
subpop2.setRequired(subpop2Required);
doReturn(ImmutableList.of(subpop1, subpop2)).when(subpopService).getSubpopulationsForUser(any());
ConsentSignature secondConsentSignature = new ConsentSignature.Builder().withName("Test User").withBirthdate("1990-01-01").withSignedOn(SIGNED_ON).build();
account.setConsentSignatureHistory(SUBPOP_GUID, ImmutableList.of(CONSENT_SIGNATURE));
account.setConsentSignatureHistory(SECOND_SUBPOP, ImmutableList.of(secondConsentSignature));
}
Aggregations