Added testing stuff.
This commit is contained in:
parent
7d9c210278
commit
91648a13fa
|
@ -31,11 +31,25 @@
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>5.1.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>2.1.214</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -2,6 +2,8 @@ spring.datasource.username=gymboard-cdn-dev
|
||||||
spring.datasource.password=testpass
|
spring.datasource.password=testpass
|
||||||
spring.datasource.url=jdbc:postgresql://localhost:5433/gymboard-cdn-dev
|
spring.datasource.url=jdbc:postgresql://localhost:5433/gymboard-cdn-dev
|
||||||
|
|
||||||
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
|
|
||||||
server.port=8082
|
server.port=8082
|
||||||
|
|
||||||
app.web-origin=http://localhost:9000
|
app.web-origin=http://localhost:9000
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
spring.jpa.open-in-view=false
|
||||||
|
|
||||||
# TODO: Find a better way than dumping files into memory.
|
# TODO: Find a better way than dumping files into memory.
|
||||||
spring.servlet.multipart.enabled=true
|
spring.servlet.multipart.enabled=true
|
||||||
spring.servlet.multipart.max-file-size=1GB
|
spring.servlet.multipart.max-file-size=1GB
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package nl.andrewlalis.gymboardcdn.service;
|
||||||
|
|
||||||
|
import nl.andrewlalis.gymboardcdn.api.FileUploadResponse;
|
||||||
|
import nl.andrewlalis.gymboardcdn.model.StoredFileRepository;
|
||||||
|
import nl.andrewlalis.gymboardcdn.model.VideoProcessingTask;
|
||||||
|
import nl.andrewlalis.gymboardcdn.model.VideoProcessingTaskRepository;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.mockito.AdditionalAnswers.returnsFirstArg;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
public class UploadServiceTest {
|
||||||
|
@Test
|
||||||
|
public void processableVideoUploadSuccess() throws IOException {
|
||||||
|
StoredFileRepository storedFileRepository = Mockito.mock(StoredFileRepository.class);
|
||||||
|
VideoProcessingTaskRepository videoTaskRepository = Mockito.mock(VideoProcessingTaskRepository.class);
|
||||||
|
when(videoTaskRepository.save(any(VideoProcessingTask.class)))
|
||||||
|
.then(returnsFirstArg());
|
||||||
|
FileService fileService = Mockito.mock(FileService.class);
|
||||||
|
MultipartFile multipartFile = new MockMultipartFile(
|
||||||
|
"file",
|
||||||
|
"testing.mp4",
|
||||||
|
"video/mp4",
|
||||||
|
new byte[]{1, 2, 3}
|
||||||
|
);
|
||||||
|
when(fileService.saveToTempFile(any(MultipartFile.class)))
|
||||||
|
.thenReturn(Path.of("test-cdn-files", "tmp", "bleh.mp4"));
|
||||||
|
|
||||||
|
when(fileService.createNewFileIdentifier()).thenReturn("abc");
|
||||||
|
|
||||||
|
UploadService uploadService = new UploadService(
|
||||||
|
storedFileRepository,
|
||||||
|
videoTaskRepository,
|
||||||
|
fileService
|
||||||
|
);
|
||||||
|
var expectedResponse = new FileUploadResponse("abc");
|
||||||
|
var response = uploadService.processableVideoUpload(multipartFile);
|
||||||
|
assertEquals(expectedResponse, response);
|
||||||
|
verify(fileService, times(1)).saveToTempFile(multipartFile);
|
||||||
|
verify(videoTaskRepository, times(1)).save(any());
|
||||||
|
verify(fileService, times(1)).createNewFileIdentifier();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
|
||||||
|
spring.datasource.driver-class-name=org.h2.Driver
|
||||||
|
|
||||||
|
spring.jpa.open-in-view=false
|
||||||
|
|
||||||
|
spring.servlet.multipart.enabled=true
|
||||||
|
spring.servlet.multipart.max-file-size=1GB
|
||||||
|
spring.servlet.multipart.max-request-size=2GB
|
||||||
|
|
||||||
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
|
|
||||||
|
server.port=8082
|
||||||
|
|
||||||
|
app.web-origin=http://localhost:9000
|
||||||
|
app.files.storage-dir=./test-cdn-files/
|
||||||
|
app.files.temp-dir=./test-cdn-files/tmp/
|
Binary file not shown.
Loading…
Reference in New Issue