Search in sources :

Example 16 with TypeUrl

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));
}
Also used : StreamObservers.noOpObserver(io.spine.io.StreamObservers.noOpObserver) StreamObserver(io.grpc.stub.StreamObserver) MemoizingObserver(io.spine.io.StreamObservers.MemoizingObserver) StreamObservers.memoizingObserver(io.spine.io.StreamObservers.memoizingObserver) Customer(io.spine.test.commandservice.customer.Customer) TypeUrl(io.spine.type.TypeUrl) CustomerId(io.spine.test.commandservice.customer.CustomerId) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) EntityRecord(io.spine.server.entity.EntityRecord) Version(io.spine.base.Version) StandStorage(io.spine.server.stand.StandStorage) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 17 with TypeUrl

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));
    }
}
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 18 with TypeUrl

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;
}
Also used : TypeUrl(io.spine.type.TypeUrl)

Example 19 with TypeUrl

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;
}
Also used : TypeUrl(io.spine.type.TypeUrl) Nullable(javax.annotation.Nullable)

Example 20 with TypeUrl

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;
}
Also used : Message(com.google.protobuf.Message) TypeUrl(io.spine.type.TypeUrl)

Aggregations

TypeUrl (io.spine.type.TypeUrl)37 Any (com.google.protobuf.Any)12 Test (org.junit.Test)11 EntityRecord (io.spine.server.entity.EntityRecord)7 Message (com.google.protobuf.Message)6 StandStorage (io.spine.server.stand.StandStorage)4 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)3 ClassName (io.spine.type.ClassName)3 TypeName (io.spine.type.TypeName)3 Descriptors (com.google.protobuf.Descriptors)2 Version (io.spine.base.Version)2 Query (io.spine.client.Query)2 BoundedContext (io.spine.server.BoundedContext)2 StandTestProjectionRepository (io.spine.server.stand.Given.StandTestProjectionRepository)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 Customer (io.spine.test.commandservice.customer.Customer)2 CustomerId (io.spine.test.commandservice.customer.CustomerId)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1