Search in sources :

Example 1 with UploadRequest

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UploadRequest(org.sagebionetworks.bridge.models.upload.UploadRequest) Test(org.testng.annotations.Test)

Example 2 with 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);
}
Also used : UploadDedupeDao(org.sagebionetworks.bridge.dao.UploadDedupeDao) AmazonS3(com.amazonaws.services.s3.AmazonS3) GeneratePresignedUrlRequest(com.amazonaws.services.s3.model.GeneratePresignedUrlRequest) UploadRequest(org.sagebionetworks.bridge.models.upload.UploadRequest) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) BridgeConfig(org.sagebionetworks.bridge.config.BridgeConfig) UploadDao(org.sagebionetworks.bridge.dao.UploadDao) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with UploadRequest

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);
}
Also used : ConcurrentModificationException(org.sagebionetworks.bridge.exceptions.ConcurrentModificationException) UploadRequest(org.sagebionetworks.bridge.models.upload.UploadRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) Test(org.testng.annotations.Test)

Example 4 with UploadRequest

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);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) UploadRequest(org.sagebionetworks.bridge.models.upload.UploadRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) Test(org.testng.annotations.Test)

Example 5 with UploadRequest

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);
}
Also used : ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) UploadView(org.sagebionetworks.bridge.models.upload.UploadView) UploadRequest(org.sagebionetworks.bridge.models.upload.UploadRequest) Upload(org.sagebionetworks.bridge.models.upload.Upload) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

UploadRequest (org.sagebionetworks.bridge.models.upload.UploadRequest)19 Test (org.testng.annotations.Test)16 DynamoUpload2 (org.sagebionetworks.bridge.dynamodb.DynamoUpload2)12 Upload (org.sagebionetworks.bridge.models.upload.Upload)6 URL (java.net.URL)4 UploadSession (org.sagebionetworks.bridge.models.upload.UploadSession)4 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)3 GeneratePresignedUrlRequest (com.amazonaws.services.s3.model.GeneratePresignedUrlRequest)3 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 Date (java.util.Date)2 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)2 UploadView (org.sagebionetworks.bridge.models.upload.UploadView)2 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 DateTime (org.joda.time.DateTime)1 BridgeConfig (org.sagebionetworks.bridge.config.BridgeConfig)1 UploadDao (org.sagebionetworks.bridge.dao.UploadDao)1 UploadDedupeDao (org.sagebionetworks.bridge.dao.UploadDedupeDao)1