Skip to content

Commit

Permalink
Split PartFilenameTest into classic and reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
patr1kt0th committed Aug 29, 2023
1 parent 9e55e3c commit c5b53b1
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
8 changes: 8 additions & 0 deletions integration-tests/part-filename/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-common</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import org.acme.openapi.api.PartFilenameValueSuffixApi;
import org.jboss.resteasy.annotations.providers.multipart.PartFilename;
import org.jboss.resteasy.annotations.providers.multipart.PartType;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class PartFilenameTest {
@Tag("resteasy-classic")
class PartFilenameRestEasyClassicTest {

private static final String PROFILE_IMAGE = "profileImage";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package io.quarkiverse.openapi.generator.it;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.lang.reflect.Field;

import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.core.MediaType;

import org.acme.openapi.api.DoNotGeneratePartFilenameApi;
import org.acme.openapi.api.GeneratePartFilenameApi;
import org.acme.openapi.api.GlobalGeneratePartFilenameApi;
import org.acme.openapi.api.PartFilenameValueApi;
import org.acme.openapi.api.PartFilenameValueSuffixApi;
import org.jboss.resteasy.reactive.PartFilename;
import org.jboss.resteasy.reactive.PartType;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@Tag("resteasy-reactive")
class PartFilenameRestEasyReactiveTest {

private static final String PROFILE_IMAGE = "profileImage";

private Field getProfileImageField(Class<?> clazz) throws NoSuchFieldException {
return clazz.getField(PROFILE_IMAGE);
}

private void testOtherAnnotations(Field field) {
var formParam = field.getAnnotation(FormParam.class);
assertNotNull(formParam);
assertEquals(PROFILE_IMAGE, formParam.value());

var partType = field.getAnnotation(PartType.class);
assertNotNull(partType);
assertEquals(MediaType.APPLICATION_OCTET_STREAM, partType.value());
}

@Test
void testGlobalGeneratePartFilename() throws NoSuchFieldException {
var field = getProfileImageField(
GlobalGeneratePartFilenameApi.PostUserProfileDataMultipartForm.class);

this.testOtherAnnotations(field);

var partFilename = field.getAnnotation(PartFilename.class);
assertNull(partFilename);
}

@Test
void testGeneratePartFilename() throws NoSuchFieldException {
var field = getProfileImageField(
GeneratePartFilenameApi.PostUserProfileDataMultipartForm.class);

this.testOtherAnnotations(field);

var partFilename = field.getAnnotation(PartFilename.class);
assertNotNull(partFilename);
assertEquals(PROFILE_IMAGE + "File", partFilename.value());
}

@Test
void testDoNotGeneratePartFilename() throws NoSuchFieldException {
var field = getProfileImageField(
DoNotGeneratePartFilenameApi.PostUserProfileDataMultipartForm.class);

this.testOtherAnnotations(field);

var partFilename = field.getAnnotation(PartFilename.class);
assertNull(partFilename);
}

@Test
void testPartFilenameValue() throws NoSuchFieldException {
var field = getProfileImageField(
PartFilenameValueApi.PostUserProfileDataMultipartForm.class);

this.testOtherAnnotations(field);

var partFilename = field.getAnnotation(PartFilename.class);
assertNotNull(partFilename);
assertEquals("test.pdf", partFilename.value());
}

@Test
void testPartFilenameValueSuffix() throws NoSuchFieldException {
var field = getProfileImageField(
PartFilenameValueSuffixApi.PostUserProfileDataMultipartForm.class);

this.testOtherAnnotations(field);

var partFilename = field.getAnnotation(PartFilename.class);
assertNotNull(partFilename);
assertEquals(PROFILE_IMAGE + ".pdf", partFilename.value());
}
}

0 comments on commit c5b53b1

Please sign in to comment.