Browse files

more tests

  • Loading branch information...
1 parent 4133b36 commit d5d0159eb34f4c8c633897e6822fcf586c8ac8f2 @liweinan liweinan committed with liweinan Oct 31, 2012
View
64 ...roviders/jackson/src/test/java/org/jboss/resteasy/test/providers/jackson/JacksonTest.java
@@ -3,6 +3,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.codehaus.jackson.annotate.JsonProperty;
import org.jboss.resteasy.annotations.providers.NoJackson;
import org.jboss.resteasy.annotations.providers.jaxb.json.BadgerFish;
import org.jboss.resteasy.client.ClientRequest;
@@ -281,6 +282,30 @@ public void setAttr2(String attr2) {
}
}
+
+ public static class XmlResourceWithJacksonAnnotation {
+ String attr1;
+ String attr2;
+
+ @JsonProperty("attr_1")
+ public String getAttr1() {
+ return attr1;
+ }
+
+ public void setAttr1(String attr1) {
+ this.attr1 = attr1;
+ }
+
+ @XmlElement
+ public String getAttr2() {
+ return attr2;
+ }
+
+ public void setAttr2(String attr2) {
+ this.attr2 = attr2;
+ }
+ }
+
@Path("/jaxb")
public static class JAXBService
{
@@ -294,21 +319,42 @@ public XmlResourceWithJAXB getJAXBResource() {
return resourceWithJAXB;
}
- }
+ @GET
+ @Path(("/json"))
+ @Produces("application/json")
+ public XmlResourceWithJacksonAnnotation getJacksonAnnotatedResource() {
+ XmlResourceWithJacksonAnnotation resource = new XmlResourceWithJacksonAnnotation();
+ resource.setAttr1("XXX");
+ resource.setAttr2("YYY");
+ return resource;
+ }
+
+ }
@Test
- public void testJacksonJAXB() throws Exception
- {
- DefaultHttpClient client = new DefaultHttpClient();
- HttpGet get = new HttpGet(generateBaseUrl() + "/jaxb");
- HttpResponse response = client.execute(get);
- BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
- Assert.assertTrue(reader.readLine().contains("attr_1"));
+ public void testJacksonJAXB() throws Exception {
+ {
+ DefaultHttpClient client = new DefaultHttpClient();
+ HttpGet get = new HttpGet(generateBaseUrl() + "/jaxb");
+ HttpResponse response = client.execute(get);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+ Assert.assertTrue(reader.readLine().contains("attr_1"));
+ }
+
+ {
+ DefaultHttpClient client = new DefaultHttpClient();
+ HttpGet get = new HttpGet(generateBaseUrl() + "/jaxb/json");
+ HttpResponse response = client.execute(get);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+ Assert.assertTrue(reader.readLine().contains("attr_1"));
+
+ }
+
}
- @Test
+ @Test
public void testJacksonProxy() throws Exception
{
JacksonProxy proxy = ProxyFactory.create(JacksonProxy.class, generateBaseUrl());

0 comments on commit d5d0159

Please sign in to comment.