Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create code example to show how to inject JSON format data into @MultipartForm parameter correctly
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
.../java/org/jboss/resteasy/test/providers/jackson2/multipart/Jackson2MultipartFormTest.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,51 @@ | ||
package org.jboss.resteasy.test.providers.jackson2.multipart; | ||
|
||
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.ResteasyClient; | ||
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; | ||
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; | ||
|
||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class Jackson2MultipartFormTest { | ||
|
||
static ResteasyClient client; | ||
|
||
@BeforeClass | ||
public static void init() { | ||
client = new ResteasyClientBuilder().build(); | ||
} | ||
|
||
@AfterClass | ||
public static void close() { | ||
client.close(); | ||
} | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
WebArchive war = TestUtil.prepareArchive(Jackson2MultipartFormTest.class.getSimpleName()); | ||
war.addClass(Jackson2MultipartFormTest.class); | ||
return TestUtil.finishContainerPrepare(war, null, JsonFormResource.class, JsonUser.class); | ||
} | ||
|
||
private String generateURL(String path) { | ||
return PortProviderUtil.generateURL(path, Jackson2MultipartFormTest.class.getSimpleName()); | ||
} | ||
|
||
@Test | ||
public void testJacksonProxy() { | ||
JsonForm proxy = client.target(generateURL("")).proxy(JsonForm.class); | ||
String name = proxy.putMultipartForm(new JsonFormResource.Form(new JsonUser("bill"))); | ||
Assert.assertEquals("bill", name); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...on-tests/src/test/java/org/jboss/resteasy/test/providers/jackson2/multipart/JsonForm.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.multipart; | ||
|
||
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("/") | ||
public interface JsonForm { | ||
|
||
@PUT | ||
@Path("form/class") | ||
@Consumes("multipart/form-data") | ||
String putMultipartForm(@MultipartForm JsonFormResource.Form form); | ||
} |
40 changes: 40 additions & 0 deletions
40
.../src/test/java/org/jboss/resteasy/test/providers/jackson2/multipart/JsonFormResource.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,40 @@ | ||
package org.jboss.resteasy.test.providers.jackson2.multipart; | ||
|
||
import org.jboss.resteasy.annotations.providers.multipart.MultipartForm; | ||
import org.jboss.resteasy.annotations.providers.multipart.PartType; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.FormParam; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("/") | ||
public class JsonFormResource { | ||
|
||
public JsonFormResource() { | ||
} | ||
|
||
public static class Form { | ||
@FormParam("user") | ||
@PartType("application/json") | ||
private JsonUser user; | ||
|
||
public Form() { | ||
} | ||
|
||
public Form(final JsonUser user) { | ||
this.user = user; | ||
} | ||
|
||
public JsonUser getUser() { | ||
return user; | ||
} | ||
} | ||
|
||
@PUT | ||
@Path("form/class") | ||
@Consumes("multipart/form-data") | ||
public String putMultipartForm(@MultipartForm Form form) { | ||
return form.getUser().getName(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...on-tests/src/test/java/org/jboss/resteasy/test/providers/jackson2/multipart/JsonUser.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.jackson2.multipart; | ||
|
||
public class JsonUser { | ||
private String name; | ||
|
||
public JsonUser() { | ||
} | ||
|
||
public JsonUser(final String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |