Skip to content

Commit

Permalink
[ALS-7539] Test file creation for uploader
Browse files Browse the repository at this point in the history
(cherry picked from commit 6035482)
  • Loading branch information
Luke Sikina authored and ramari16 committed Dec 20, 2024
1 parent 94e7603 commit a11c03a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import edu.harvard.hms.dbmi.avillach.hpds.data.query.ResultType;
import edu.harvard.hms.dbmi.avillach.hpds.processing.upload.SignUrlService;
import edu.harvard.hms.dbmi.avillach.hpds.service.filesharing.FileSharingService;
import edu.harvard.hms.dbmi.avillach.hpds.service.filesharing.TestDataService;
import edu.harvard.hms.dbmi.avillach.hpds.service.util.Paginator;
import edu.harvard.hms.dbmi.avillach.hpds.service.util.QueryDecorator;
import org.apache.http.entity.ContentType;
Expand Down Expand Up @@ -48,7 +49,8 @@ public class PicSureService {
@Autowired
public PicSureService(QueryService queryService, TimelineProcessor timelineProcessor, CountProcessor countProcessor,
VariantListProcessor variantListProcessor, AbstractProcessor abstractProcessor, Paginator paginator,
SignUrlService signUrlService, FileSharingService fileSystemService, QueryDecorator queryDecorator
SignUrlService signUrlService, FileSharingService fileSystemService, QueryDecorator queryDecorator,
TestDataService testDataService
) {
this.queryService = queryService;
this.timelineProcessor = timelineProcessor;
Expand All @@ -60,6 +62,8 @@ public PicSureService(QueryService queryService, TimelineProcessor timelineProce
this.queryDecorator = queryDecorator;
this.signUrlService = signUrlService;
Crypto.loadDefaultKey();
this.testDataService = testDataService;
Crypto.loadDefaultKey();
}

private final QueryService queryService;
Expand All @@ -84,6 +88,8 @@ public PicSureService(QueryService queryService, TimelineProcessor timelineProce

private final QueryDecorator queryDecorator;

private final TestDataService testDataService;

private static final String QUERY_METADATA_FIELD = "queryMetadata";
private static final int RESPONSE_CACHE_SIZE = 50;

Expand Down Expand Up @@ -252,6 +258,10 @@ private Optional<String> roundTripUUID(String uuid) {
public ResponseEntity writeQueryResult(
@RequestBody() Query query, @PathVariable("dataType") String datatype
) {
if ("test_upload".equals(datatype)) {
return testDataService.uploadTestFile(query.getPicSureId()) ?
ResponseEntity.ok().build() : ResponseEntity.status(500).build();
}
if (roundTripUUID(query.getPicSureId()).map(id -> !id.equalsIgnoreCase(query.getPicSureId())).orElse(false)) {
return ResponseEntity
.status(400)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.harvard.hms.dbmi.avillach.hpds.service.filesharing;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
* Writes test data to the directory shared with the uploader to test
* uploading features
*/
@Service
public class TestDataService {

private static final Logger LOG = LoggerFactory.getLogger(TestDataService.class);

private final FileSystemService fileSystemService;

@Autowired
public TestDataService(FileSystemService fileSystemService) {
this.fileSystemService = fileSystemService;
}

public boolean uploadTestFile(String uuid) {
LOG.info("Writing test file for uuid {}", uuid);
return fileSystemService.writeResultToFile(
"test_data.txt",
"This is a disposable test file",
uuid
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.harvard.hms.dbmi.avillach.hpds.service.filesharing;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertTrue;


public class TestDataServiceTest {
FileSystemService fileSystemService;

TestDataService subject;

@Test
public void shouldCreateTestFileForUpload() {
fileSystemService = Mockito.mock(FileSystemService.class);
subject = new TestDataService(fileSystemService);

String uuid = UUID.randomUUID().toString();
Mockito.when(fileSystemService.writeResultToFile("test_data.txt", "This is a disposable test file", uuid.toString()))
.thenReturn(true);

boolean success = subject.uploadTestFile(uuid);
assertTrue(success);
Mockito.verify(fileSystemService, Mockito.times(1))
.writeResultToFile("test_data.txt", "This is a disposable test file", uuid.toString());
}
}

0 comments on commit a11c03a

Please sign in to comment.