Search in sources :

Example 6 with ConstraintViolation

use of io.spine.validate.ConstraintViolation in project core-java by SpineEventEngine.

the class MessageValidatorShould method provide_one_valid_violation_if_number_is_less_than_decimal_min.

@Test
public void provide_one_valid_violation_if_number_is_less_than_decimal_min() {
    minDecimalNumberTest(LESS_THAN_MIN, /*inclusive=*/
    true, /*valid=*/
    false);
    assertEquals(1, violations.size());
    final ConstraintViolation violation = firstViolation();
    assertEquals(LESS_THAN_MIN_MSG, format(violation.getMsgFormat(), violation.getParam(0), violation.getParam(1)));
    assertFieldPathIs(violation, VALUE);
    assertTrue(violation.getViolationList().isEmpty());
}
Also used : ConstraintViolation(io.spine.validate.ConstraintViolation) Test(org.junit.Test)

Example 7 with ConstraintViolation

use of io.spine.validate.ConstraintViolation in project core-java by SpineEventEngine.

the class MessageValidatorShould method provide_one_valid_violation_if_number_is_less_than_min.

@Test
public void provide_one_valid_violation_if_number_is_less_than_min() {
    final MinNumberFieldValue msg = MinNumberFieldValue.newBuilder().setValue(LESS_THAN_MIN).build();
    validate(msg);
    assertEquals(1, violations.size());
    final ConstraintViolation violation = firstViolation();
    assertEquals(LESS_THAN_MIN_MSG, format(violation.getMsgFormat(), violation.getParam(0)));
    assertFieldPathIs(violation, VALUE);
    assertTrue(violation.getViolationList().isEmpty());
}
Also used : ConstraintViolation(io.spine.validate.ConstraintViolation) MinNumberFieldValue(io.spine.test.validate.msg.MinNumberFieldValue) Test(org.junit.Test)

Example 8 with ConstraintViolation

use of io.spine.validate.ConstraintViolation in project core-java by SpineEventEngine.

the class MessageValidatorShould method checkErrorMessage.

private void checkErrorMessage(String expectedMessage) {
    final ConstraintViolation constraintViolation = firstViolation();
    assertEquals(expectedMessage, constraintViolation.getMsgFormat());
}
Also used : ConstraintViolation(io.spine.validate.ConstraintViolation)

Example 9 with ConstraintViolation

use of io.spine.validate.ConstraintViolation in project core-java by SpineEventEngine.

the class MessageValidatorShould method provide_one_valid_violation_if_required_field_is_not_set.

@Test
public void provide_one_valid_violation_if_required_field_is_not_set() {
    final RequiredStringFieldValue invalidMsg = RequiredStringFieldValue.getDefaultInstance();
    validate(invalidMsg);
    assertEquals(1, violations.size());
    final ConstraintViolation violation = firstViolation();
    assertEquals(NO_VALUE_MSG, violation.getMsgFormat());
    assertFieldPathIs(violation, VALUE);
    assertTrue(violation.getViolationList().isEmpty());
}
Also used : ConstraintViolation(io.spine.validate.ConstraintViolation) CustomMessageRequiredStringFieldValue(io.spine.test.validate.msg.CustomMessageRequiredStringFieldValue) RequiredStringFieldValue(io.spine.test.validate.msg.RequiredStringFieldValue) Test(org.junit.Test)

Example 10 with ConstraintViolation

use of io.spine.validate.ConstraintViolation in project core-java by SpineEventEngine.

the class ValidatorShould method validate_command_and_return_violations_if_context_is_NOT_valid.

@Test
public void validate_command_and_return_violations_if_context_is_NOT_valid() {
    final Command command = TestActorRequestFactory.newInstance(ValidatorShould.class).createCommand(createProjectMessage(), Time.getCurrentTime());
    final Command commandWithoutContext = command.toBuilder().setContext(CommandContext.getDefaultInstance()).build();
    final List<ConstraintViolation> violations = validator.validate(CommandEnvelope.of(commandWithoutContext));
    assertEquals(1, violations.size());
}
Also used : Command(io.spine.base.Command) ConstraintViolation(io.spine.validate.ConstraintViolation) Test(org.junit.Test)

Aggregations

ConstraintViolation (io.spine.validate.ConstraintViolation)27 Test (org.junit.Test)18 Command (io.spine.core.Command)5 Command (io.spine.base.Command)4 Any (com.google.protobuf.Any)2 MessageInvalid (io.spine.core.MessageInvalid)2 CustomMessageRequiredStringFieldValue (io.spine.test.validate.msg.CustomMessageRequiredStringFieldValue)2 RequiredStringFieldValue (io.spine.test.validate.msg.RequiredStringFieldValue)2 Optional (com.google.common.base.Optional)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 Message (com.google.protobuf.Message)1 ProtocolMessageEnum (com.google.protobuf.ProtocolMessageEnum)1 CommandContext (io.spine.base.CommandContext)1 CommandId (io.spine.base.CommandId)1 Error (io.spine.base.Error)1 Identifiers.idToString (io.spine.base.Identifiers.idToString)1 Event (io.spine.core.Event)1 EnclosedMessageFieldValue (io.spine.test.validate.msg.EnclosedMessageFieldValue)1 MaxNumberFieldValue (io.spine.test.validate.msg.MaxNumberFieldValue)1