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;
}
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();
}
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();
}
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()));
}
}
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();
}
Aggregations