Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RESTEASY-1442] Add JsonFilterSuperClassTest
- Loading branch information
Showing
4 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
.../java/org/jboss/resteasy/test/providers/jackson2/jsonfilter/JsonFilterSuperClassTest.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,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(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../java/org/jboss/resteasy/test/providers/jackson2/jsonfilter/resource/JsonFilterChild.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,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; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...g/jboss/resteasy/test/providers/jackson2/jsonfilter/resource/JsonFilterChildResource.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,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"); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...java/org/jboss/resteasy/test/providers/jackson2/jsonfilter/resource/JsonFilterParent.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,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; | ||
} | ||
|
||
|
||
|
||
} |