@Deployment(testable = false)
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(MyApplication.class, NameAddResource.class, Name.class, Email.class, EmailValidator.class);
}
cd javaee7-samples/jaxrs/resource-validation/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=NameAddResourceTest
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(MyApplication.class, NameAddResource.class, Name.class, Email.class, EmailValidator.class);
}
@Test
public void shouldPassNameValidation() throws Exception {
JsonObject name = startValidName()
.build();
Response response = postName(name);
assertStatus(response, OK);
}
@Test
public void shouldFailAtFirstNameSizeValidation() throws Exception {
JsonObject name = startValidName()
.add("firstName", "")
.build();
Response response = postName(name);
assertFailedValidation(response);
}
@Test
public void shouldFailAtFirstNameNullValidation() throws Exception {
JsonObject name = startValidName()
.addNull("firstName")
.build();
Response response = postName(name);
assertFailedValidation(response);
}
@Test
public void shouldFailAtLastNameSizeValidation() throws Exception {
JsonObject name = startValidName()
.add("lastName", "")
.build();
Response response = postName(name);
assertFailedValidation(response);
}
@Test
public void shouldFailAtLastNameNullValidation() throws Exception {
JsonObject name = startValidName()
.addNull("lastName")
.build();
Response response = postName(name);
assertFailedValidation(response);
}
@Test
public void shouldFailAtEmailAtSymbolValidation() throws Exception {
JsonObject name = startValidName()
.add("email", "missing-at-symbol.com")
.build();
Response response = postName(name);
assertFailedValidation(response);
}
@Test
public void shouldFailAtEmailComDomainValidation() throws Exception {
JsonObject name = startValidName()
.add("email", "other-than-com@domain.pl")
.build();
Response response = postName(name);
assertFailedValidation(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/resource-validation/
Do the changes as you see fit and send a pull request!
Good Luck!