Search in sources :

Example 6 with Project

use of io.spine.test.projection.Project in project core-java by SpineEventEngine.

the class ProjectionStorageShould method newState.

@Override
protected Message newState(I id) {
    final String projectId = id.getClass().getName();
    final Project state = Given.project(projectId, "Projection name " + projectId);
    return state;
}
Also used : Project(io.spine.test.projection.Project)

Example 7 with Project

use of io.spine.test.projection.Project in project core-java by SpineEventEngine.

the class ProjectionStorageShould method checkProjectIdIsInList.

@SuppressWarnings("BreakStatement")
private static <I> Project checkProjectIdIsInList(EntityRecord project, List<I> ids) {
    final Any packedState = project.getState();
    final Project state = AnyPacker.unpack(packedState);
    final ProjectId id = state.getId();
    final String stringIdRepr = id.getId();
    boolean isIdPresent = false;
    for (I genericId : ids) {
        isIdPresent = genericId.toString().equals(stringIdRepr);
        if (isIdPresent) {
            break;
        }
    }
    assertTrue(isIdPresent);
    return state;
}
Also used : Project(io.spine.test.projection.Project) ProjectId(io.spine.test.projection.ProjectId) Any(com.google.protobuf.Any)

Example 8 with Project

use of io.spine.test.projection.Project in project core-java by SpineEventEngine.

the class ProjectionStorageShould method read_all_messages_with_field_mask.

@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void read_all_messages_with_field_mask() {
    final List<I> ids = fillStorage(5);
    final String projectDescriptor = Project.getDescriptor().getFullName();
    // clashes with non-related tests.
    @SuppressWarnings("DuplicateStringLiteralInspection") final FieldMask fieldMask = maskForPaths(projectDescriptor + ".id", projectDescriptor + ".name");
    final Map<I, EntityRecord> read = storage.readAll(fieldMask);
    assertSize(ids.size(), read);
    for (Map.Entry<I, EntityRecord> record : read.entrySet()) {
        assertContains(record.getKey(), ids);
        final Any packedState = record.getValue().getState();
        final Project state = AnyPacker.unpack(packedState);
        assertMatchesMask(state, fieldMask);
    }
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.projection.Project) Map(java.util.Map) Any(com.google.protobuf.Any) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 9 with Project

use of io.spine.test.projection.Project in project core-java by SpineEventEngine.

the class StandShould method trigger_subscription_callback_upon_update_of_projection.

@Test
public void trigger_subscription_callback_upon_update_of_projection() {
    final Stand stand = prepareStandWithAggregateRepo(mock(StandStorage.class));
    final Topic allProjects = requestFactory.topic().allOf(Project.class);
    final MemoizeEntityUpdateCallback memoizeCallback = new MemoizeEntityUpdateCallback();
    subscribeAndActivate(stand, allProjects, memoizeCallback);
    assertNull(memoizeCallback.newEntityState);
    final Map.Entry<ProjectId, Project> sampleData = fillSampleProjects(1).entrySet().iterator().next();
    final ProjectId projectId = sampleData.getKey();
    final Project project = sampleData.getValue();
    final Version stateVersion = Tests.newVersionWithNumber(1);
    stand.update(asEnvelope(projectId, project, stateVersion));
    final Any packedState = AnyPacker.pack(project);
    assertEquals(packedState, memoizeCallback.newEntityState);
}
Also used : Project(io.spine.test.projection.Project) Version(io.spine.base.Version) StandStorage(io.spine.server.stand.StandStorage) ProjectId(io.spine.test.projection.ProjectId) Topic(io.spine.client.Topic) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Any(com.google.protobuf.Any) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

Project (io.spine.test.projection.Project)9 Any (com.google.protobuf.Any)5 ProjectId (io.spine.test.projection.ProjectId)5 EntityRecord (io.spine.server.entity.EntityRecord)3 Test (org.junit.Test)3 FieldMask (com.google.protobuf.FieldMask)2 Map (java.util.Map)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 Version (io.spine.base.Version)1 Query (io.spine.client.Query)1 Topic (io.spine.client.Topic)1 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)1 StandStorage (io.spine.server.stand.StandStorage)1 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)1 TypeUrl (io.spine.type.TypeUrl)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1