Search in sources :

Example 6 with MemoizedValue

use of io.spine.server.entity.storage.EntityColumn.MemoizedValue in project core-java by SpineEventEngine.

the class RecordStorageShould method withLifecycleColumns.

protected static EntityRecordWithColumns withLifecycleColumns(EntityRecord record) {
    final LifecycleFlags flags = record.getLifecycleFlags();
    final Map<String, MemoizedValue> columns = ImmutableMap.of(LifecycleColumns.ARCHIVED.columnName(), booleanColumn(LifecycleColumns.ARCHIVED.column(), flags.getArchived()), LifecycleColumns.DELETED.columnName(), booleanColumn(LifecycleColumns.DELETED.column(), flags.getDeleted()));
    final EntityRecordWithColumns result = createRecord(record, columns);
    return result;
}
Also used : MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) LifecycleFlags(io.spine.server.entity.LifecycleFlags)

Example 7 with MemoizedValue

use of io.spine.server.entity.storage.EntityColumn.MemoizedValue in project core-java by SpineEventEngine.

the class RecordStorageShould method booleanColumn.

private static MemoizedValue booleanColumn(EntityColumn column, boolean value) {
    final MemoizedValue memoizedValue = mock(MemoizedValue.class);
    when(memoizedValue.getSourceColumn()).thenReturn(column);
    when(memoizedValue.getValue()).thenReturn(value);
    return memoizedValue;
}
Also used : MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue)

Example 8 with MemoizedValue

use of io.spine.server.entity.storage.EntityColumn.MemoizedValue 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 9 with MemoizedValue

use of io.spine.server.entity.storage.EntityColumn.MemoizedValue 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)

Example 10 with MemoizedValue

use of io.spine.server.entity.storage.EntityColumn.MemoizedValue in project core-java by SpineEventEngine.

the class ColumnShould method memoize_value_regarding_nulls.

@Test
public void memoize_value_regarding_nulls() {
    final EntityColumn nullableColumn = forMethod("getNull", TestEntity.class);
    final MemoizedValue memoizedNull = nullableColumn.memoizeFor(new TestEntity(""));
    assertTrue(memoizedNull.isNull());
    assertNull(memoizedNull.getValue());
}
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)

Aggregations

MemoizedValue (io.spine.server.entity.storage.EntityColumn.MemoizedValue)12 Test (org.junit.Test)8 TestEntity (io.spine.server.entity.storage.given.ColumnTestEnv.TestEntity)5 BrokenTestEntity (io.spine.server.entity.storage.given.ColumnTestEnv.BrokenTestEntity)3 EqualsTester (com.google.common.testing.EqualsTester)2 EntityRecord (io.spine.server.entity.EntityRecord)2 LifecycleFlags (io.spine.server.entity.LifecycleFlags)1 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)1