Search in sources :

Example 1 with CacheKey

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());
}
Also used : IntentToParticipate(org.sagebionetworks.bridge.models.itp.IntentToParticipate) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) Test(org.testng.annotations.Test)

Example 2 with CacheKey

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");
}
Also used : IntentToParticipate(org.sagebionetworks.bridge.models.itp.IntentToParticipate) TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) Test(org.testng.annotations.Test)

Example 3 with CacheKey

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());
}
Also used : IntentToParticipate(org.sagebionetworks.bridge.models.itp.IntentToParticipate) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) Test(org.testng.annotations.Test)

Example 4 with CacheKey

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) ConsentSignature(org.sagebionetworks.bridge.models.subpopulations.ConsentSignature) Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation) IntentToParticipate(org.sagebionetworks.bridge.models.itp.IntentToParticipate) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) Test(org.testng.annotations.Test)

Example 5 with CacheKey

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) Test(org.testng.annotations.Test)

Aggregations

CacheKey (org.sagebionetworks.bridge.cache.CacheKey)61 Test (org.testng.annotations.Test)16 Account (org.sagebionetworks.bridge.models.accounts.Account)13 App (org.sagebionetworks.bridge.models.apps.App)11 Study (org.sagebionetworks.bridge.models.studies.Study)11 IntentToParticipate (org.sagebionetworks.bridge.models.itp.IntentToParticipate)10 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)8 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)7 Subpopulation (org.sagebionetworks.bridge.models.subpopulations.Subpopulation)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 BridgeServiceException (org.sagebionetworks.bridge.exceptions.BridgeServiceException)5 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)5 IOException (java.io.IOException)4 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)4 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)4 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)4 AuthUtils.canAccessAccount (org.sagebionetworks.bridge.AuthUtils.canAccessAccount)3 RequestContext (org.sagebionetworks.bridge.RequestContext)3 Phone (org.sagebionetworks.bridge.models.accounts.Phone)3 Organization (org.sagebionetworks.bridge.models.organizations.Organization)3