use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method filter_archived_or_deleted_records_on_by_ID_bulk_read.
@Test
public void filter_archived_or_deleted_records_on_by_ID_bulk_read() {
final I activeId = newId();
final I archivedId = newId();
final I deletedId = newId();
final TestCounterEntity<I> activeEntity = new TestCounterEntity<>(activeId);
final TestCounterEntity<I> archivedEntity = new TestCounterEntity<>(archivedId);
archivedEntity.archive();
final TestCounterEntity<I> deletedEntity = new TestCounterEntity<>(deletedId);
deletedEntity.delete();
final EntityRecord activeRecord = newStorageRecord(activeId, activeEntity.getState());
final EntityRecord archivedRecord = newStorageRecord(archivedId, archivedEntity.getState());
final EntityRecord deletedRecord = newStorageRecord(deletedId, deletedEntity.getState());
final RecordStorage<I> storage = getStorage();
storage.write(deletedId, create(deletedRecord, deletedEntity, storage));
storage.write(activeId, create(activeRecord, activeEntity, storage));
storage.write(archivedId, create(archivedRecord, archivedEntity, storage));
final EntityIdFilter idFilter = EntityIdFilter.newBuilder().addIds(toEntityId(activeId)).addIds(toEntityId(archivedId)).addIds(toEntityId(deletedId)).build();
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).build();
final EntityQuery<I> query = EntityQueries.<I>from(filters, storage).withLifecycleFlags(storage);
final Iterator<EntityRecord> read = storage.readAll(query, FieldMask.getDefaultInstance());
assertSingleRecord(activeRecord, read);
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method write_record_with_columns.
@Test
public void write_record_with_columns() {
final I id = newId();
final EntityRecord record = newStorageRecord(id);
final TestCounterEntity<I> testEntity = new TestCounterEntity<>(id);
final RecordStorage<I> storage = getStorage();
final EntityRecordWithColumns recordWithColumns = create(record, testEntity, storage);
storage.write(id, recordWithColumns);
final RecordReadRequest<I> readRequest = newReadRequest(id);
final Optional<EntityRecord> readRecord = storage.read(readRequest);
assertTrue(readRecord.isPresent());
assertEquals(record, readRecord.get());
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method update_entity_column_values.
@Test
public void update_entity_column_values() {
final Project.Status initialStatus = DONE;
// is used for documentation purposes.
@SuppressWarnings("UnnecessaryLocalVariable") final Project.Status statusAfterUpdate = CANCELLED;
final Int32Value initialStatusValue = Int32Value.newBuilder().setValue(initialStatus.getNumber()).build();
final ColumnFilter status = eq("projectStatusValue", initialStatusValue);
final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder().setOperator(ALL).addFilter(status).build();
final EntityFilters filters = EntityFilters.newBuilder().addFilter(aggregatingFilter).build();
final RecordStorage<I> storage = getStorage();
final EntityQuery<I> query = EntityQueries.from(filters, storage);
final I id = newId();
final TestCounterEntity<I> entity = new TestCounterEntity<>(id);
entity.setStatus(initialStatus);
final EntityRecord record = newStorageRecord(id, newState(id));
final EntityRecordWithColumns recordWithColumns = create(record, entity, storage);
final FieldMask fieldMask = FieldMask.getDefaultInstance();
// Create the record.
storage.write(id, recordWithColumns);
final Iterator<EntityRecord> recordsBefore = storage.readAll(query, fieldMask);
assertSingleRecord(record, recordsBefore);
// Update the entity columns of the record.
entity.setStatus(statusAfterUpdate);
final EntityRecordWithColumns updatedRecordWithColumns = create(record, entity, storage);
storage.write(id, updatedRecordWithColumns);
final Iterator<EntityRecord> recordsAfter = storage.readAll(query, fieldMask);
assertFalse(recordsAfter.hasNext());
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method accept_records_with_empty_storage_fields.
@Test
public void accept_records_with_empty_storage_fields() {
final I id = newId();
final EntityRecord record = newStorageRecord(id);
final EntityRecordWithColumns recordWithStorageFields = EntityRecordWithColumns.of(record);
assertFalse(recordWithStorageFields.hasColumns());
final RecordStorage<I> storage = getStorage();
storage.write(id, recordWithStorageFields);
final RecordReadRequest<I> readRequest = newReadRequest(id);
final Optional<EntityRecord> actualRecord = storage.read(readRequest);
assertTrue(actualRecord.isPresent());
assertEquals(record, actualRecord.get());
}
use of io.spine.server.entity.EntityRecord in project core-java by SpineEventEngine.
the class RecordStorageShould method read_single_record_with_mask.
// Converter nullability issues
@SuppressWarnings("ConstantConditions")
@Test
public void read_single_record_with_mask() {
final I id = newId();
final EntityRecord record = newStorageRecord(id);
final RecordStorage<I> storage = getStorage();
storage.write(id, record);
final Descriptors.Descriptor descriptor = newState(id).getDescriptorForType();
final FieldMask idMask = FieldMasks.maskOf(descriptor, 1);
final RecordReadRequest<I> readRequest = new RecordReadRequest<>(id);
final Optional<EntityRecord> optional = storage.read(readRequest, idMask);
assertTrue(optional.isPresent());
final EntityRecord entityRecord = optional.get();
final Message unpacked = unpack(entityRecord.getState());
assertFalse(isDefault(unpacked));
}
Aggregations