io.dropwizard.jersey.validation.ValidationErrorMessage Java Examples

The following examples show how to use io.dropwizard.jersey.validation.ValidationErrorMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotificationResourceTest.java    From notification with Apache License 2.0 6 votes vote down vote up
@Test
public void testStoreEmptyCategory() throws Exception {
  final Notification notification = Notification.builder("", "testing 1 2 3").build();

  final Response response =
      resources
          .client()
          .target("/v1/notifications/test")
          .request(MediaType.APPLICATION_JSON)
          .post(Entity.json(notification));

  verify(store, never()).store(anyString(), any(Notification.class));
  assertThat(response.getStatus()).isEqualTo(422);

  final ValidationErrorMessage msg = response.readEntity(ValidationErrorMessage.class);
  assertThat(msg.getErrors()).containsOnly("category may not be empty");
}
 
Example #2
Source File: NotificationResourceTest.java    From notification with Apache License 2.0 6 votes vote down vote up
@Test
public void testStoreMissingMessage() throws Exception {
  final Notification notification = Notification.builder("test-category").build();

  final Response response =
      resources
          .client()
          .target("/v1/notifications/test")
          .request(MediaType.APPLICATION_JSON)
          .post(Entity.json(notification));

  verify(store, never()).store(anyString(), any(Notification.class));
  assertThat(response.getStatus()).isEqualTo(422);

  final ValidationErrorMessage msg = response.readEntity(ValidationErrorMessage.class);
  assertThat(msg.getErrors()).containsOnly("message may not be empty");
}
 
Example #3
Source File: NotificationResourceTest.java    From notification with Apache License 2.0 6 votes vote down vote up
@Test
public void testStoreEmptyMessage() throws Exception {
  final Notification notification = Notification.builder("test-category", "").build();

  final Response response =
      resources
          .client()
          .target("/v1/notifications/test")
          .request(MediaType.APPLICATION_JSON)
          .post(Entity.json(notification));

  verify(store, never()).store(anyString(), any(Notification.class));
  assertThat(response.getStatus()).isEqualTo(422);

  final ValidationErrorMessage msg = response.readEntity(ValidationErrorMessage.class);
  assertThat(msg.getErrors()).containsOnly("message may not be empty");
}
 
Example #4
Source File: UserREST.java    From commafeed with Apache License 2.0 6 votes vote down vote up
@Path("/register")
@POST
@UnitOfWork
@ApiOperation(value = "Register a new account")
@Timed
public Response registerUser(@Valid @ApiParam(required = true) RegistrationRequest req,
		@Context @ApiParam(hidden = true) SessionHelper sessionHelper) {
	try {
		User registeredUser = userService.register(req.getName(), req.getPassword(), req.getEmail(), Arrays.asList(Role.USER));
		userService.login(req.getName(), req.getPassword());
		sessionHelper.setLoggedInUser(registeredUser);
		return Response.ok().build();
	} catch (final IllegalArgumentException e) {
		return Response.status(422).entity(new ValidationErrorMessage(ImmutableList.of(e.getMessage()))).type(MediaType.TEXT_PLAIN)
				.build();
	}
}
 
Example #5
Source File: RefreshDatasetResourceTest.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Test
public void itWillErrorIfTheMatchingDatasetIsNotValid() {
    Response response = refreshDatasetResource.client()
        .target("/refresh-matching-dataset")
        .request()
        .post(json("{}"));
    assertThat(response.getStatus()).isEqualTo(422);
    ValidationErrorMessage errorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(errorMessage.getErrors()).isNotEmpty();
    assertThat(errorMessage.getErrors()).contains("firstName may not be null");
}
 
Example #6
Source File: NotificationResourceTest.java    From notification with Apache License 2.0 5 votes vote down vote up
@Test
public void testStoreNull() throws Exception {
  final Response response =
      resources
          .client()
          .target("/v1/notifications/test")
          .request(MediaType.APPLICATION_JSON)
          .post(null);

  verify(store, never()).store(anyString(), any(Notification.class));
  assertThat(response.getStatus()).isEqualTo(422);

  final ValidationErrorMessage msg = response.readEntity(ValidationErrorMessage.class);
  assertThat(msg.getErrors()).containsOnly("The request body may not be null");
}