Search in sources :

Example 21 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_greater_than_decimal_max.

@Test
public void provide_one_valid_violation_if_number_is_greater_than_decimal_max() {
    maxDecimalNumberTest(GREATER_THAN_MAX, /*inclusive=*/
    true, /*valid=*/
    false);
    assertEquals(1, violations.size());
    final ConstraintViolation violation = firstViolation();
    assertEquals(GREATER_MAX_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 22 with ConstraintViolation

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

the class MessageValidatorShould method provide_one_valid_violation_if_entity_id_in_command_is_not_valid.

@Test
public void provide_one_valid_violation_if_entity_id_in_command_is_not_valid() {
    validate(EntityIdMsgFieldValue.getDefaultInstance());
    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) Test(org.junit.Test)

Example 23 with ConstraintViolation

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

the class MessageValidatorShould method provide_one_valid_violation_if_integral_digit_count_is_greater_than_max.

@Test
public void provide_one_valid_violation_if_integral_digit_count_is_greater_than_max() {
    digitsCountTest(INT_DIGIT_COUNT_GREATER_THAN_MAX, /*valid=*/
    false);
    assertEquals(1, violations.size());
    final ConstraintViolation violation = firstViolation();
    assertEquals("Number value is out of bounds, expected: <2 max digits>.<2 max digits>.", 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 24 with ConstraintViolation

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

the class ValidatorShould method validate_command_and_return_violations_if_message_is_NOT_valid.

@Test
public void validate_command_and_return_violations_if_message_is_NOT_valid() {
    final Any invalidMessagePacked = AnyPacker.pack(CreateProject.getDefaultInstance());
    final Command commandWithEmptyMessage = Command.newBuilder().setId(generateId()).setMessage(invalidMessagePacked).setContext(createCommandContext()).build();
    final List<ConstraintViolation> violations = validator.validate(CommandEnvelope.of(commandWithEmptyMessage));
    assertEquals(3, violations.size());
}
Also used : Command(io.spine.base.Command) ConstraintViolation(io.spine.validate.ConstraintViolation) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 25 with ConstraintViolation

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

the class CommandValidatorViolationCheckShould method validate_command_and_return_violations_if_message_is_NOT_valid.

@Test
public void validate_command_and_return_violations_if_message_is_NOT_valid() {
    final Any invalidMessagePacked = AnyPacker.pack(CmdCreateProject.getDefaultInstance());
    final Command commandWithEmptyMessage = Command.newBuilder().setId(generateId()).setMessage(invalidMessagePacked).setContext(withRandomActor()).build();
    final List<ConstraintViolation> violations = inspect(CommandEnvelope.of(commandWithEmptyMessage));
    assertEquals(3, violations.size());
}
Also used : Command(io.spine.core.Command) ConstraintViolation(io.spine.validate.ConstraintViolation) Any(com.google.protobuf.Any) 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