use of org.sagebionetworks.bridge.models.upload.UploadRequest in project BridgeServer2 by Sage-Bionetworks.
the class UploadValidatorTest method withOptionalParams.
@Test
public void withOptionalParams() throws Exception {
ObjectNode metadata = (ObjectNode) BridgeObjectMapper.get().readTree("{\"key\":\"value\"}");
UploadRequest uploadRequest = makeValidUploadRequestBuilder().withMetadata(metadata).build();
Validate.entityThrowingException(UploadValidator.INSTANCE, uploadRequest);
}
use of org.sagebionetworks.bridge.models.upload.UploadRequest 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.models.upload.UploadRequest in project BridgeServer2 by Sage-Bionetworks.
the class UploadServiceTest method uploadCompleteConcurrentModificationException.
@Test
public void uploadCompleteConcurrentModificationException() throws Exception {
UploadRequest uploadRequest = constructUploadRequest();
DynamoUpload2 upload = new DynamoUpload2(uploadRequest, HEALTH_CODE);
upload.setUploadId(ORIGINAL_UPLOAD_ID);
upload.setRecordId(RECORD_ID);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setSSEAlgorithm(AES_256_SERVER_SIDE_ENCRYPTION);
when(mockS3Client.getObjectMetadata(UPLOAD_BUCKET_NAME, ORIGINAL_UPLOAD_ID)).thenReturn(metadata);
doThrow(new ConcurrentModificationException("error")).when(mockUploadDao).uploadComplete(S3_WORKER, upload);
svc.uploadComplete(TEST_APP_ID, S3_WORKER, upload, true);
verify(mockUploadDao).uploadComplete(S3_WORKER, upload);
verify(mockUploadValidationService, never()).validateUpload(TEST_APP_ID, upload);
}
use of org.sagebionetworks.bridge.models.upload.UploadRequest in project BridgeServer2 by Sage-Bionetworks.
the class UploadServiceTest method uploadComplete.
@Test
public void uploadComplete() throws Exception {
App app = App.create();
app.setExporter3Enabled(false);
when(mockAppService.getApp(TEST_APP_ID)).thenReturn(app);
UploadRequest uploadRequest = constructUploadRequest();
DynamoUpload2 upload = new DynamoUpload2(uploadRequest, HEALTH_CODE);
upload.setUploadId(ORIGINAL_UPLOAD_ID);
upload.setRecordId(RECORD_ID);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setSSEAlgorithm(AES_256_SERVER_SIDE_ENCRYPTION);
when(mockS3Client.getObjectMetadata(UPLOAD_BUCKET_NAME, ORIGINAL_UPLOAD_ID)).thenReturn(metadata);
svc.uploadComplete(TEST_APP_ID, S3_WORKER, upload, true);
verify(mockUploadDao).uploadComplete(S3_WORKER, upload);
verify(mockUploadValidationService).validateUpload(TEST_APP_ID, upload);
}
use of org.sagebionetworks.bridge.models.upload.UploadRequest in project BridgeServer2 by Sage-Bionetworks.
the class UploadServiceTest method getUploads.
@Test
public void getUploads() throws Exception {
UploadRequest uploadRequest = constructUploadRequest();
Upload upload = new DynamoUpload2(uploadRequest, HEALTH_CODE);
upload.setUploadId(ORIGINAL_UPLOAD_ID);
DateTime startTime = TIMESTAMP.minusDays(7);
DateTime endTime = TIMESTAMP;
ForwardCursorPagedResourceList<Upload> uploads = new ForwardCursorPagedResourceList<>(ImmutableList.of(upload), null);
when(mockUploadDao.getUploads(HEALTH_CODE, startTime, endTime, 40, "offsetKey")).thenReturn(uploads);
ForwardCursorPagedResourceList<UploadView> result = svc.getUploads(HEALTH_CODE, startTime, endTime, 40, "offsetKey");
assertEquals(result.getItems().get(0).getUpload(), upload);
}
Aggregations