Search in sources :

Example 41 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class AggregateTestEnv method typeUrlOf.

/**
 * Obtains the {@link TypeUrl} of the message from the provided event.
 */
public static TypeUrl typeUrlOf(Event event) {
    final Any message = event.getMessage();
    final TypeUrl result = TypeUrl.parse(message.getTypeUrl());
    return result;
}
Also used : TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any)

Example 42 with TypeUrl

use of io.spine.type.TypeUrl 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)

Example 43 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class StandStorageShould method checkByTypeRead.

// OK for this test.
@SuppressWarnings({ "MethodWithMultipleLoops", "ConstantConditions" })
private void checkByTypeRead(FieldMask fieldMask) {
    final boolean withFieldMask = !fieldMask.equals(FieldMask.getDefaultInstance());
    final StandStorage storage = getStorage();
    final TypeUrl type = TypeUrl.from(Project.getDescriptor());
    final int projectsCount = 4;
    final List<AggregateStateId> projectIds = fill(storage, projectsCount, DEFAULT_ID_SUPPLIER);
    final int tasksCount = 5;
    for (int i = 0; i < tasksCount; i++) {
        final TaskId genericId = TaskId.newBuilder().setId(i).build();
        final AggregateStateId id = AggregateStateId.of(genericId, TypeUrl.from(Task.getDescriptor()));
        final Task task = Task.newBuilder().setTaskId(genericId).setTitle("Test task").setDescription("With description").build();
        final EntityRecord record = newRecord(task);
        storage.write(id, record);
    }
    final Iterator<EntityRecord> readRecords = withFieldMask ? storage.readAllByType(TypeUrl.from(Project.getDescriptor()), fieldMask) : storage.readAllByType(TypeUrl.from(Project.getDescriptor()));
    final Set<EntityRecord> readDistinct = Sets.newHashSet(readRecords);
    assertSize(projectsCount, readDistinct);
    for (EntityRecord record : readDistinct) {
        final Any state = record.getState();
        final Project project = AnyPacker.unpack(state);
        final AggregateStateId restored = AggregateStateId.of(project.getId(), type);
        assertContains(restored, projectIds);
        if (withFieldMask) {
            assertMatchesMask(project, fieldMask);
        }
    }
}
Also used : Task(io.spine.test.storage.Task) TaskId(io.spine.test.storage.TaskId) TypeUrl(io.spine.type.TypeUrl) Any(com.google.protobuf.Any) EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project)

Example 44 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class SubscriptionService method selectBoundedContext.

private BoundedContext selectBoundedContext(Target target) {
    final TypeUrl type = TypeUrl.parse(target.getType());
    final BoundedContext result = typeToContextMap.get(type);
    return result;
}
Also used : TypeUrl(io.spine.type.TypeUrl)

Example 45 with TypeUrl

use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.

the class CommandsShould method obtain_type_url_of_command.

@Test
public void obtain_type_url_of_command() {
    final ActorRequestFactory factory = TestActorRequestFactory.newInstance(CommandsShould.class);
    final StringValue message = toMessage(Identifier.newUuid());
    final Command command = factory.command().create(message);
    final TypeUrl typeUrl = CommandEnvelope.of(command).getTypeName().toUrl();
    assertEquals(TypeUrl.of(StringValue.class), typeUrl);
}
Also used : ActorRequestFactory(io.spine.client.ActorRequestFactory) TestActorRequestFactory(io.spine.client.TestActorRequestFactory) TypeUrl(io.spine.type.TypeUrl) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Aggregations

TypeUrl (io.spine.type.TypeUrl)46 Test (org.junit.Test)15 Any (com.google.protobuf.Any)14 EntityRecord (io.spine.server.entity.EntityRecord)8 Message (com.google.protobuf.Message)7 BoundedContext (io.spine.server.BoundedContext)5 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)3 ClassName (io.spine.type.ClassName)3 Descriptors (com.google.protobuf.Descriptors)2 StringValue (com.google.protobuf.StringValue)2 Error (io.spine.base.Error)2 Query (io.spine.client.Query)2 Ack (io.spine.core.Ack)2 Command (io.spine.core.Command)2 Event (io.spine.core.Event)2 Rejection (io.spine.core.Rejection)2 TenantId (io.spine.core.TenantId)2 Version (io.spine.core.Version)2 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)2 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)2