Search in sources :

Example 1 with InvalidEntityStateException

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);
    }
}
Also used : User(io.spine.test.aggregate.user.User) InvalidEntityStateException(io.spine.server.entity.InvalidEntityStateException) List(java.util.List) Test(org.junit.Test)

Example 2 with InvalidEntityStateException

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);
    }
}
Also used : User(io.spine.test.aggregate.user.User) InvalidEntityStateException(io.spine.server.entity.InvalidEntityStateException) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 3 with InvalidEntityStateException

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());
}
Also used : InvalidEntityStateException(io.spine.server.entity.InvalidEntityStateException) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 4 with InvalidEntityStateException

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());
    }
}
Also used : InvalidEntityStateException(io.spine.server.entity.InvalidEntityStateException) NaturalNumber(io.spine.test.entity.number.NaturalNumber) Test(org.junit.Test)

Aggregations

InvalidEntityStateException (io.spine.server.entity.InvalidEntityStateException)4 Test (org.junit.Test)4 User (io.spine.test.aggregate.user.User)2 List (java.util.List)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 StringValue (com.google.protobuf.StringValue)1 NaturalNumber (io.spine.test.entity.number.NaturalNumber)1