Search in sources :

Example 1 with MemoizedValue

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

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

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

the class EntityRecordWithColumnsShould method be_serializable.

@Test
public void be_serializable() {
    final EntityRecord record = Sample.messageOfType(EntityRecord.class);
    final VersionableEntity<?, ?> entity = Given.entityOfClass(TestEntity.class).withVersion(1).build();
    final String columnName = version.name();
    final EntityColumn column = findColumn(VersionableEntity.class, columnName);
    final MemoizedValue value = column.memoizeFor(entity);
    final Map<String, MemoizedValue> columns = singletonMap(columnName, value);
    final EntityRecordWithColumns recordWithColumns = of(record, columns);
    reserializeAndAssert(recordWithColumns);
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) Test(org.junit.Test)

Example 4 with MemoizedValue

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

the class EntityRecordWithColumnsShould method have_equals.

@Test
public void have_equals() {
    final MemoizedValue mockValue = mock(MemoizedValue.class);
    final EntityRecordWithColumns noFieldsEnvelope = of(EntityRecord.getDefaultInstance());
    final EntityRecordWithColumns emptyFieldsEnvelope = of(EntityRecord.getDefaultInstance(), Collections.<String, MemoizedValue>emptyMap());
    final EntityRecordWithColumns notEmptyFieldsEnvelope = of(EntityRecord.getDefaultInstance(), singletonMap("key", mockValue));
    new EqualsTester().addEqualityGroup(noFieldsEnvelope, emptyFieldsEnvelope, notEmptyFieldsEnvelope).addEqualityGroup(newRecord()).addEqualityGroup(// Each one has different EntityRecord
    newRecord()).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) MemoizedValue(io.spine.server.entity.storage.EntityColumn.MemoizedValue) Test(org.junit.Test)

Example 5 with MemoizedValue

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

the class EntityRecordWithColumnsShould method store_column_values.

@Test
public void store_column_values() {
    final MemoizedValue mockValue = mock(MemoizedValue.class);
    final String columnName = "some-key";
    final Map<String, MemoizedValue> columnsExpected = singletonMap(columnName, mockValue);
    final EntityRecordWithColumns record = of(Sample.messageOfType(EntityRecord.class), columnsExpected);
    final Collection<String> columnNames = record.getColumnNames();
    assertSize(1, columnNames);
    assertTrue(columnNames.contains(columnName));
    assertEquals(mockValue, record.getColumnValue(columnName));
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) 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