Skip to content

Commit

Permalink
[RESTEASY-1442] Add JsonFilterSuperClassTest
Browse files Browse the repository at this point in the history
  • Loading branch information
kanovotn authored and asoldano committed Oct 4, 2016
1 parent b10ffc6 commit 89aa36d
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
@@ -0,0 +1,62 @@
package org.jboss.resteasy.test.providers.jackson2.jsonfilter;

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.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.test.providers.jackson2.jsonfilter.resource.*;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.jboss.resteasy.utils.PortProviderUtil;
import org.jboss.resteasy.utils.TestUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;

/**
* @tpSubChapter Jackson2 provider
* @tpChapter Integration tests
* @tpTestCaseDetails Filters fields from json object. Specifies the filter implementation class in web.xml.
* JsonFilterParent defines the @JsonFilter annotation. JsonFilter applies to its subclass JsonFilterChild as well.
* @tpSince RESTEasy 3.1.0
*/
@RunWith(Arquillian.class)
@RunAsClient
public class JsonFilterSuperClassTest {

@Deployment
public static Archive<?> deploy() {
WebArchive war = TestUtil.prepareArchive(JsonFilterSuperClassTest.class.getSimpleName());
war.addClasses(JsonFilterParent.class, JsonFilterChild.class, PersonType.class, ObjectFilterModifier.class,
ObjectWriterModifierFilter.class);
war.addAsManifestResource(new StringAsset("Manifest-Version: 1.0\n" + "Dependencies: com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider\n"), "MANIFEST.MF");
war.addAsWebInfResource(JsonFilterWithSerlvetFilterTest.class.getPackage(), "web.xml", "web.xml");
return TestUtil.finishContainerPrepare(war, null, JsonFilterChildResource.class);
}

private String generateURL(String path) {
return PortProviderUtil.generateURL(path, JsonFilterSuperClassTest.class.getSimpleName());
}

/**
* @tpTestDetails Json string in the response is correctly filtered
* @tpSince RESTEasy 3.1.0
*/
@Test
public void testJacksonStringInSuperClass() throws Exception {
Client client = new ResteasyClientBuilder().build();
WebTarget target = client.target(generateURL("/superclass/333"));
Response response = target.request().get();
response.bufferEntity();
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
Assert.assertTrue("Filter doesn't work", !response.readEntity(String.class).contains("id") &&
response.readEntity(String.class).contains("name"));
client.close();
}
}
@@ -0,0 +1,22 @@
package org.jboss.resteasy.test.providers.jackson2.jsonfilter.resource;

public class JsonFilterChild extends JsonFilterParent {
protected PersonType personType;

public JsonFilterChild() {

}

public JsonFilterChild(PersonType personType, int id, String name) {
super(name, id);
this.personType = personType;
}

public PersonType getPersonType() {
return personType;
}

public void setPersonType(PersonType personType) {
this.personType = personType;
}
}
@@ -0,0 +1,16 @@
package org.jboss.resteasy.test.providers.jackson2.jsonfilter.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

@Path("/superclass")
public class JsonFilterChildResource {
@GET
@Produces("application/json")
@Path("{id}")
public JsonFilterChild getProduct(@PathParam("id") int id) {
return new JsonFilterChild(PersonType.CUSTOMER, id, "Melissa");
}
}
@@ -0,0 +1,37 @@
package org.jboss.resteasy.test.providers.jackson2.jsonfilter.resource;

import com.fasterxml.jackson.annotation.JsonFilter;

@JsonFilter("nameFilter")
public class JsonFilterParent {
protected String name;
protected int id;

public JsonFilterParent() {

}

public JsonFilterParent(String name, int id) {
this.name = name;
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}



}

0 comments on commit 89aa36d

Please sign in to comment.