Search in sources :

Example 11 with ProjectId

use of io.spine.test.projection.ProjectId 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 12 with ProjectId

use of io.spine.test.projection.ProjectId 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 13 with ProjectId

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

the class StandShould method entityFilterMatcher.

@SuppressWarnings("OverlyComplexAnonymousInnerClass")
private static ArgumentMatcher<EntityFilters> entityFilterMatcher(final Collection<ProjectId> projectIds) {
    // ALL the expected IDs.
    return new ArgumentMatcher<EntityFilters>() {

        @Override
        public boolean matches(EntityFilters argument) {
            boolean everyElementPresent = true;
            for (EntityId entityId : argument.getIdFilter().getIdsList()) {
                final Any idAsAny = entityId.getId();
                final Message rawId = unpack(idAsAny);
                if (rawId instanceof ProjectId) {
                    final ProjectId convertedProjectId = (ProjectId) rawId;
                    everyElementPresent = everyElementPresent && projectIds.contains(convertedProjectId);
                } else {
                    everyElementPresent = false;
                }
            }
            return everyElementPresent;
        }
    };
}
Also used : EntityId(io.spine.client.EntityId) Message(com.google.protobuf.Message) ArgumentMatcher(org.mockito.ArgumentMatcher) EntityFilters(io.spine.client.EntityFilters) ProjectId(io.spine.test.projection.ProjectId) Any(com.google.protobuf.Any)

Example 14 with ProjectId

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

the class ProjectionRepositoryShould method skip_all_the_events_after_catch_up_outdated.

// Due to mockito matcher usage
@SuppressWarnings("unchecked")
@Test
public void skip_all_the_events_after_catch_up_outdated() throws InterruptedException {
    // Set up bounded context
    final BoundedContext boundedContext = TestBoundedContextFactory.MultiTenant.newBoundedContext();
    final int eventsCount = 10;
    final EventStore eventStore = boundedContext.getEventBus().getEventStore();
    for (int i = 0; i < eventsCount; i++) {
        final ProjectId projectId = ProjectId.newBuilder().setId(valueOf(i)).build();
        final Message eventMessage = ProjectCreated.newBuilder().setProjectId(projectId).build();
        final Event event = createEvent(pack(projectId), eventMessage);
        appendEvent(eventStore, event);
    }
    // Set up repository
    final Duration duration = Durations2.nanos(1L);
    final ProjectionRepository repository = spy(new ManualCatchupProjectionRepository(boundedContext, duration));
    repository.initStorage(storageFactory());
    repository.catchUp();
    // Check bulk write
    verify(repository, never()).store(any(Projection.class));
}
Also used : EventStore(io.spine.server.event.EventStore) Message(com.google.protobuf.Message) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) MultiTenant.newBoundedContext(io.spine.testdata.TestBoundedContextFactory.MultiTenant.newBoundedContext) BoundedContext(io.spine.server.BoundedContext) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Example 15 with ProjectId

use of io.spine.test.projection.ProjectId 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

ProjectId (io.spine.test.projection.ProjectId)21 Test (org.junit.Test)13 Project (io.spine.test.projection.Project)6 Any (com.google.protobuf.Any)4 Version (io.spine.core.Version)4 Message (com.google.protobuf.Message)3 Event (io.spine.base.Event)3 Event (io.spine.core.Event)3 TestProjection (io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjection)3 Duration (com.google.protobuf.Duration)2 EntityFilters (io.spine.client.EntityFilters)2 Topic (io.spine.client.Topic)2 GivenVersion (io.spine.core.given.GivenVersion)2 BoundedContext (io.spine.server.BoundedContext)2 StandTestProjection (io.spine.server.stand.Given.StandTestProjection)2 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Task (io.spine.test.projection.Task)2 PrjProjectCreated (io.spine.test.projection.event.PrjProjectCreated)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2