use of io.spine.server.entity.InvalidEntityStateException in project core-java by SpineEventEngine.
the class AggregatePartShould method throw_InvalidEntityStateException_if_state_is_invalid.
@Test
public void throw_InvalidEntityStateException_if_state_is_invalid() {
final User user = User.newBuilder().setFirstName("|").setLastName("|").build();
try {
aggregatePartOfClass(AnAggregatePart.class).withRoot(root).withId(getClass().getName()).withVersion(1).withState(user).build();
fail();
} catch (InvalidEntityStateException e) {
final List<ConstraintViolation> violations = e.getError().getValidationError().getConstraintViolationList();
assertSize(user.getAllFields().size(), violations);
}
}
use of io.spine.server.entity.InvalidEntityStateException in project core-java by SpineEventEngine.
the class AggregateShould method throw_InvalidEntityStateException_if_state_is_invalid.
@Test
public void throw_InvalidEntityStateException_if_state_is_invalid() {
final User user = User.newBuilder().setFirstName("|").setLastName("|").build();
try {
aggregateOfClass(UserAggregate.class).withId(getClass().getName()).withVersion(1).withState(user).build();
fail();
} catch (InvalidEntityStateException e) {
final List<ConstraintViolation> violations = e.getError().getValidationError().getConstraintViolationList();
assertSize(user.getAllFields().size(), violations);
}
}
use of io.spine.server.entity.InvalidEntityStateException in project core-java by SpineEventEngine.
the class InvalidEntityStateExceptionShould method create_exception_with_violations.
@Test
public void create_exception_with_violations() {
final StringValue entityState = StringValue.getDefaultInstance();
final InvalidEntityStateException exception = onConstraintViolations(entityState, singletonList(ConstraintViolation.getDefaultInstance()));
assertNotNull(exception.getMessage());
assertNotNull(exception.getError());
assertEquals(entityState, exception.getEntityState());
}
use of io.spine.server.entity.InvalidEntityStateException in project core-java by SpineEventEngine.
the class AbstractEntityShould method throw_InvalidEntityStateException_if_state_is_invalid.
@Test
public void throw_InvalidEntityStateException_if_state_is_invalid() {
final NaturalNumberEntity entity = new NaturalNumberEntity(0L);
final NaturalNumber invalidNaturalNumber = newNaturalNumber(-1);
try {
// This should pass.
entity.updateState(newNaturalNumber(1));
// This should fail.
entity.updateState(invalidNaturalNumber);
fail("Exception expected.");
} catch (InvalidEntityStateException e) {
assertSize(1, e.getError().getValidationError().getConstraintViolationList());
}
}
Aggregations