@Deployment(testable = false)
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(MyApplication.class, MyResource.class, People.class, Person.class);
}
cd javaee7-samples/jaxrs/server-negotiation/Now we are ready to start testing. You can run all the tests in this sample by executing:
mvn test
Or you can run individual tests by executing one of the following:mvn test -Dtest=MyResourceTest
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(MyApplication.class, MyResource.class, People.class, Person.class);
}
@Test
public void testJson() throws JSONException {
String response = target.request().accept("application/*").get(String.class);
JSONAssert.assertEquals("[{\"name\":\"Penny\",\"age\":1},{\"name\":\"Leonard\",\"age\":2},{\"name\":\"Sheldon\",\"age\":3}]",
response,
JSONCompareMode.STRICT);
}
@Test
public void testJson2() throws JSONException {
String response = target.request().get(String.class);
JSONAssert.assertEquals("[{\"name\":\"Penny\",\"age\":1},{\"name\":\"Leonard\",\"age\":2},{\"name\":\"Sheldon\",\"age\":3}]",
response,
JSONCompareMode.STRICT);
}
@Test
public void testXml() throws JSONException, SAXException, IOException {
String response = target.request().accept("application/xml").get(String.class);
XMLAssert.assertXMLEqual("<people><person><age>1</age><name>Penny</name></person><person><age>2</age><name>Leonard</name></person><person><age>3</age><name>Sheldon</name></person></people>",
response);
}
There's a lot more about JavaEE to cover. If you're ready to learn more, check out the other available samples.
git clone git://github.com/javaee-samples/javaee7-samples.git
cd javaee7-samples/jaxrs/server-negotiation/
Do the changes as you see fit and send a pull request!
Good Luck!