Search in sources :

Example 1 with Project

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

the class StandShould method fillSampleProjects.

private static Map<ProjectId, Project> fillSampleProjects(int numberOfProjects) {
    final Map<ProjectId, Project> sampleProjects = newHashMap();
    @SuppressWarnings("UnsecureRandomNumberGeneration") final Random randomizer = new Random(Integer.MAX_VALUE);
    for (int projectIndex = 0; projectIndex < numberOfProjects; projectIndex++) {
        final int numericId = randomizer.nextInt();
        final ProjectId customerId = projectIdFor(numericId);
        final Project project = Project.newBuilder().setName(String.valueOf(numericId)).build();
        sampleProjects.put(customerId, project);
    }
    return sampleProjects;
}
Also used : Project(io.spine.test.projection.Project) Random(java.util.Random) ProjectId(io.spine.test.projection.ProjectId)

Example 2 with Project

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

the class StandShould method fillSampleProjects.

private static void fillSampleProjects(Map<ProjectId, Project> sampleProjects, int numberOfProjects) {
    for (int projectIndex = 0; projectIndex < numberOfProjects; projectIndex++) {
        final Project project = Project.getDefaultInstance();
        final ProjectId projectId = ProjectId.newBuilder().setId(UUID.randomUUID().toString()).build();
        sampleProjects.put(projectId, project);
    }
}
Also used : Project(io.spine.test.projection.Project) ProjectId(io.spine.test.projection.ProjectId)

Example 3 with Project

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

the class StandShould method doCheckReadingProjectsById.

private void doCheckReadingProjectsById(int numberOfProjects) {
    // Define the types and values used as a test data.
    final Map<ProjectId, Project> sampleProjects = newHashMap();
    final TypeUrl projectType = TypeUrl.of(Project.class);
    fillSampleProjects(sampleProjects, numberOfProjects);
    final StandTestProjectionRepository projectionRepository = mock(StandTestProjectionRepository.class);
    when(projectionRepository.getEntityStateType()).thenReturn(projectType);
    setupExpectedFindAllBehaviour(sampleProjects, projectionRepository);
    final Stand stand = prepareStandWithProjectionRepo(projectionRepository);
    final Query readMultipleProjects = requestFactory.query().byIds(Project.class, sampleProjects.keySet());
    final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
    stand.execute(readMultipleProjects, responseObserver);
    final List<Any> messageList = checkAndGetMessageList(responseObserver);
    assertEquals(sampleProjects.size(), messageList.size());
    final Collection<Project> allCustomers = sampleProjects.values();
    for (Any singleRecord : messageList) {
        final Project unpackedSingleResult = unpack(singleRecord);
        assertTrue(allCustomers.contains(unpackedSingleResult));
    }
}
Also used : Project(io.spine.test.projection.Project) Query(io.spine.client.Query) ProjectId(io.spine.test.projection.ProjectId) TypeUrl(io.spine.type.TypeUrl) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) Any(com.google.protobuf.Any)

Example 4 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 5 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)

Aggregations

Project (io.spine.test.projection.Project)7 ProjectId (io.spine.test.projection.ProjectId)6 Any (com.google.protobuf.Any)3 Version (io.spine.core.Version)2 Test (org.junit.Test)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 Query (io.spine.client.Query)1 Topic (io.spine.client.Topic)1 Event (io.spine.core.Event)1 GivenVersion (io.spine.core.given.GivenVersion)1 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)1 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)1 TypeUrl (io.spine.type.TypeUrl)1 Map (java.util.Map)1 Random (java.util.Random)1