use of org.sagebionetworks.bridge.cache.CacheKey in project BridgeServer2 by Sage-Bionetworks.
the class IntentServiceTest method submitIntentToParticipateWithoutInstallLinks.
@Test
public void submitIntentToParticipateWithoutInstallLinks() {
IntentToParticipate intent = TestUtils.getIntentToParticipate(TIMESTAMP).build();
when(mockApp.getIdentifier()).thenReturn(TEST_APP_ID);
when(mockAppService.getApp(intent.getAppId())).thenReturn(mockApp);
CacheKey cacheKey = CacheKey.itp(SubpopulationGuid.create("subpopGuid"), TEST_APP_ID, PHONE);
service.submitIntentToParticipate(intent);
verify(mockSubpopService).getSubpopulation(eq(TEST_APP_ID), subpopGuidCaptor.capture());
assertEquals(subpopGuidCaptor.getValue().getGuid(), intent.getSubpopGuid());
// We do store the intent
verify(mockCacheProvider).setObject(keyCaptor.capture(), eq(intent), eq(4 * 60 * 60));
assertEquals(keyCaptor.getValue(), cacheKey);
// But we don't send a message because installLinks map is empty
verify(mockSmsService, never()).sendSmsMessage(any(), any());
}
use of org.sagebionetworks.bridge.cache.CacheKey in project BridgeServer2 by Sage-Bionetworks.
the class IntentServiceTest method submitIntentToParticipateWithEmail.
@Test
public void submitIntentToParticipateWithEmail() throws Exception {
IntentToParticipate intent = TestUtils.getIntentToParticipate(TIMESTAMP).withPhone(null).withOsName("iOS").withEmail("email@email.com").build();
Map<String, String> installLinks = Maps.newHashMap();
installLinks.put("iOS", "this-is-a-link");
installLinks.put("Android", "the-wrong-link");
when(mockApp.getIdentifier()).thenReturn(TEST_APP_ID);
when(mockApp.getInstallLinks()).thenReturn(installLinks);
when(mockAppService.getApp(intent.getAppId())).thenReturn(mockApp);
TemplateRevision revision = TemplateRevision.create();
revision.setSubject("subject");
revision.setDocumentContent("body ${appInstallUrl}");
revision.setMimeType(HTML);
when(mockTemplateService.getRevisionForUser(mockApp, EMAIL_APP_INSTALL_LINK)).thenReturn(revision);
CacheKey cacheKey = CacheKey.itp(SubpopulationGuid.create("subpopGuid"), TEST_APP_ID, "email@email.com");
service.submitIntentToParticipate(intent);
verify(mockSubpopService).getSubpopulation(eq(TEST_APP_ID), subpopGuidCaptor.capture());
assertEquals(subpopGuidCaptor.getValue().getGuid(), intent.getSubpopGuid());
verify(mockCacheProvider).setObject(keyCaptor.capture(), eq(intent), eq(4 * 60 * 60));
assertEquals(keyCaptor.getValue(), cacheKey);
verify(mockParticipantService).sendInstallLinkMessage(mockApp, TRANSACTIONAL, null, "email@email.com", null, "iPhone OS");
}
use of org.sagebionetworks.bridge.cache.CacheKey in project BridgeServer2 by Sage-Bionetworks.
the class IntentServiceTest method submitIntentToParticipateExists.
@Test
public void submitIntentToParticipateExists() {
IntentToParticipate intent = TestUtils.getIntentToParticipate(TIMESTAMP).build();
Map<String, String> installLinks = Maps.newHashMap();
installLinks.put("Android", "this-is-a-link");
CacheKey cacheKey = CacheKey.itp(SubpopulationGuid.create("subpopGuid"), TEST_APP_ID, TestConstants.PHONE);
when(mockApp.getIdentifier()).thenReturn(TEST_APP_ID);
when(mockAppService.getApp(intent.getAppId())).thenReturn(mockApp);
when(mockCacheProvider.getObject(cacheKey, IntentToParticipate.class)).thenReturn(intent);
service.submitIntentToParticipate(intent);
verify(mockSubpopService).getSubpopulation(eq(TEST_APP_ID), subpopGuidCaptor.capture());
assertEquals(subpopGuidCaptor.getValue().getGuid(), intent.getSubpopGuid());
// These are not called.
verify(mockCacheProvider, never()).setObject(cacheKey, intent, (4 * 60 * 60));
verify(mockSmsService, never()).sendSmsMessage(any(), any());
}
use of org.sagebionetworks.bridge.cache.CacheKey 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.cache.CacheKey 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);
}
Aggregations