Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALS-7539] Test file creation for uploader #128

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}