Search in sources :

Example 1 with StandTestProjectionRepository

use of io.spine.server.stand.Given.StandTestProjectionRepository in project core-java by SpineEventEngine.

the class StandShould method use_provided_executor_upon_update_of_watched_type.

@Test
public void use_provided_executor_upon_update_of_watched_type() {
    final Executor executor = mock(Executor.class);
    final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setCallbackExecutor(executor)).build();
    final Stand stand = boundedContext.getStand();
    final StandTestProjectionRepository standTestProjectionRepo = new StandTestProjectionRepository();
    stand.registerTypeSupplier(standTestProjectionRepo);
    final Topic projectProjections = requestFactory.topic().allOf(Project.class);
    final MemoizingObserver<Subscription> observer = memoizingObserver();
    stand.subscribe(projectProjections, observer);
    final Subscription subscription = observer.firstResponse();
    final StreamObserver<Response> noopObserver = noOpObserver();
    stand.activate(subscription, emptyUpdateCallback(), noopObserver);
    assertNotNull(subscription);
    verify(executor, never()).execute(any(Runnable.class));
    final ProjectId someId = ProjectId.getDefaultInstance();
    final Version stateVersion = GivenVersion.withNumber(1);
    stand.update(asEnvelope(someId, Project.getDefaultInstance(), stateVersion));
    verify(executor, times(1)).execute(any(Runnable.class));
}
Also used : QueryResponse(io.spine.client.QueryResponse) Response(io.spine.core.Response) Executor(java.util.concurrent.Executor) GivenVersion(io.spine.core.given.GivenVersion) Version(io.spine.core.Version) ProjectId(io.spine.test.projection.ProjectId) BoundedContext(io.spine.server.BoundedContext) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) Topic(io.spine.client.Topic) Subscription(io.spine.client.Subscription) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 2 with StandTestProjectionRepository

use of io.spine.server.stand.Given.StandTestProjectionRepository in project core-java by SpineEventEngine.

the class StandShould method prepareStandWithAggregateRepo.

protected Stand prepareStandWithAggregateRepo(StandStorage standStorage) {
    final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(multitenant).setStand(Stand.newBuilder().setStorage(standStorage)).build();
    final Stand stand = boundedContext.getStand();
    assertNotNull(stand);
    final CustomerAggregateRepository customerAggregateRepo = new CustomerAggregateRepository();
    stand.registerTypeSupplier(customerAggregateRepo);
    final StandTestProjectionRepository projectProjectionRepo = new StandTestProjectionRepository();
    stand.registerTypeSupplier(projectProjectionRepo);
    return stand;
}
Also used : BoundedContext(io.spine.server.BoundedContext) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) CustomerAggregateRepository(io.spine.server.Given.CustomerAggregateRepository)

Example 3 with StandTestProjectionRepository

use of io.spine.server.stand.Given.StandTestProjectionRepository 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 StandTestProjectionRepository

use of io.spine.server.stand.Given.StandTestProjectionRepository in project core-java by SpineEventEngine.

the class StandShould method register_projection_repositories.

@Test
public void register_projection_repositories() {
    final boolean multitenant = isMultitenant();
    final BoundedContext boundedContext = BoundedContext.newBuilder().setMultitenant(multitenant).build();
    final Stand stand = boundedContext.getStand();
    checkTypesEmpty(stand);
    final StandTestProjectionRepository standTestProjectionRepo = new StandTestProjectionRepository();
    stand.registerTypeSupplier(standTestProjectionRepo);
    checkHasExactlyOne(stand.getExposedTypes(), Project.getDescriptor());
    final ImmutableSet<TypeUrl> knownAggregateTypes = stand.getExposedAggregateTypes();
    // As we registered a projection repo, known aggregate types should be still empty.
    assertTrue("For some reason an aggregate type was registered", knownAggregateTypes.isEmpty());
    final StandTestProjectionRepository anotherTestProjectionRepo = new StandTestProjectionRepository();
    stand.registerTypeSupplier(anotherTestProjectionRepo);
    checkHasExactlyOne(stand.getExposedTypes(), Project.getDescriptor());
}
Also used : BoundedContext(io.spine.server.BoundedContext) TypeUrl(io.spine.type.TypeUrl) StandTestProjectionRepository(io.spine.server.stand.Given.StandTestProjectionRepository) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Aggregations

StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)4 BoundedContext (io.spine.server.BoundedContext)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 ProjectId (io.spine.test.projection.ProjectId)2 TypeUrl (io.spine.type.TypeUrl)2 Test (org.junit.Test)2 Any (com.google.protobuf.Any)1 Query (io.spine.client.Query)1 QueryResponse (io.spine.client.QueryResponse)1 Subscription (io.spine.client.Subscription)1 Topic (io.spine.client.Topic)1 Response (io.spine.core.Response)1 Version (io.spine.core.Version)1 GivenVersion (io.spine.core.given.GivenVersion)1 CustomerAggregateRepository (io.spine.server.Given.CustomerAggregateRepository)1 Project (io.spine.test.projection.Project)1 Executor (java.util.concurrent.Executor)1