use of org.sagebionetworks.bridge.config.BridgeConfig in project BridgeServer2 by Sage-Bionetworks.
the class UploadServiceCreateUploadTest method dupeWhitelisted.
@Test
public void dupeWhitelisted() {
// If the current app is whitelisted for dupes, then all 3 cases (not dupe, incomplete dupe, complete dupe)
// look exactly the same. We have no way of knowing whether something is a dupe or not, because we never look.
// mock config with dupe app whitelist
BridgeConfig mockConfig = mock(BridgeConfig.class);
when(mockConfig.getProperty(UploadService.CONFIG_KEY_UPLOAD_BUCKET)).thenReturn(TEST_BUCKET);
svc.setConfig(mockConfig);
// mock upload DAO
when(mockUploadDao.createUpload(uploadRequest, API_APP_ID, TEST_HEALTH_CODE, null)).thenReturn(TEST_UPLOAD);
testUpload(API_APP_ID, TEST_UPLOAD_ID);
// verify we created and registered the dupe; verify we never queried for dupes
verify(mockUploadDedupeDao, never()).getDuplicate(any(), any(), any());
verify(mockUploadDao).createUpload(uploadRequest, API_APP_ID, TEST_HEALTH_CODE, null);
verify(mockUploadDedupeDao).registerUpload(TEST_HEALTH_CODE, TEST_UPLOAD_MD5, TEST_UPLOAD_REQUESTED_ON, TEST_UPLOAD_ID);
}
use of org.sagebionetworks.bridge.config.BridgeConfig in project BridgeServer2 by Sage-Bionetworks.
the class UploadServiceCreateUploadTest method setup.
@BeforeMethod
public void setup() throws Exception {
// mock now
DateTimeUtils.setCurrentMillisFixed(TEST_UPLOAD_REQUESTED_ON.getMillis());
// make test request
uploadRequest = BridgeObjectMapper.get().readValue(TEST_UPLOAD_REQUEST_JSON, UploadRequest.class);
// mock config
BridgeConfig mockConfig = mock(BridgeConfig.class);
when(mockConfig.getProperty(UploadService.CONFIG_KEY_UPLOAD_BUCKET)).thenReturn(TEST_BUCKET);
// mock upload DAOs. (The tests will mock the calls, since they vary with each test.)
mockUploadDao = mock(UploadDao.class);
mockUploadDedupeDao = mock(UploadDedupeDao.class);
// mock upload credentials service
AWSSessionCredentials mockCredentials = mock(AWSSessionCredentials.class);
UploadSessionCredentialsService mockCredentialsSvc = mock(UploadSessionCredentialsService.class);
when(mockCredentialsSvc.getSessionCredentials()).thenReturn(mockCredentials);
// mock presigned URL call
presignedUrlRequestArgumentCaptor = ArgumentCaptor.forClass(GeneratePresignedUrlRequest.class);
AmazonS3 mockS3UploadClient = mock(AmazonS3.class);
when(mockS3UploadClient.generatePresignedUrl(presignedUrlRequestArgumentCaptor.capture())).thenReturn(new URL(TEST_PRESIGNED_URL));
// set up service
svc = new UploadService();
svc.setConfig(mockConfig);
svc.setUploadDao(mockUploadDao);
svc.setUploadDedupeDao(mockUploadDedupeDao);
svc.setUploadSessionCredentialsService(mockCredentialsSvc);
svc.setS3UploadClient(mockS3UploadClient);
}
use of org.sagebionetworks.bridge.config.BridgeConfig in project BridgeServer2 by Sage-Bionetworks.
the class UserDataDownloadViaSqsServiceTest method test.
@Test
public void test() throws Exception {
// main test strategy is to validate that the args get transformed and sent to SQS as expected
// mock config
BridgeConfig mockConfig = mock(BridgeConfig.class);
when(mockConfig.getProperty(CONFIG_KEY_UDD_SQS_QUEUE_URL)).thenReturn(SQS_URL);
// mock SQS
AmazonSQSClient mockSqsClient = mock(AmazonSQSClient.class);
SendMessageResult mockSqsResult = new SendMessageResult().withMessageId(SQS_MESSAGE_ID);
ArgumentCaptor<String> sqsMessageCaptor = ArgumentCaptor.forClass(String.class);
when(mockSqsClient.sendMessage(eq(SQS_URL), sqsMessageCaptor.capture())).thenReturn(mockSqsResult);
// set up test service
UserDataDownloadViaSqsService testService = new UserDataDownloadViaSqsService();
testService.setBridgeConfig(mockConfig);
testService.setSqsClient(mockSqsClient);
// test inputs
DateRange dateRange = new DateRange(LocalDate.parse(START_DATE), LocalDate.parse(END_DATE));
// execute
testService.requestUserData(TEST_APP_ID, USER_ID, dateRange);
// Validate SQS args.
String sqsMessageText = sqsMessageCaptor.getValue();
JsonNode sqsMessageNode = JSON_OBJECT_MAPPER.readTree(sqsMessageText);
// first assert parent node
assertEquals(sqsMessageNode.size(), 2);
assertEquals(sqsMessageNode.get(REQUEST_KEY_SERVICE).asText(), UDD_SERVICE_TITLE);
// then assert body node
JsonNode msgBody = sqsMessageNode.path(REQUEST_KEY_BODY);
assertEquals(msgBody.size(), 5);
assertEquals(msgBody.get(REQUEST_KEY_STUDY_ID).textValue(), TEST_APP_ID);
assertEquals(msgBody.get(REQUEST_KEY_APP_ID).textValue(), TEST_APP_ID);
assertEquals(msgBody.get(REQUEST_KEY_USER_ID).textValue(), USER_ID);
assertEquals(msgBody.get(REQUEST_KEY_START_DATE).textValue(), START_DATE);
assertEquals(msgBody.get(REQUEST_KEY_END_DATE).textValue(), END_DATE);
}
use of org.sagebionetworks.bridge.config.BridgeConfig in project BridgeServer2 by Sage-Bionetworks.
the class ExportViaSqsServiceTest method test.
@Test
public void test() throws Exception {
// mock config
BridgeConfig mockConfig = mock(BridgeConfig.class);
when(mockConfig.getProperty(ExportViaSqsService.CONFIG_KEY_EXPORTER_SQS_QUEUE_URL)).thenReturn(SQS_URL);
// mock SQS
AmazonSQSClient mockSqsClient = mock(AmazonSQSClient.class);
SendMessageResult mockSqsResult = new SendMessageResult().withMessageId(SQS_MESSAGE_ID);
ArgumentCaptor<String> sqsMessageCaptor = ArgumentCaptor.forClass(String.class);
when(mockSqsClient.sendMessage(eq(SQS_URL), sqsMessageCaptor.capture())).thenReturn(mockSqsResult);
// set up test service
ExportViaSqsService service = new ExportViaSqsService();
service.setBridgeConfig(mockConfig);
service.setSqsClient(mockSqsClient);
// execute and validate
service.startOnDemandExport(TEST_APP_ID);
String sqsMessageText = sqsMessageCaptor.getValue();
JsonNode sqsMessageNode = JSON_OBJECT_MAPPER.readTree(sqsMessageText);
assertEquals(sqsMessageNode.size(), 5);
assertEquals(sqsMessageNode.get(ExportViaSqsService.REQUEST_KEY_END_DATE_TIME).textValue(), EXPECTED_END_DATE_TIME_STRING);
assertEquals(sqsMessageNode.get(ExportViaSqsService.REQUEST_KEY_TAG).textValue(), "On-Demand Export appId=" + TEST_APP_ID + " endDateTime=" + EXPECTED_END_DATE_TIME_STRING);
assertTrue(sqsMessageNode.get(ExportViaSqsService.REQUEST_KEY_USE_LAST_EXPORT_TIME).booleanValue());
JsonNode appWhitelistNode = sqsMessageNode.get(ExportViaSqsService.REQUEST_KEY_APP_WHITELIST);
assertEquals(appWhitelistNode.size(), 1);
assertEquals(appWhitelistNode.get(0).textValue(), TEST_APP_ID);
JsonNode studyWhitelistNode = sqsMessageNode.get(ExportViaSqsService.REQUEST_KEY_STUDY_WHITELIST);
assertEquals(studyWhitelistNode.size(), 1);
assertEquals(studyWhitelistNode.get(0).textValue(), TEST_APP_ID);
}
use of org.sagebionetworks.bridge.config.BridgeConfig in project BridgeServer2 by Sage-Bionetworks.
the class EmailVerificationServiceAsyncHandlerTest method setup.
@BeforeMethod
public void setup() {
// Mock config.
BridgeConfig mockConfig = mock(BridgeConfig.class);
when(mockConfig.getProperty(EmailVerificationService.CONFIG_KEY_NOTIFICATION_TOPIC_ARN)).thenReturn(DUMMY_NOTIFICATION_ARN);
// Mock SES Client. Each call should fail once, then succeed. (Get notification topic call will be mocked
// individually in tests, since the result varies from test to test.)
mockSesClient = mock(AmazonSimpleEmailServiceClient.class);
when(mockSesClient.verifyEmailIdentity(any())).thenThrow(makeAwsInternalError()).thenReturn(new VerifyEmailIdentityResult());
// Set Notifications has to use an Answer because there are actually two different types of calls here.
numSetBounceNotificationCalls = 0;
numSetComplaintNotificationCalls = 0;
when(mockSesClient.setIdentityNotificationTopic(any())).thenAnswer(invocation -> {
SetIdentityNotificationTopicRequest request = invocation.getArgument(0);
boolean shouldThrow = false;
switch(request.getNotificationType()) {
case "Bounce":
{
numSetBounceNotificationCalls++;
shouldThrow = numSetBounceNotificationCalls < 2;
break;
}
case "Complaint":
{
numSetComplaintNotificationCalls++;
shouldThrow = numSetComplaintNotificationCalls < 2;
break;
}
default:
{
fail("Unexpected code path");
}
}
if (shouldThrow) {
throw makeAwsInternalError();
} else {
return new SetIdentityNotificationTopicResult();
}
});
// Set up service.
EmailVerificationService service = new EmailVerificationService();
service.setAmazonSimpleEmailServiceClient(mockSesClient);
service.setConfig(mockConfig);
// For testing purposes, set to 2 tries and a large rate limit.
service.setMaxSesTries(2);
service.setSesRateLimit(1000.0);
// Set up handler.
asyncHandler = service.new AsyncSnsTopicHandler(EMAIL_ADDRESS);
}
Aggregations