Search in sources :

Example 11 with Query

use of io.spine.client.Query in project core-java by SpineEventEngine.

the class StandShould method throw_invalid_query_exception_packed_as_IAE_if_invalid_query_message_passed.

@Test
public void throw_invalid_query_exception_packed_as_IAE_if_invalid_query_message_passed() {
    final Stand stand = Stand.newBuilder().build();
    final Query invalidQuery = Query.getDefaultInstance();
    try {
        stand.execute(invalidQuery, StreamObservers.<QueryResponse>noOpObserver());
        fail("Expected IllegalArgumentException due to invalid query message passed," + " but got nothing");
    } catch (IllegalArgumentException e) {
        verifyInvalidQueryException(invalidQuery, e);
    }
}
Also used : Query(io.spine.client.Query) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 12 with Query

use of io.spine.client.Query in project core-java by SpineEventEngine.

the class StandShould method throw_invalid_query_exception_packed_as_IAE_if_querying_unknown_type.

@Test
public void throw_invalid_query_exception_packed_as_IAE_if_querying_unknown_type() {
    final Stand stand = Stand.newBuilder().build();
    checkTypesEmpty(stand);
    // Customer type was NOT registered.
    // So create a query for an unknown type.
    final Query readAllCustomers = requestFactory.query().all(Customer.class);
    try {
        stand.execute(readAllCustomers, StreamObservers.<QueryResponse>noOpObserver());
        fail("Expected IllegalArgumentException upon executing query with unknown target," + " but got nothing");
    } catch (IllegalArgumentException e) {
        verifyUnsupportedQueryTargetException(readAllCustomers, e);
    }
}
Also used : Query(io.spine.client.Query) Test(org.junit.Test) TenantAwareTest(io.spine.server.tenant.TenantAwareTest)

Example 13 with Query

use of io.spine.client.Query in project core-java by SpineEventEngine.

the class QueryBuilderShould method persist_only_last_ids_clause.

@Test
public void persist_only_last_ids_clause() {
    final Iterable<?> genericIds = asList(newUuid(), -1, newMessageId());
    final Long[] longIds = { 1L, 2L, 3L };
    final Message[] messageIds = { newMessageId(), newMessageId(), newMessageId() };
    final String[] stringIds = { newUuid(), newUuid(), newUuid() };
    final Integer[] intIds = { 4, 5, 6 };
    final Query query = factory().query().select(TestEntity.class).byId(genericIds).byId(longIds).byId(stringIds).byId(intIds).byId(messageIds).build();
    assertNotNull(query);
    final Target target = query.getTarget();
    final EntityFilters filters = target.getFilters();
    final Collection<EntityId> entityIds = filters.getIdFilter().getIdsList();
    assertSize(messageIds.length, entityIds);
    final Function<EntityId, ProjectId> transformer = new EntityIdUnpacker<>(ProjectId.class);
    final Iterable<? extends Message> actualValues = transform(entityIds, transformer);
    assertThat(actualValues, containsInAnyOrder(messageIds));
}
Also used : Message(com.google.protobuf.Message) Query(io.spine.client.Query) EntityFilters(io.spine.client.EntityFilters) ProjectId(io.spine.test.validate.msg.ProjectId) Matchers.containsString(org.hamcrest.Matchers.containsString) EntityId(io.spine.client.EntityId) Target(io.spine.client.Target) Test(org.junit.Test)

Example 14 with Query

use of io.spine.client.Query in project core-java by SpineEventEngine.

the class QueryOperationShould method reject_null_input.

@Test(expected = NullPointerException.class)
public void reject_null_input() {
    final Query nullQuery = Tests.nullRef();
    new QueryOperation(nullQuery) {

        @Override
        public void run() {
        // Do nothing;
        }
    };
}
Also used : Query(io.spine.client.Query) Test(org.junit.Test)

Example 15 with Query

use of io.spine.client.Query in project core-java by SpineEventEngine.

the class QueryOperationShould method return_query_id.

@Test
public void return_query_id() {
    final QueryId id = Queries.generateId();
    final Query query = Query.newBuilder().setId(id).build();
    final QueryOperation op = new QueryOperation(query) {

        @Override
        public void run() {
        // Do nothing.
        }
    };
    assertEquals(id, op.queryId());
}
Also used : Query(io.spine.client.Query) QueryId(io.spine.client.QueryId) Test(org.junit.Test)

Aggregations

Query (io.spine.client.Query)22 Test (org.junit.Test)18 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)8 Any (com.google.protobuf.Any)7 Customer (io.spine.test.commandservice.customer.Customer)6 Version (io.spine.core.Version)5 GivenVersion (io.spine.core.given.GivenVersion)5 QueryResponse (io.spine.client.QueryResponse)4 Target (io.spine.client.Target)3 CustomerId (io.spine.test.commandservice.customer.CustomerId)3 TypeUrl (io.spine.type.TypeUrl)3 FieldMask (com.google.protobuf.FieldMask)2 EntityFilters (io.spine.client.EntityFilters)2 EntityId (io.spine.client.EntityId)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 CanIgnoreReturnValue (com.google.errorprone.annotations.CanIgnoreReturnValue)1 Descriptors (com.google.protobuf.Descriptors)1 Message (com.google.protobuf.Message)1 ActorRequestFactory (io.spine.client.ActorRequestFactory)1 EntityIdFilter (io.spine.client.EntityIdFilter)1