use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class StandShould method operate_with_storage_provided_through_builder.
@SuppressWarnings("OverlyCoupledMethod")
@Test
public void operate_with_storage_provided_through_builder() {
final StandStorage standStorageMock = mock(StandStorage.class);
final BoundedContext boundedContext = BoundedContext.newBuilder().setStand(Stand.newBuilder().setStorage(standStorageMock)).build();
final Stand stand = boundedContext.getStand();
assertNotNull(stand);
final io.spine.server.Given.CustomerAggregateRepository customerAggregateRepo = new io.spine.server.Given.CustomerAggregateRepository(boundedContext);
stand.registerTypeSupplier(customerAggregateRepo);
final int numericIdValue = 17;
final CustomerId customerId = customerIdFor(numericIdValue);
final io.spine.server.Given.CustomerAggregate customerAggregate = customerAggregateRepo.create(customerId);
final Customer customerState = customerAggregate.getState();
final TypeUrl customerType = TypeUrl.of(Customer.class);
final Version stateVersion = Tests.newVersionWithNumber(1);
verify(standStorageMock, never()).write(any(AggregateStateId.class), any(EntityRecordWithColumns.class));
stand.update(asEnvelope(customerId, customerState, stateVersion));
final AggregateStateId expectedAggregateStateId = AggregateStateId.of(customerId, customerType);
final Any packedState = AnyPacker.pack(customerState);
final EntityRecord expectedRecord = EntityRecord.newBuilder().setState(packedState).build();
verify(standStorageMock, times(1)).write(eq(expectedAggregateStateId), recordStateMatcher(expectedRecord));
}
use of io.spine.type.TypeUrl 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 = AnyPacker.unpack(singleRecord);
assertTrue(allCustomers.contains(unpackedSingleResult));
}
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class MatchFilter method checkEventType.
private boolean checkEventType(Message message) {
final TypeUrl actualTypeUrl = TypeUrl.of(message);
if (eventTypeUrl == null) {
return true;
}
final boolean result = actualTypeUrl.equals(eventTypeUrl);
return result;
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class MatchFilter method getEventTypeUrl.
@Nullable
private static TypeUrl getEventTypeUrl(EventFilter filter) {
final String eventType = filter.getEventType();
final TypeUrl result = eventType.isEmpty() ? null : TypeName.of(eventType).toUrl();
return result;
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class Sample method messageValueFor.
private static Message messageValueFor(FieldDescriptor field) {
final TypeUrl messageType = TypeUrl.from(field.getMessageType());
final Class<? extends Message> javaClass = classFor(messageType);
final Message fieldValue = messageOfType(javaClass);
return fieldValue;
}
Aggregations