Search in sources :

Example 1 with DynamoApp

use of org.sagebionetworks.bridge.dynamodb.DynamoApp in project BridgeServer2 by Sage-Bionetworks.

the class TestUtils method getValidApp.

public static DynamoApp getValidApp(Class<?> clazz) {
    String id = TestUtils.randomName(clazz);
    Map<String, String> pushNotificationARNs = Maps.newHashMap();
    pushNotificationARNs.put(OperatingSystem.IOS, "arn:ios:" + id);
    pushNotificationARNs.put(OperatingSystem.ANDROID, "arn:android:" + id);
    // This app will save without further modification.
    DynamoApp app = new DynamoApp();
    app.setName("Test App [" + clazz.getSimpleName() + "]");
    app.setShortName("ShortName");
    app.setAutoVerificationEmailSuppressed(true);
    app.setPasswordPolicy(PasswordPolicy.DEFAULT_PASSWORD_POLICY);
    app.setAppIdExcludedInExport(true);
    app.setIdentifier(id);
    app.setMinAgeOfConsent(18);
    app.setSponsorName("The Council on Test Studies");
    app.setConsentNotificationEmail("bridge-testing+consent@sagebase.org");
    app.setConsentNotificationEmailVerified(true);
    app.setSynapseDataAccessTeamId(1234L);
    app.setSynapseProjectId("test-synapse-project-id");
    app.setTechnicalEmail("bridge-testing+technical@sagebase.org");
    app.setUploadValidationStrictness(UploadValidationStrictness.REPORT);
    app.setUsesCustomExportSchedule(true);
    app.setSupportEmail("bridge-testing+support@sagebase.org");
    app.setUserProfileAttributes(Sets.newHashSet("a", "b"));
    app.setTaskIdentifiers(Sets.newHashSet("task1", "task2"));
    app.setActivityEventKeys(Sets.newHashSet("event1", "event2"));
    app.setDataGroups(Sets.newHashSet("beta_users", "production_users"));
    app.setStrictUploadValidationEnabled(true);
    app.setHealthCodeExportEnabled(true);
    app.setEmailVerificationEnabled(true);
    app.setReauthenticationEnabled(true);
    app.setEmailSignInEnabled(true);
    app.setPhoneSignInEnabled(true);
    app.setVerifyChannelOnSignInEnabled(true);
    app.setExternalIdRequiredOnSignup(true);
    app.setActive(true);
    app.setDisableExport(false);
    app.setAccountLimit(0);
    app.setPushNotificationARNs(pushNotificationARNs);
    app.setAutoVerificationPhoneSuppressed(true);
    Map<String, String> defaultTemplates = new HashMap<>();
    for (TemplateType type : TemplateType.values()) {
        String typeName = type.name().toLowerCase();
        defaultTemplates.put(typeName, "ABC-DEF");
    }
    app.setDefaultTemplates(defaultTemplates);
    Exporter3Configuration exporter3Config = new Exporter3Configuration();
    exporter3Config.setDataAccessTeamId(1234L);
    exporter3Config.setParticipantVersionTableId("participant-version-synapse-table-id");
    exporter3Config.setProjectId("synapse-project-id");
    exporter3Config.setRawDataFolderId("synapse-folder-id");
    exporter3Config.setStorageLocationId(5678L);
    app.setExporter3Configuration(exporter3Config);
    return app;
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) HashMap(java.util.HashMap) TemplateType(org.sagebionetworks.bridge.models.templates.TemplateType) Exporter3Configuration(org.sagebionetworks.bridge.models.apps.Exporter3Configuration)

Example 2 with DynamoApp

use of org.sagebionetworks.bridge.dynamodb.DynamoApp in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantControllerTest method before.

@BeforeMethod
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    app = new DynamoApp();
    app.setUserProfileAttributes(Sets.newHashSet("foo", "baz"));
    app.setIdentifier(TEST_APP_ID);
    participant = new StudyParticipant.Builder().withRoles(CALLER_ROLES).withStudyIds(CALLER_STUDIES).withId(TEST_USER_ID).build();
    session = new UserSession(participant);
    session.setAuthenticated(true);
    session.setAppId(TEST_APP_ID);
    doAnswer((ans) -> {
        RequestContext.updateFromSession(session, mockSponsorService);
        return session;
    }).when(controller).getSessionIfItExists();
    when(mockAppService.getApp(TEST_APP_ID)).thenReturn(app);
    List<AccountSummary> summaries = ImmutableList.of(SUMMARY1, SUMMARY1, SUMMARY1);
    PagedResourceList<AccountSummary> page = new PagedResourceList<>(summaries, 30).withRequestParam("offsetBy", 10).withRequestParam("pageSize", 20).withRequestParam("startTime", START_TIME).withRequestParam("endTime", END_TIME).withRequestParam("emailFilter", "foo");
    when(mockParticipantService.getPagedAccountSummaries(eq(app), any())).thenReturn(page);
    SessionUpdateService sessionUpdateService = new SessionUpdateService();
    sessionUpdateService.setCacheProvider(mockCacheProvider);
    sessionUpdateService.setConsentService(mockConsentService);
    sessionUpdateService.setNotificationTopicService(mock(NotificationTopicService.class));
    controller.setSessionUpdateService(sessionUpdateService);
    doReturn(mockRequest).when(controller).request();
    doReturn(mockResponse).when(controller).response();
}
Also used : AccountSummary(org.sagebionetworks.bridge.models.accounts.AccountSummary) SessionUpdateService(org.sagebionetworks.bridge.services.SessionUpdateService) DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) NotificationTopicService(org.sagebionetworks.bridge.services.NotificationTopicService) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with DynamoApp

use of org.sagebionetworks.bridge.dynamodb.DynamoApp in project BridgeServer2 by Sage-Bionetworks.

the class SchedulePlanControllerTest method before.

@BeforeMethod
public void before() {
    MockitoAnnotations.initMocks(this);
    app = new DynamoApp();
    app.setIdentifier(TEST_APP_ID);
    when(mockAppService.getApp(app.getIdentifier())).thenReturn(app);
    when(mockAppService.getApp(app.getIdentifier())).thenReturn(app);
    when(mockUserSession.getAppId()).thenReturn(TEST_APP_ID);
    doReturn(mockUserSession).when(controller).getAuthenticatedSession(DEVELOPER);
    doReturn(mockUserSession).when(controller).getAuthenticatedSession(DEVELOPER, ADMIN);
    doReturn(mockRequest).when(controller).request();
    doReturn(mockResponse).when(controller).response();
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with DynamoApp

use of org.sagebionetworks.bridge.dynamodb.DynamoApp in project BridgeServer2 by Sage-Bionetworks.

the class BridgeExceptionHandlerTest method bridgeValidationExceptionCorrectlyReported.

@Test
public void bridgeValidationExceptionCorrectlyReported() throws Throwable {
    App app = new DynamoApp();
    try {
        Validate.entityThrowingException(new AppValidator(), app);
        fail("Should have thrown exception");
    } catch (InvalidEntityException e) {
        MethodInvocation invocation = mock(MethodInvocation.class);
        when(invocation.proceed()).thenThrow(e);
        ResponseEntity<String> response = handler.handleException(mockRequest, e);
        JsonNode node = new ObjectMapper().readTree(response.getBody());
        assertEquals(node.size(), 5);
        assertEquals(node.get("errors").get("identifier").get(0).textValue(), "identifier is required");
        assertEquals(node.get("type").textValue(), "InvalidEntityException");
        assertNotNull(node.get("entity"));
        assertNotNull(node.get("errors"));
        assertEquals(response.getStatusCodeValue(), 400);
        assertEquals(node.get("statusCode").intValue(), 400);
        // Verify log.
        verify(logger).info(contains(e.getMessage()));
    }
}
Also used : DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) App(org.sagebionetworks.bridge.models.apps.App) ResponseEntity(org.springframework.http.ResponseEntity) DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) AppValidator(org.sagebionetworks.bridge.validators.AppValidator) MethodInvocation(org.aopalliance.intercept.MethodInvocation) JsonNode(com.fasterxml.jackson.databind.JsonNode) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test) HttpUtilTest(org.sagebionetworks.bridge.spring.util.HttpUtilTest)

Example 5 with DynamoApp

use of org.sagebionetworks.bridge.dynamodb.DynamoApp in project BridgeServer2 by Sage-Bionetworks.

the class UserProfileControllerTest method before.

@BeforeMethod
public void before() {
    MockitoAnnotations.initMocks(this);
    app = new DynamoApp();
    app.setIdentifier(TEST_APP_ID);
    app.setDataGroups(USER_DATA_GROUPS);
    app.setUserProfileAttributes(TEST_STUDY_ATTRIBUTES);
    when(mockConsentService.getConsentStatuses(any())).thenReturn(CONSENT_STATUSES_MAP);
    when(mockAppService.getApp((String) any())).thenReturn(app);
    ViewCache viewCache = new ViewCache();
    viewCache.setCachePeriod(BRIDGE_VIEW_EXPIRE_IN_SECONDS);
    viewCache.setObjectMapper(BridgeObjectMapper.get());
    viewCache.setCacheProvider(mockCacheProvider);
    controller.setViewCache(viewCache);
    SessionUpdateService sessionUpdateService = new SessionUpdateService();
    sessionUpdateService.setCacheProvider(mockCacheProvider);
    sessionUpdateService.setConsentService(mockConsentService);
    sessionUpdateService.setNotificationTopicService(mockNotificationTopicService);
    controller.setSessionUpdateService(sessionUpdateService);
    session = new UserSession(new StudyParticipant.Builder().withHealthCode(HEALTH_CODE).withId(TEST_USER_ID).build());
    session.setAppId(TEST_APP_ID);
    doReturn(session).when(controller).getAuthenticatedSession();
    doReturn(mockRequest).when(controller).request();
    doReturn(mockResponse).when(controller).response();
}
Also used : ViewCache(org.sagebionetworks.bridge.cache.ViewCache) SessionUpdateService(org.sagebionetworks.bridge.services.SessionUpdateService) DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)24 BeforeMethod (org.testng.annotations.BeforeMethod)10 Test (org.testng.annotations.Test)9 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)6 App (org.sagebionetworks.bridge.models.apps.App)6 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)3 FileInputStream (java.io.FileInputStream)2 RequestContext (org.sagebionetworks.bridge.RequestContext)2 DynamoSchedulePlan (org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan)2 DynamoStudyConsent1 (org.sagebionetworks.bridge.dynamodb.DynamoStudyConsent1)2 DynamoSubpopulation (org.sagebionetworks.bridge.dynamodb.DynamoSubpopulation)2 ReportIndex (org.sagebionetworks.bridge.models.reports.ReportIndex)2 SchedulePlan (org.sagebionetworks.bridge.models.schedules.SchedulePlan)2 Study (org.sagebionetworks.bridge.models.studies.Study)2 StudyConsentView (org.sagebionetworks.bridge.models.subpopulations.StudyConsentView)2 Subpopulation (org.sagebionetworks.bridge.models.subpopulations.Subpopulation)2 SessionUpdateService (org.sagebionetworks.bridge.services.SessionUpdateService)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2