Skip to content

Commit

Permalink
Merge pull request #27592 from Sgitario/rr_beanparam_27501
Browse files Browse the repository at this point in the history
Resteasy Reactive: Fix nested bean params for sub resources
  • Loading branch information
geoand committed Aug 30, 2022
2 parents 0283b7d + 881c4fe commit 51e27e8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
@@ -0,0 +1,71 @@
package io.quarkus.resteasy.reactive.server.test.beanparam;

import static org.hamcrest.CoreMatchers.equalTo;

import javax.ws.rs.BeanParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

/**
* Related to the issue: https://github.com/quarkusio/quarkus/issues/27501
*/
public class NestedBeanParamInSubResourcesTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(TestResource.class, SearchResource.class, City.class, Country.class));

@Test
void shouldParseNestedBeanParams() {
RestAssured.get("/test/city/search?name=Malaga&country=Spain")
.then()
.statusCode(200)
.body(equalTo("Got: Malaga, Spain"));
}

@Path("/test")
public static class TestResource {

@Path("/city")
public SearchResource searchCities() {
return new SearchResource();
}

}

public static class SearchResource {

@GET
@Path("/search")
@Produces(MediaType.TEXT_PLAIN)
public String search(@BeanParam City city) {
return "Got: " + city.name + ", " + city.country.country;
}
}

public static class City {

@QueryParam("name")
String name;

@BeanParam
Country country;
}

public static class Country {
@QueryParam("country")
String country;
}
}
Expand Up @@ -350,6 +350,7 @@ public static ResourceScanningResult scanResources(
Set<String> beanParams = new HashSet<>();

Set<ClassInfo> beanParamAsBeanUsers = new HashSet<>(scannedResources.values());
beanParamAsBeanUsers.addAll(possibleSubResources.values());

Collection<AnnotationInstance> unregisteredBeanParamAnnotations = new ArrayList<>(
index.getAnnotations(ResteasyReactiveDotNames.BEAN_PARAM));
Expand Down

0 comments on commit 51e27e8

Please sign in to comment.