-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Kasean/1-uploading-files-to-core-back-end…
…-module 1 uploading files to core back end module
- Loading branch information
Showing
11 changed files
with
92 additions
and
25 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
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
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
org.apache.kafka.common.network.InvalidReceiveException: Invalid receive (size = 1195725856 larger than 104857600) | ||
org.apache.kafka.common.network.InvalidReceiveException: Invalid receive (size = 1195725856 larger than 104857600) | ||
|
||
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test | ||
|
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
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
26 changes: 26 additions & 0 deletions
26
core-back-end/src/main/java/org/student/api/FilesController.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,26 @@ | ||
package org.student.api; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.codec.multipart.FilePart; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequestMapping("api/v1/files") | ||
public class FilesController { | ||
|
||
private static final Logger logger = LogManager.getLogger(FilesController.class); | ||
|
||
@PostMapping("/upload") | ||
public Mono<String> uploadFile(@RequestPart("file") Mono<FilePart> filePartMono) { | ||
return filePartMono.doOnNext(fp -> logger.info("Received file: " + fp.filename())). | ||
then(Mono.just("File uploaded successfully.")); | ||
} | ||
|
||
} |
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
37 changes: 37 additions & 0 deletions
37
core-back-end/src/test/java/org/student/api/FilesControllerTest.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,37 @@ | ||
package org.student.api; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.MultipartBodyBuilder; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import org.springframework.web.reactive.function.BodyInserters; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@WebFluxTest(FilesController.class) | ||
public class FilesControllerTest { | ||
|
||
@Autowired | ||
private WebTestClient webTestClient; | ||
|
||
@Test | ||
@WithMockUser(username = "user") | ||
public void testFileUploading(){ | ||
ClassPathResource resource = new ClassPathResource("testFile.csv"); | ||
MultipartBodyBuilder builder = new MultipartBodyBuilder(); | ||
builder.part("file", resource); | ||
|
||
webTestClient.mutateWith(SecurityMockServerConfigurers.csrf()).post().uri("http://localhost:8888/api/v1/files/upload") | ||
.contentType(MediaType.MULTIPART_FORM_DATA) | ||
.body(BodyInserters.fromMultipartData(builder.build())) | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBody(String.class).isEqualTo("File uploaded successfully."); | ||
} | ||
} |
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,2 @@ | ||
server: | ||
port: 8888 |
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 @@ | ||
"test,test" |