Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RESTEASY-2064] Prepare test for yasson/issues/152 - setter with mult…
…iple arguments
- Loading branch information
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...st/java/org/jboss/resteasy/test/providers/jsonb/basic/SetMethodWithMoreArgumentsTest.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,74 @@ | ||
package org.jboss.resteasy.test.providers.jsonb.basic; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.logging.Logger; | ||
import org.jboss.resteasy.test.providers.jsonb.basic.resource.Dog; | ||
import org.jboss.resteasy.test.providers.jsonb.basic.resource.SetMethodWithMoreArgumentsResource; | ||
import org.jboss.resteasy.utils.PortProviderUtil; | ||
import org.jboss.resteasy.utils.TestUtil; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
/** | ||
* @tpSubChapter Json-binding provider | ||
* @tpChapter Integration test | ||
* @tpSince RESTEasy 3.6.2.Final | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class SetMethodWithMoreArgumentsTest { | ||
|
||
protected static final Logger LOG = Logger.getLogger(SetMethodWithMoreArgumentsTest.class.getName()); | ||
|
||
static Client client; | ||
|
||
private static final String DEFAULT = "war_default"; | ||
|
||
@Deployment(name = DEFAULT) | ||
public static Archive<?> deployDefault() { | ||
WebArchive war = TestUtil.prepareArchive(DEFAULT); | ||
war.addClass(Dog.class); | ||
return TestUtil.finishContainerPrepare(war, null, SetMethodWithMoreArgumentsResource.class); | ||
} | ||
|
||
|
||
@BeforeClass | ||
public static void init() { | ||
client = ClientBuilder.newClient(); | ||
} | ||
|
||
@AfterClass | ||
public static void after() throws Exception { | ||
client.close(); | ||
} | ||
|
||
/** | ||
* @tpTestDetails Entity class Dog has setNameAndSort method with two arguments which causes 'javax.json.bind.JsonbException: Invalid count of arguments for setter' with yasson-1.0.1. | ||
* This test checks that this behavior is no longer present in newer versions of yasson. | ||
* @tpSince RESTEasy 3.6.2.Final | ||
*/ | ||
@Test | ||
public void test() { | ||
WebTarget target = client.target(PortProviderUtil.generateURL("/dog", DEFAULT)); | ||
Entity<Dog> entity = Entity.entity( | ||
new Dog("Rex", "german shepherd"), MediaType.APPLICATION_JSON_TYPE.withCharset("UTF-8")); | ||
Dog dog = target.request().post(entity, Dog.class); | ||
LOG.info(dog); | ||
Assert.assertTrue(dog.getName().equals("Jethro")); | ||
Assert.assertTrue(dog.getSort().equals("stafford")); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...ation-tests/src/test/java/org/jboss/resteasy/test/providers/jsonb/basic/resource/Dog.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,50 @@ | ||
package org.jboss.resteasy.test.providers.jsonb.basic.resource; | ||
|
||
import javax.json.bind.annotation.JsonbPropertyOrder; | ||
|
||
/** | ||
* Created by tterem. | ||
*/ | ||
@JsonbPropertyOrder({"name", "sort"}) | ||
public class Dog { | ||
|
||
private String name; | ||
private String sort; | ||
|
||
public Dog() { | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Dog{" + | ||
"name='" + name + '\'' + | ||
", sort='" + sort + '\'' + | ||
'}'; | ||
} | ||
|
||
public Dog(final String name, final String sort) { | ||
this.name = name; | ||
this.sort = sort; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getSort() { | ||
return sort; | ||
} | ||
|
||
public void setSort(String sort) { | ||
this.sort = sort; | ||
} | ||
|
||
public void setNameAndSort(String name, String sort) { | ||
this.name = name; | ||
this.sort = sort; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...boss/resteasy/test/providers/jsonb/basic/resource/SetMethodWithMoreArgumentsResource.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,20 @@ | ||
package org.jboss.resteasy.test.providers.jsonb.basic.resource; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
|
||
@Path("/") | ||
public class SetMethodWithMoreArgumentsResource { | ||
|
||
@Path("/dog") | ||
@POST | ||
@Produces("application/json") | ||
@Consumes("application/json") | ||
public Dog getDog(Dog dog) throws Exception { | ||
dog.setNameAndSort("Jethro", "stafford"); | ||
return dog; | ||
} | ||
|
||
} |