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);
}
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());
}
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);
}
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();
}
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));
}
Aggregations