Search in sources :

Example 1 with IntentToParticipate

use of org.sagebionetworks.bridge.models.itp.IntentToParticipate 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 IntentToParticipate

use of org.sagebionetworks.bridge.models.itp.IntentToParticipate 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 IntentToParticipate

use of org.sagebionetworks.bridge.models.itp.IntentToParticipate 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 IntentToParticipate

use of org.sagebionetworks.bridge.models.itp.IntentToParticipate in project BridgeServer2 by Sage-Bionetworks.

the class IntentServiceTest method submitIntentToParticipateInvalid.

@Test(expectedExceptions = InvalidEntityException.class)
public void submitIntentToParticipateInvalid() {
    IntentToParticipate intent = TestUtils.getIntentToParticipate(TIMESTAMP).build();
    IntentToParticipate invalid = new IntentToParticipate.Builder().copyOf(intent).withPhone(null).build();
    service.submitIntentToParticipate(invalid);
}
Also used : IntentToParticipate(org.sagebionetworks.bridge.models.itp.IntentToParticipate) Test(org.testng.annotations.Test)

Example 5 with IntentToParticipate

use of org.sagebionetworks.bridge.models.itp.IntentToParticipate 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)

Aggregations

IntentToParticipate (org.sagebionetworks.bridge.models.itp.IntentToParticipate)27 Test (org.testng.annotations.Test)23 CacheKey (org.sagebionetworks.bridge.cache.CacheKey)10 Account (org.sagebionetworks.bridge.models.accounts.Account)5 Subpopulation (org.sagebionetworks.bridge.models.subpopulations.Subpopulation)4 ConsentSignature (org.sagebionetworks.bridge.models.subpopulations.ConsentSignature)3 TemplateRevision (org.sagebionetworks.bridge.models.templates.TemplateRevision)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)2 Phone (org.sagebionetworks.bridge.models.accounts.Phone)2 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)1 SharingOption (org.sagebionetworks.bridge.models.accounts.SharingOption)1 App (org.sagebionetworks.bridge.models.apps.App)1 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1