Search in sources :

Example 1 with TemplateRevision

use of org.sagebionetworks.bridge.models.templates.TemplateRevision 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 2 with TemplateRevision

use of org.sagebionetworks.bridge.models.templates.TemplateRevision in project BridgeServer2 by Sage-Bionetworks.

the class ConsentServiceTest method resendConsentAgreementWithPhoneOK.

@Test
public void resendConsentAgreementWithPhoneOK() throws Exception {
    doReturn("asdf.pdf").when(consentService).getSignedConsentUrl();
    account.setConsentSignatureHistory(SUBPOP_GUID, ImmutableList.of(CONSENT_SIGNATURE));
    TemplateRevision revision = TemplateRevision.create();
    revision.setDocumentContent("some test content");
    when(templateService.getRevisionForUser(app, TemplateType.SMS_SIGNED_CONSENT)).thenReturn(revision);
    consentService.resendConsentAgreement(app, SUBPOP_GUID, PHONE_PARTICIPANT);
    verify(smsService).sendSmsMessage(eq(ID), smsProviderCaptor.capture());
    ArgumentCaptor<ObjectMetadata> metadataCaptor = ArgumentCaptor.forClass(ObjectMetadata.class);
    verify(s3Helper).writeBytesToS3(eq(ConsentService.USERSIGNED_CONSENTS_BUCKET), eq("asdf.pdf"), any(), metadataCaptor.capture());
    assertEquals(metadataCaptor.getValue().getSSEAlgorithm(), ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    SmsMessageProvider provider = smsProviderCaptor.getValue();
    assertEquals(provider.getPhone(), PHONE_PARTICIPANT.getPhone());
    assertEquals(provider.getApp(), app);
    assertEquals(provider.getSmsType(), "Transactional");
    assertEquals(provider.getTokenMap().get("consentUrl"), SHORT_URL);
    assertEquals(provider.getTemplateRevision().getDocumentContent(), revision.getDocumentContent());
}
Also used : TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) SmsMessageProvider(org.sagebionetworks.bridge.sms.SmsMessageProvider) Test(org.testng.annotations.Test)

Example 3 with TemplateRevision

use of org.sagebionetworks.bridge.models.templates.TemplateRevision in project BridgeServer2 by Sage-Bionetworks.

the class TemplateRevisionValidatorTest method valid.

@Test
public void valid() {
    TemplateRevision revision = createValidTemplate();
    Validate.entityThrowingException(INSTANCE, revision);
}
Also used : TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) Test(org.testng.annotations.Test)

Example 4 with TemplateRevision

use of org.sagebionetworks.bridge.models.templates.TemplateRevision in project BridgeServer2 by Sage-Bionetworks.

the class TemplateRevisionValidatorTest method validateStoragePath.

@Test
public void validateStoragePath() {
    TemplateRevision revision = createValidTemplate();
    revision.setStoragePath(null);
    assertValidatorMessage(INSTANCE, revision, "storagePath", "cannot be blank");
}
Also used : TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) Test(org.testng.annotations.Test)

Example 5 with TemplateRevision

use of org.sagebionetworks.bridge.models.templates.TemplateRevision in project BridgeServer2 by Sage-Bionetworks.

the class TemplateRevisionValidatorTest method validateCreatedOn.

@Test
public void validateCreatedOn() {
    TemplateRevision revision = createValidTemplate();
    revision.setCreatedOn(null);
    assertValidatorMessage(INSTANCE, revision, "createdOn", "cannot be null");
}
Also used : TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) Test(org.testng.annotations.Test)

Aggregations

TemplateRevision (org.sagebionetworks.bridge.models.templates.TemplateRevision)63 Test (org.testng.annotations.Test)42 BasicEmailProvider (org.sagebionetworks.bridge.services.email.BasicEmailProvider)9 SmsMessageProvider (org.sagebionetworks.bridge.sms.SmsMessageProvider)9 App (org.sagebionetworks.bridge.models.apps.App)5 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)4 Account (org.sagebionetworks.bridge.models.accounts.Account)4 Template (org.sagebionetworks.bridge.models.templates.Template)4 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)3 DateTime (org.joda.time.DateTime)3 CacheKey (org.sagebionetworks.bridge.cache.CacheKey)3 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)3 IntentToParticipate (org.sagebionetworks.bridge.models.itp.IntentToParticipate)3 PublishRequest (com.amazonaws.services.sns.model.PublishRequest)2 URL (java.net.URL)2 MimeBodyPart (javax.mail.internet.MimeBodyPart)2 BridgeServiceException (org.sagebionetworks.bridge.exceptions.BridgeServiceException)2 CreatedOnHolder (org.sagebionetworks.bridge.models.CreatedOnHolder)2 Criteria (org.sagebionetworks.bridge.models.Criteria)2 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)2