-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 #21817 from Sgitario/reactive_beanparam_classcast
Provide contextual error message for incorrect use of @BeanParam
- Loading branch information
Showing
6 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
.../resteasy/reactive/server/test/beanparam/FailWithAnnotationsInAMethodOfBeanParamTest.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,54 @@ | ||
package io.quarkus.resteasy.reactive.server.test.beanparam; | ||
|
||
import javax.enterprise.inject.spi.DeploymentException; | ||
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.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FailWithAnnotationsInAMethodOfBeanParamTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setExpectedException(DeploymentException.class) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(GreetingResource.class, NoQueryParamsInFieldsNameData.class)); | ||
|
||
@Test | ||
void shouldBeanParamWorkWithoutFieldsAnnotatedWithQueryParam() { | ||
Assertions.fail("The test case should not be invoked as it should fail with a deployment exception."); | ||
} | ||
|
||
@Path("/greeting") | ||
public static class GreetingResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello(@BeanParam NoQueryParamsInFieldsNameData request) { | ||
return "Hello, " + request.getName(); | ||
} | ||
} | ||
|
||
public static class NoQueryParamsInFieldsNameData { | ||
private String name; | ||
|
||
@QueryParam("name") | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...quarkus/resteasy/reactive/server/test/beanparam/FailWithNoAnnotationsInBeanParamTest.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,52 @@ | ||
package io.quarkus.resteasy.reactive.server.test.beanparam; | ||
|
||
import javax.enterprise.inject.spi.DeploymentException; | ||
import javax.ws.rs.BeanParam; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FailWithNoAnnotationsInBeanParamTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setExpectedException(DeploymentException.class) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(GreetingResource.class, NoQueryParamsInFieldsNameData.class)); | ||
|
||
@Test | ||
void shouldBeanParamWorkWithoutFieldsAnnotatedWithQueryParam() { | ||
Assertions.fail("The test case should not be invoked as it should fail with a deployment exception."); | ||
} | ||
|
||
@Path("/greeting") | ||
public static class GreetingResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello(@BeanParam NoQueryParamsInFieldsNameData request) { | ||
return "Hello, " + request.getName(); | ||
} | ||
} | ||
|
||
public static class NoQueryParamsInFieldsNameData { | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |
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