Java 类io.dropwizard.jersey.validation.ValidationErrorMessage 实例源码

项目:coner-core    文件:CompetitionGroupsResourceTest.java   
@Test
public void whenAddCompetitionGroupWithLargeHandicapFactorItShouldFailValidation() throws Exception {
    AddCompetitionGroupRequest requestCompetitionGroupApiEntity = objectMapper.readValue(
            fixture("fixtures/api/entity/competition_group_add-request-with-large-handicap-factor.json"),
            AddCompetitionGroupRequest.class
    );
    Entity<AddCompetitionGroupRequest> requestEntity = Entity.json(requestCompetitionGroupApiEntity);

    Response response = resources.client()
            .target("/competitionGroups")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage errorsResponse = response.readEntity(ValidationErrorMessage.class);
    assertThat(errorsResponse.getErrors())
            .isNotEmpty()
            .contains("factor must be less than or equal to 1.000");
    verifyZeroInteractions(competitionGroupEntityService);
}
项目:coner-core    文件:CompetitionGroupsResourceTest.java   
@Test
public void whenAddCompetitionGroupWithoutResultTimeTypeItShouldFailValidation() throws Exception {
    AddCompetitionGroupRequest requestCompetitionGroupApiEntity = objectMapper.readValue(
            fixture("fixtures/api/entity/competition_group_add-request-without-result-time-type.json"),
            AddCompetitionGroupRequest.class
    );
    Entity<AddCompetitionGroupRequest> requestEntity = Entity.json(requestCompetitionGroupApiEntity);

    Response response = resources.client()
            .target("/competitionGroups")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("resultTimeType may not be empty");
    verifyZeroInteractions(competitionGroupEntityService);
}
项目:coner-core    文件:CompetitionGroupsResourceTest.java   
@Test
public void whenAddCompetitionGroupWithoutGroupingItShouldFailValidation() throws Exception {
    AddCompetitionGroupRequest requestCompetitionGroupApiEntity = objectMapper.readValue(
            fixture("fixtures/api/entity/competition_group_add-request-without-grouping.json"),
            AddCompetitionGroupRequest.class
    );
    Entity<AddCompetitionGroupRequest> requestEntity = Entity.json(requestCompetitionGroupApiEntity);

    Response response = resources.client()
            .target("/competitionGroups")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage errorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(errorMessage.getErrors())
            .isNotEmpty()
            .contains("grouping may not be null");
    verifyZeroInteractions(competitionGroupEntityService);
}
项目:coner-core    文件:EventsResourceTest.java   
@Test
public void whenAddEventWithoutNameItShouldFailValidation() throws Exception {
    AddEventRequest requestEvent = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/event_add-request-without-name.json"),
            AddEventRequest.class
    );
    Entity<AddEventRequest> requestEntity = Entity.json(requestEvent);

    Response response = resources.client()
            .target("/events")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("name may not be empty");
    verifyZeroInteractions(eventEntityService);
}
项目:coner-core    文件:EventsResourceTest.java   
@Test
public void whenAddEventWithoutDateItShouldFailValidation() throws Exception {
    AddEventRequest requestEvent = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/event_add-request-without-date.json"),
            AddEventRequest.class
    );
    Entity<AddEventRequest> requestEntity = Entity.json(requestEvent);

    Response response = resources.client()
            .target("/events")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("date may not be null");

    verifyZeroInteractions(eventEntityService);
}
项目:coner-core    文件:EventsResourceTest.java   
@Test
public void whenAddEventWithoutHandicapGroupSetIdItShouldFailValidation() throws Exception {
    AddEventRequest request = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/event_add-request-without-handicap-group-set-id.json"),
            AddEventRequest.class
    );
    Entity<AddEventRequest> requestEntity = Entity.json(request);

    Response response = resources.client()
            .target("/events")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("handicapGroupSetId may not be empty");

    verifyZeroInteractions(eventEntityService);
}
项目:coner-core    文件:EventsResourceTest.java   
@Test
public void whenAddEventWithoutCompetitionGroupSetIdItShouldFailValidation() throws Exception {
    AddEventRequest request = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/event_add-request-without-competition-group-set-id.json"),
            AddEventRequest.class
    );
    Entity<AddEventRequest> requestEntity = Entity.json(request);

    Response response = resources.client()
            .target("/events")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("competitionGroupSetId may not be empty");

    verifyZeroInteractions(eventEntityService);
}
项目:coner-core    文件:HandicapGroupsResourceTest.java   
@Test
public void whenAddHandicapGroupWithLargeFactorItShouldFailValidation() throws Exception {
    AddHandicapGroupRequest requestHandicapGroup = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/handicap_group_add-request-wrong-factor.json"),
            AddHandicapGroupRequest.class
    );
    Entity<AddHandicapGroupRequest> requestEntity = Entity.json(requestHandicapGroup);

    HandicapGroupAddPayload addPayload = mock(HandicapGroupAddPayload.class);
    when(handicapGroupMapper.toDomainAddPayload(requestHandicapGroup)).thenReturn(addPayload);

    Response response = resources.client()
            .target("/handicapGroups")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);
    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("factor must be less than or equal to 1.000");

    verifyZeroInteractions(handicapGroupEntityService);
}
项目:coner-core    文件:CompetitionGroupIntegrationTest.java   
@Test
public void whenCreateInvalidCompetitionGroupItShouldReject() {
    URI competitionGroupsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path(COMPETITION_GROUPS_PATH)
            .build();
    AddCompetitionGroupRequest addCompetitionGroupRequest = ApiRequestTestUtils.fullAddCompetitionGroup();
    addCompetitionGroupRequest.setName(null);
    addCompetitionGroupRequest.setResultTimeType(null);

    Response addCompetitionGroupResponseContainer = client.target(competitionGroupsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addCompetitionGroupRequest));

    assertThat(addCompetitionGroupResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addCompetitionGroupResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:RegistrationIntegrationTest.java   
@Test
public void whenCreateRegistrationWithoutPersonItShouldReject() {
    URI eventRegistrationsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path("/events/{eventId}/registrations")
            .build(prerequisites.eventId);
    AddRegistrationRequest addRegistrationRequest = ApiRequestTestUtils.fullAddRegistration();
    addRegistrationRequest.setPerson(null);

    Response addRegistrationResponseContainer = client.target(eventRegistrationsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addRegistrationRequest));

    assertThat(addRegistrationResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addRegistrationResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:RegistrationIntegrationTest.java   
@Test
public void whenCreateRegistrationWithoutCarItShouldReject() {
    URI eventRegistrationsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path("/events/{eventId}/registrations")
            .build(prerequisites.eventId);
    AddRegistrationRequest addRegistrationRequest = ApiRequestTestUtils.fullAddRegistration();
    addRegistrationRequest.setCar(null);

    Response addRegistrationResponseContainer = client.target(eventRegistrationsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addRegistrationRequest));

    assertThat(addRegistrationResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addRegistrationResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:EventIntegrationTest.java   
@Test
public void whenCreateEventInvalidItShouldReject() {
    URI eventsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path("/events")
            .build();
    AddEventRequest addEventRequest = ApiRequestTestUtils.fullAddEvent();
    addEventRequest.setName(null);

    Response addEventResponseContainer = client.target(eventsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addEventRequest));

    assertThat(addEventResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addEventResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:HandicapGroupIntegrationTest.java   
@Test
public void whenCreateInvalidHandicapGroupItShouldReject() {
    URI handicapGroupsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path(HANDICAP_GROUPS_PATH)
            .build();
    AddHandicapGroupRequest addHandicapGroupRequest = ApiRequestTestUtils.fullAddHandicapGroup();
    addHandicapGroupRequest.setName(null);
    addHandicapGroupRequest.setFactor(null);

    Response addHandicapGroupResponseContainer = client.target(handicapGroupsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addHandicapGroupRequest));

    assertThat(addHandicapGroupResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addHandicapGroupResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:CompetitionGroupsResourceTest.java   
@Test
public void whenAddCompetitionGroupWithLargeHandicapFactorItShouldFailValidation() throws Exception {
    AddCompetitionGroupRequest requestCompetitionGroupApiEntity = objectMapper.readValue(
            fixture("fixtures/api/entity/competition_group_add-request-with-large-handicap-factor.json"),
            AddCompetitionGroupRequest.class
    );
    Entity<AddCompetitionGroupRequest> requestEntity = Entity.json(requestCompetitionGroupApiEntity);

    Response response = resources.client()
            .target("/competitionGroups")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage errorsResponse = response.readEntity(ValidationErrorMessage.class);
    assertThat(errorsResponse.getErrors())
            .isNotEmpty()
            .contains("factor must be less than or equal to 1.000");
    verifyZeroInteractions(competitionGroupEntityService);
}
项目:coner-core    文件:CompetitionGroupsResourceTest.java   
@Test
public void whenAddCompetitionGroupWithoutResultTimeTypeItShouldFailValidation() throws Exception {
    AddCompetitionGroupRequest requestCompetitionGroupApiEntity = objectMapper.readValue(
            fixture("fixtures/api/entity/competition_group_add-request-without-result-time-type.json"),
            AddCompetitionGroupRequest.class
    );
    Entity<AddCompetitionGroupRequest> requestEntity = Entity.json(requestCompetitionGroupApiEntity);

    Response response = resources.client()
            .target("/competitionGroups")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("resultTimeType may not be empty");
    verifyZeroInteractions(competitionGroupEntityService);
}
项目:coner-core    文件:CompetitionGroupsResourceTest.java   
@Test
public void whenAddCompetitionGroupWithoutGroupingItShouldFailValidation() throws Exception {
    AddCompetitionGroupRequest requestCompetitionGroupApiEntity = objectMapper.readValue(
            fixture("fixtures/api/entity/competition_group_add-request-without-grouping.json"),
            AddCompetitionGroupRequest.class
    );
    Entity<AddCompetitionGroupRequest> requestEntity = Entity.json(requestCompetitionGroupApiEntity);

    Response response = resources.client()
            .target("/competitionGroups")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage errorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(errorMessage.getErrors())
            .isNotEmpty()
            .contains("grouping may not be null");
    verifyZeroInteractions(competitionGroupEntityService);
}
项目:coner-core    文件:EventsResourceTest.java   
@Test
public void whenAddEventWithoutNameItShouldFailValidation() throws Exception {
    AddEventRequest requestEvent = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/event_add-request-without-name.json"),
            AddEventRequest.class
    );
    Entity<AddEventRequest> requestEntity = Entity.json(requestEvent);

    Response response = resources.client()
            .target("/events")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("name may not be empty");
    verifyZeroInteractions(eventEntityService);
}
项目:coner-core    文件:EventsResourceTest.java   
@Test
public void whenAddEventWithoutDateItShouldFailValidation() throws Exception {
    AddEventRequest requestEvent = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/event_add-request-without-date.json"),
            AddEventRequest.class
    );
    Entity<AddEventRequest> requestEntity = Entity.json(requestEvent);

    Response response = resources.client()
            .target("/events")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("date may not be null");

    verifyZeroInteractions(eventEntityService);
}
项目:coner-core    文件:EventsResourceTest.java   
@Test
public void whenAddEventWithoutHandicapGroupSetIdItShouldFailValidation() throws Exception {
    AddEventRequest request = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/event_add-request-without-handicap-group-set-id.json"),
            AddEventRequest.class
    );
    Entity<AddEventRequest> requestEntity = Entity.json(request);

    Response response = resources.client()
            .target("/events")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("handicapGroupSetId may not be empty");

    verifyZeroInteractions(eventEntityService);
}
项目:coner-core    文件:EventsResourceTest.java   
@Test
public void whenAddEventWithoutCompetitionGroupSetIdItShouldFailValidation() throws Exception {
    AddEventRequest request = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/event_add-request-without-competition-group-set-id.json"),
            AddEventRequest.class
    );
    Entity<AddEventRequest> requestEntity = Entity.json(request);

    Response response = resources.client()
            .target("/events")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);

    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("competitionGroupSetId may not be empty");

    verifyZeroInteractions(eventEntityService);
}
项目:coner-core    文件:HandicapGroupsResourceTest.java   
@Test
public void whenAddHandicapGroupWithLargeFactorItShouldFailValidation() throws Exception {
    AddHandicapGroupRequest requestHandicapGroup = objectMapper.readValue(
            FixtureHelpers.fixture("fixtures/api/entity/handicap_group_add-request-wrong-factor.json"),
            AddHandicapGroupRequest.class
    );
    Entity<AddHandicapGroupRequest> requestEntity = Entity.json(requestHandicapGroup);

    HandicapGroupAddPayload addPayload = mock(HandicapGroupAddPayload.class);
    when(handicapGroupMapper.toDomainAddPayload(requestHandicapGroup)).thenReturn(addPayload);

    Response response = resources.client()
            .target("/handicapGroups")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(requestEntity);
    assertThat(response.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = response.readEntity(ValidationErrorMessage.class);
    assertThat(validationErrorMessage.getErrors())
            .isNotEmpty()
            .contains("factor must be less than or equal to 1.000");

    verifyZeroInteractions(handicapGroupEntityService);
}
项目:coner-core    文件:CompetitionGroupIntegrationTest.java   
@Test
public void whenCreateInvalidCompetitionGroupItShouldReject() {
    URI competitionGroupsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path(COMPETITION_GROUPS_PATH)
            .build();
    AddCompetitionGroupRequest addCompetitionGroupRequest = ApiRequestTestUtils.fullAddCompetitionGroup();
    addCompetitionGroupRequest.setName(null);
    addCompetitionGroupRequest.setResultTimeType(null);

    Response addCompetitionGroupResponseContainer = client.target(competitionGroupsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addCompetitionGroupRequest));

    assertThat(addCompetitionGroupResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addCompetitionGroupResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:RegistrationIntegrationTest.java   
@Test
public void whenCreateRegistrationWithoutPersonItShouldReject() {
    URI eventRegistrationsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path("/events/{eventId}/registrations")
            .build(prerequisites.eventId);
    AddRegistrationRequest addRegistrationRequest = ApiRequestTestUtils.fullAddRegistration();
    addRegistrationRequest.setPerson(null);

    Response addRegistrationResponseContainer = client.target(eventRegistrationsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addRegistrationRequest));

    assertThat(addRegistrationResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addRegistrationResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:RegistrationIntegrationTest.java   
@Test
public void whenCreateRegistrationWithoutCarItShouldReject() {
    URI eventRegistrationsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path("/events/{eventId}/registrations")
            .build(prerequisites.eventId);
    AddRegistrationRequest addRegistrationRequest = ApiRequestTestUtils.fullAddRegistration();
    addRegistrationRequest.setCar(null);

    Response addRegistrationResponseContainer = client.target(eventRegistrationsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addRegistrationRequest));

    assertThat(addRegistrationResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addRegistrationResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:EventIntegrationTest.java   
@Test
public void whenCreateEventInvalidItShouldReject() {
    URI eventsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path("/events")
            .build();
    AddEventRequest addEventRequest = ApiRequestTestUtils.fullAddEvent();
    addEventRequest.setName(null);

    Response addEventResponseContainer = client.target(eventsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addEventRequest));

    assertThat(addEventResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addEventResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:coner-core    文件:HandicapGroupIntegrationTest.java   
@Test
public void whenCreateInvalidHandicapGroupItShouldReject() {
    URI handicapGroupsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
            .path(HANDICAP_GROUPS_PATH)
            .build();
    AddHandicapGroupRequest addHandicapGroupRequest = ApiRequestTestUtils.fullAddHandicapGroup();
    addHandicapGroupRequest.setName(null);
    addHandicapGroupRequest.setFactor(null);

    Response addHandicapGroupResponseContainer = client.target(handicapGroupsUri)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(addHandicapGroupRequest));

    assertThat(addHandicapGroupResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);
    ValidationErrorMessage validationErrorMessage = addHandicapGroupResponseContainer.readEntity(
            ValidationErrorMessage.class
    );
    assertThat(validationErrorMessage.getErrors()).isNotEmpty();
}
项目:commafeed    文件:UserREST.java   
@Path("/register")
@POST
@UnitOfWork
@ApiOperation(value = "Register a new account")
@Timed
public Response register(@Valid @ApiParam(required = true) RegistrationRequest req, @Context 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();
    }
}
项目:verify-hub    文件:AuthnRequestFromTransactionResourceIntegrationTest.java   
@Test
public void badEntityResponseThrown_WhenMandatoryFieldsAreMissing() throws Exception {
    sessionId = aSessionIsCreated();
    Response response = postIdpSelected(new IdpSelected(null, null, null));

    assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);

    ValidationErrorMessage msg = response.readEntity(ValidationErrorMessage.class);

    assertThat(msg.getErrors()).contains("selectedIdpEntityId may not be empty");
    assertThat(msg.getErrors()).contains("principalIpAddress may not be empty");
    assertThat(msg.getErrors()).contains("registration may not be null");
}
项目:sam    文件:ConstraintViolationExceptionMapper.java   
@Override
public Response toResponse(ConstraintViolationException exc) {

  final ImmutableList<String> violations = FluentIterable.from(exc.getConstraintViolations())
    .transform(violation -> violation.getPropertyPath() + " " + violation.getMessage())
    .toList();

  final int statusCode = RestHelper.HTTP_STATUS_VALIDATION_ERROR;
  return Response.status(statusCode)
    .entity(new ValidationErrorMessage(violations))
    .build();
}
项目:coner-core    文件:CompetitionGroupsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add a Competition Group")
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                message = "Failed validation",
                response = ValidationErrorMessage.class
        )
})
public Response addCompetitionGroup(
        @Valid @ApiParam(value = "Competition Group") AddCompetitionGroupRequest request
) throws AddEntityException {
    CompetitionGroupAddPayload addPayload = competitionGroupMapper.toDomainAddPayload(request);
    CompetitionGroup domainEntity = competitionGroupEntityService.add(addPayload);
    CompetitionGroupApiEntity entity = competitionGroupMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/competitionGroups/{competitionGroupId}")
            .build(entity.getId()))
            .build();
}
项目:coner-core    文件:EventRunsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add a new run")
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.NOT_FOUND_404,
                response = ErrorMessage.class,
                message = "No event with given ID"
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                response = ValidationErrorMessage.class,
                message = "Failed validation"
        )
})
public Response addRun(
        @PathParam("eventId") @ApiParam(value = "Event ID", required = true) String eventId,
        @Valid @ApiParam(value = "Run", required = true) AddRunRequest request
) throws AddEntityException, EntityNotFoundException {
    RunAddPayload addPayload = runMapper.toDomainAddPayload(request, eventId);
    Run domainEntity = runEntityService.add(addPayload);
    RunApiEntity run = runMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/events/{eventId}/runs/{runId}")
                                    .build(eventId, run.getId()))
            .build();
}
项目:coner-core    文件:EventsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add an Event", response = Response.class)
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                response = ValidationErrorMessage.class,
                message = "Failed validation"
        )
})
public Response addEvent(
        @Valid @ApiParam(value = "Event", required = true) AddEventRequest request
) throws AddEntityException {
    EventAddPayload addPayload = eventMapper.toDomainAddPayload(request);
    Event domainEntity = eventEntityService.add(addPayload);
    EventApiEntity eventApiEntity = eventMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/events/{eventId}")
            .build(eventApiEntity.getId()))
            .build();
}
项目:coner-core    文件:EventRegistrationsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add a new registration")
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.NOT_FOUND_404,
                response = ErrorMessage.class,
                message = "No event with given ID"
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                response = ValidationErrorMessage.class,
                message = "Failed validation"
        )
})
public Response addRegistration(
        @PathParam("eventId") @ApiParam(value = "Event ID", required = true) String eventId,
        @Valid @ApiParam(value = "Registration", required = true) AddRegistrationRequest request
) throws AddEntityException, EntityNotFoundException {
    RegistrationAddPayload addPayload = registrationMapper.toDomainAddPayload(request, eventId);
    Registration domainEntity = eventRegistrationService.add(addPayload);
    RegistrationApiEntity registration = registrationMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/events/{eventId}/registrations/{registrationId}")
            .build(eventId, registration.getId()))
            .build();
}
项目:coner-core    文件:HandicapGroupSetsResource.java   
@POST
@UnitOfWork
@ApiOperation(
        value = "Add a new Handicap Group Set",
        notes = "Optionally include a set of Handicap Group entities with ID to associate them"
)
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                message = "Failed validation",
                response = ValidationErrorMessage.class
        )
})
public Response add(
        @Valid @NotNull @ApiParam(value = "Handicap Group Set") AddHandicapGroupSetRequest request
) throws AddEntityException {
    HandicapGroupSetAddPayload addPayload = handicapGroupSetMapper.toDomainAddPayload(request);
    HandicapGroupSet domainEntity = handicapGroupSetService.add(addPayload);
    HandicapGroupSetApiEntity entity = handicapGroupSetMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/handicapGroups/sets/{handicapGroupSetId}")
            .build(entity.getId()))
            .build();
}
项目:coner-core    文件:CompetitionGroupSetsResource.java   
@POST
@UnitOfWork
@ApiOperation(
        value = "Add a new Competition Group Set",
        notes = "Optionally include a list of Competition Group entities with ID to associate them"
)
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                message = "Failed validation",
                response = ValidationErrorMessage.class
        )
})
public Response add(
        @Valid @ApiParam(value = "Competition Group Set") AddCompetitionGroupSetRequest request
) throws AddEntityException {
    CompetitionGroupSetAddPayload addPayload = competitionGroupSetMapper.toDomainAddPayload(request);
    CompetitionGroupSet domainEntity = competitionGroupSetService.add(addPayload);
    CompetitionGroupSetApiEntity entity = competitionGroupSetMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/competitionGroups/sets/{competitionGroupSetId}")
            .build(entity.getId()))
            .build();
}
项目:coner-core    文件:HandicapGroupsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add a Handicap Group")
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                message = "Failed validation",
                response = ValidationErrorMessage.class
        )
})
public Response addHandicapGroup(
        @Valid @ApiParam(value = "Handicap Group") AddHandicapGroupRequest request
) throws AddEntityException {
    HandicapGroupAddPayload addPayload = handicapGroupMapper.toDomainAddPayload(request);
    HandicapGroup domainEntity = handicapGroupEntityService.add(addPayload);
    HandicapGroupApiEntity entity = handicapGroupMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/handicapGroups/{handicapGroupId}")
            .build(entity.getId()))
            .build();
}
项目:coner-core    文件:CompetitionGroupsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add a Competition Group")
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                message = "Failed validation",
                response = ValidationErrorMessage.class
        )
})
public Response addCompetitionGroup(
        @Valid @ApiParam(value = "Competition Group") AddCompetitionGroupRequest request
) throws AddEntityException {
    CompetitionGroupAddPayload addPayload = competitionGroupMapper.toDomainAddPayload(request);
    CompetitionGroup domainEntity = competitionGroupEntityService.add(addPayload);
    CompetitionGroupApiEntity entity = competitionGroupMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/competitionGroups/{competitionGroupId}")
            .build(entity.getId()))
            .build();
}
项目:coner-core    文件:EventRunsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add a new run")
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.NOT_FOUND_404,
                response = ErrorMessage.class,
                message = "No event with given ID"
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                response = ValidationErrorMessage.class,
                message = "Failed validation"
        )
})
public Response addRun(
        @PathParam("eventId") @ApiParam(value = "Event ID", required = true) String eventId,
        @Valid @ApiParam(value = "Run", required = true) AddRunRequest request
) throws AddEntityException, EntityNotFoundException {
    RunAddPayload addPayload = runMapper.toDomainAddPayload(request, eventId);
    Run domainEntity = runEntityService.add(addPayload);
    RunApiEntity run = runMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/events/{eventId}/runs/{runId}")
                                    .build(eventId, run.getId()))
            .build();
}
项目:coner-core    文件:EventsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add an Event", response = Response.class)
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                response = ValidationErrorMessage.class,
                message = "Failed validation"
        )
})
public Response addEvent(
        @Valid @ApiParam(value = "Event", required = true) AddEventRequest request
) throws AddEntityException {
    EventAddPayload addPayload = eventMapper.toDomainAddPayload(request);
    Event domainEntity = eventEntityService.add(addPayload);
    EventApiEntity eventApiEntity = eventMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/events/{eventId}")
            .build(eventApiEntity.getId()))
            .build();
}
项目:coner-core    文件:EventRegistrationsResource.java   
@POST
@UnitOfWork
@ApiOperation(value = "Add a new registration")
@ApiResponses({
        @ApiResponse(
                code = HttpStatus.CREATED_201,
                message = ApiResponseConstants.Created.MESSAGE,
                responseHeaders = {
                        @ResponseHeader(
                                name = ApiResponseConstants.Created.Headers.NAME,
                                description = ApiResponseConstants.Created.Headers.DESCRIPTION,
                                response = String.class
                        )
                }
        ),
        @ApiResponse(
                code = HttpStatus.NOT_FOUND_404,
                response = ErrorMessage.class,
                message = "No event with given ID"
        ),
        @ApiResponse(
                code = HttpStatus.UNPROCESSABLE_ENTITY_422,
                response = ValidationErrorMessage.class,
                message = "Failed validation"
        )
})
public Response addRegistration(
        @PathParam("eventId") @ApiParam(value = "Event ID", required = true) String eventId,
        @Valid @ApiParam(value = "Registration", required = true) AddRegistrationRequest request
) throws AddEntityException, EntityNotFoundException {
    RegistrationAddPayload addPayload = registrationMapper.toDomainAddPayload(request, eventId);
    Registration domainEntity = eventRegistrationService.add(addPayload);
    RegistrationApiEntity registration = registrationMapper.toApiEntity(domainEntity);
    return Response.created(UriBuilder.fromPath("/events/{eventId}/registrations/{registrationId}")
            .build(eventId, registration.getId()))
            .build();
}