Search in sources :

Example 46 with EntityRecord

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);
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) EntityIdFilter(io.spine.client.EntityIdFilter) EntityFilters(io.spine.client.EntityFilters) Test(org.junit.Test)

Example 47 with EntityRecord

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());
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) Test(org.junit.Test)

Example 48 with EntityRecord

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());
}
Also used : CompositeColumnFilter(io.spine.client.CompositeColumnFilter) EntityFilters(io.spine.client.EntityFilters) CompositeColumnFilter(io.spine.client.CompositeColumnFilter) ColumnFilter(io.spine.client.ColumnFilter) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) Int32Value(com.google.protobuf.Int32Value) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 49 with EntityRecord

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());
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) Test(org.junit.Test)

Example 50 with EntityRecord

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));
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Message(com.google.protobuf.Message) Descriptors(com.google.protobuf.Descriptors) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

EntityRecord (io.spine.server.entity.EntityRecord)55 Test (org.junit.Test)34 Any (com.google.protobuf.Any)24 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)15 Message (com.google.protobuf.Message)10 Project (io.spine.test.storage.Project)10 TypeUrl (io.spine.type.TypeUrl)9 FieldMask (com.google.protobuf.FieldMask)7 EntityFilters (io.spine.client.EntityFilters)7 ProjectId (io.spine.test.storage.ProjectId)7 ColumnFilter (io.spine.client.ColumnFilter)5 EntityIdFilter (io.spine.client.EntityIdFilter)4 LinkedList (java.util.LinkedList)4 CompositeColumnFilter (io.spine.client.CompositeColumnFilter)3 Version (io.spine.core.Version)3 CompositeQueryParameter (io.spine.server.entity.storage.CompositeQueryParameter)3 EntityColumn (io.spine.server.entity.storage.EntityColumn)3 QueryParameters (io.spine.server.entity.storage.QueryParameters)3 StandStorage (io.spine.server.stand.StandStorage)3 ImmutableList (com.google.common.collect.ImmutableList)2