-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 (195): Continue developing base for proxy
- Loading branch information
Manuel Klaus
committed
Dec 16, 2024
1 parent
ebfbfe8
commit c0a3773
Showing
7 changed files
with
105 additions
and
9 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
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
83 changes: 83 additions & 0 deletions
83
backend/app.hopps.fin/src/test/java/app/hopps/fin/endpoint/DocumentResourceTest.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,83 @@ | ||
package app.hopps.fin.endpoint; | ||
|
||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.core.Response; | ||
import org.apache.commons.io.IOUtils; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.flywaydb.core.Flyway; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.awssdk.core.sync.RequestBody; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
|
||
import java.io.InputStream; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(DocumentResource.class) | ||
class DocumentResourceTest { | ||
@Inject | ||
Flyway flyway; | ||
|
||
@Inject | ||
S3Client s3Client; | ||
|
||
@ConfigProperty(name = "app.hopps.fin.bucket.name") | ||
String bucketName; | ||
|
||
@BeforeEach | ||
void setup() { | ||
flyway.clean(); | ||
flyway.migrate(); | ||
|
||
try (InputStream zugferdInputStream = getClass().getClassLoader().getResourceAsStream("ZUGFeRD.pdf")) { | ||
assert zugferdInputStream != null; | ||
byte[] byteArray = IOUtils.toByteArray(zugferdInputStream); | ||
|
||
s3Client.putObject(PutObjectRequest.builder() | ||
.key("imageKey") | ||
.bucket(bucketName) | ||
.build(), RequestBody.fromBytes(byteArray)); | ||
} catch (Exception ignored) { | ||
// Do nothing | ||
} | ||
} | ||
|
||
@Test | ||
void shouldNotGetFile() { | ||
given() | ||
.when() | ||
.get("{documentKey}", "randomKey") | ||
.then() | ||
.statusCode(Response.Status.NOT_FOUND.getStatusCode()); | ||
} | ||
|
||
@Test | ||
void shouldGetFile() { | ||
given() | ||
.when() | ||
.get("{documentKey}", "imageKey") | ||
.then() | ||
.statusCode(Response.Status.OK.getStatusCode()); | ||
} | ||
|
||
@Test | ||
@Disabled("ByteArrayInputStream serialization error") | ||
void shouldUploadFile() { | ||
InputStream zugferdInputStream = getClass().getClassLoader().getResourceAsStream("ZUGFeRD.pdf"); | ||
|
||
given() | ||
.when() | ||
.multiPart("file", zugferdInputStream) | ||
.multiPart("filename", "ZUGFeRD.pdf") | ||
.multiPart("mimetype", "application/pdf") | ||
.post() | ||
.then() | ||
.statusCode(Response.Status.ACCEPTED.getStatusCode()); | ||
} | ||
} |
Binary file not shown.