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));
}
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));
}
}
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;
}
};
}
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));
}
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;
}
Aggregations