Skip to content

Commit

Permalink
[ALS-7539] Test file creation for uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina authored and Luke-Sikina committed Nov 28, 2024
1 parent 3199846 commit 6035482
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import edu.harvard.hms.dbmi.avillach.hpds.data.query.ResultType;
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 @@ -45,9 +46,9 @@ public class PicSureService implements IResourceRS {

@Autowired
public PicSureService(QueryService queryService, TimelineProcessor timelineProcessor, CountProcessor countProcessor,
VariantListProcessor variantListProcessor, AbstractProcessor abstractProcessor,
Paginator paginator, FileSharingService fileSystemService, QueryDecorator queryDecorator
) {
VariantListProcessor variantListProcessor, AbstractProcessor abstractProcessor,
Paginator paginator, FileSharingService fileSystemService, QueryDecorator queryDecorator, TestDataService testDataService
) {
this.queryService = queryService;
this.timelineProcessor = timelineProcessor;
this.countProcessor = countProcessor;
Expand All @@ -56,7 +57,8 @@ public PicSureService(QueryService queryService, TimelineProcessor timelineProce
this.paginator = paginator;
this.fileSystemService = fileSystemService;
this.queryDecorator = queryDecorator;
Crypto.loadDefaultKey();
this.testDataService = testDataService;
Crypto.loadDefaultKey();
}

private final QueryService queryService;
Expand All @@ -79,6 +81,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 @@ -275,6 +279,10 @@ private Optional<String> roundTripUUID(String uuid) {
public Response writeQueryResult(
@RequestBody() Query query, @PathParam("dataType") String datatype
) {
if ("test_upload".equals(datatype)) {
return testDataService.uploadTestFile(query.getPicSureId()) ?
Response.ok().build() : Response.status(500).build();
}
if (roundTripUUID(query.getPicSureId()).map(id -> !id.equalsIgnoreCase(query.getPicSureId())).orElse(false)) {
return Response
.status(400, "The query pic-sure ID is not a UUID")
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,32 @@
package edu.harvard.hms.dbmi.avillach.hpds.service.filesharing;

import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.util.UUID;

import static org.junit.Assert.*;


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 6035482

Please sign in to comment.