-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ALS-7539] Test file creation for uploader
- Loading branch information
Luke Sikina
committed
Nov 27, 2024
1 parent
3199846
commit c24a795
Showing
3 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/filesharing/TestDataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...test/java/edu/harvard/hms/dbmi/avillach/hpds/service/filesharing/TestDataServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |