Skip to content

Commit

Permalink
[RESTEASY-2064] Prepare test for yasson/issues/152 - setter with mult…
Browse files Browse the repository at this point in the history
…iple arguments
  • Loading branch information
Tomas Terem authored and asoldano committed Nov 12, 2018
1 parent 106545a commit dfa3b30
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
@@ -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"));
}

}
@@ -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;
}
}
@@ -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;
}

}

0 comments on commit dfa3b30

Please sign in to comment.