Search in sources :

Example 1 with TestEntity

use of io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity in project core-java by SpineEventEngine.

the class ColumnShould method invoke_getter.

@Test
public void invoke_getter() {
    final String entityId = "entity-id";
    final int version = 2;
    final EntityColumn column = forMethod("getVersion", VersionableEntity.class);
    final TestEntity entity = Given.entityOfClass(TestEntity.class).withId(entityId).withVersion(version).build();
    final Version actualVersion = (Version) column.getFor(entity);
    assertEquals(version, actualVersion.getNumber());
}
Also used : TestEntity(io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity) BrokenTestEntity(io.spine.server.entity.storage.given.ColumnTestEnv.BrokenTestEntity) Version(io.spine.core.Version) Test(org.junit.Test)

Example 2 with TestEntity

use of io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity in project core-java by SpineEventEngine.

the class ColumnShould method memoize_value_at_at_point_in_time.

@Test
public void memoize_value_at_at_point_in_time() {
    final EntityColumn mutableColumn = forMethod("getMutableState", TestEntity.class);
    final TestEntity entity = new TestEntity("");
    final int initialState = 1;
    final int changedState = 42;
    entity.setMutableState(initialState);
    final MemoizedValue memoizedState = mutableColumn.memoizeFor(entity);
    entity.setMutableState(changedState);
    final int extractedState = (int) mutableColumn.getFor(entity);
    final Integer value = (Integer) memoizedState.getValue();
    assertNotNull(value);
    assertEquals(initialState, value.intValue());
    assertEquals(changedState, extractedState);
}
Also used : TestEntity(io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity) BrokenTestEntity(io.spine.server.entity.storage.given.ColumnTestEnv.BrokenTestEntity) MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) Test(org.junit.Test)

Example 3 with TestEntity

use of io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity in project core-java by SpineEventEngine.

the class ColumnShould method memoize_value_which_has_reference_on_Column_itself.

@Test
public void memoize_value_which_has_reference_on_Column_itself() {
    final EntityColumn column = forMethod("getMutableState", TestEntity.class);
    final TestEntity entity = new TestEntity("");
    final MemoizedValue memoizedValue = column.memoizeFor(entity);
    assertSame(column, memoizedValue.getSourceColumn());
}
Also used : TestEntity(io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity) BrokenTestEntity(io.spine.server.entity.storage.given.ColumnTestEnv.BrokenTestEntity) MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) Test(org.junit.Test)

Example 4 with TestEntity

use of io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity in project core-java by SpineEventEngine.

the class ColumnMemoizedValueShould method support_equality.

@Test
public void support_equality() {
    /*
        4 equality groups represent following cases:
            A - 3 values of the same column memoized on the same instance of Entity;
            A-mutated - the value of the same column on the same object but after the field change;
            B - the value of a different column on the same instance;
            C - the value of a mock column (used to ensure that MemoizedValue#equals is decoupled
                from the EntityColumn#equals).
         */
    final EntityColumn columnA = findColumn(TestEntity.class, MUTABLE_STATE_COLUMN);
    final EntityColumn columnB = findColumn(TestEntity.class, ARCHIVED_COLUMN);
    final EntityColumn columnC = mock(EntityColumn.class);
    final TestEntity entity = new TestEntity("ID");
    final MemoizedValue valueA1 = columnA.memoizeFor(entity);
    final MemoizedValue valueA2 = columnA.memoizeFor(entity);
    final MemoizedValue valueA3 = columnA.memoizeFor(entity);
    entity.setMutableState(42);
    final MemoizedValue valueAMutated = columnA.memoizeFor(entity);
    final MemoizedValue valueB = columnB.memoizeFor(entity);
    final MemoizedValue valueC = new MemoizedValue(columnC, entity.getState());
    new EqualsTester().addEqualityGroup(valueA1, valueA2, valueA3).addEqualityGroup(valueAMutated).addEqualityGroup(valueB).addEqualityGroup(valueC).testEquals();
}
Also used : TestEntity(io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity) EqualsTester(com.google.common.testing.EqualsTester) MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) Test(org.junit.Test)

Example 5 with TestEntity

use of io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity in project core-java by SpineEventEngine.

the class ColumnMemoizedValueShould method be_serializable.

@Test
public void be_serializable() {
    final EntityColumn column = findColumn(TestEntity.class, MUTABLE_STATE_COLUMN);
    final TestEntity entity = new TestEntity("my-id");
    entity.setMutableState(42);
    final MemoizedValue value = column.memoizeFor(entity);
    reserializeAndAssert(value);
}
Also used : TestEntity(io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity) MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) Test(org.junit.Test)

Aggregations

TestEntity (io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity)8 Test (org.junit.Test)8 BrokenTestEntity (io.spine.server.entity.storage.given.ColumnTestEnv.BrokenTestEntity)6 MemoizedValue (io.spine.server.entity.storage.EntityColumn.MemoizedValue)5 EqualsTester (com.google.common.testing.EqualsTester)1 Version (io.spine.core.Version)1