Search in sources :

Example 1 with Int32Value

use of com.google.protobuf.Int32Value in project core-java by SpineEventEngine.

the class IntegerFieldValidatorShould method wrap_to_any.

@Test
public void wrap_to_any() {
    final Any any = validator.wrap(VALUE);
    final Int32Value msg = AnyPacker.unpack(any);
    assertEquals(VALUE, (Integer) msg.getValue());
}
Also used : Int32Value(com.google.protobuf.Int32Value) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 2 with Int32Value

use of com.google.protobuf.Int32Value in project core-java by SpineEventEngine.

the class RecordStorageShould method filter_records_by_columns.

// Complex test case (still tests a single operation)
@SuppressWarnings("OverlyLongMethod")
@Test
public void filter_records_by_columns() {
    final Project.Status requiredValue = Project.Status.DONE;
    final Int32Value wrappedValue = Int32Value.newBuilder().setValue(requiredValue.getNumber()).build();
    final Version versionValue = Version.newBuilder().setNumber(// Value of the counter after one columns
    2).build();
    final EntityFilters filters = EntityFilters.newBuilder().putColumnFilter("projectStatusValue", AnyPacker.pack(wrappedValue)).putColumnFilter("counterVersion", AnyPacker.pack(versionValue)).build();
    final EntityQuery<I> query = EntityQueries.from(filters, TestCounterEntity.class);
    final I idMatching = newId();
    final I idWrong1 = newId();
    final I idWrong2 = newId();
    final TestCounterEntity<I> matchingEntity = new TestCounterEntity<>(idMatching);
    final TestCounterEntity<I> wrongEntity1 = new TestCounterEntity<>(idWrong1);
    final TestCounterEntity<I> wrongEntity2 = new TestCounterEntity<>(idWrong2);
    // 2 of 3 have required values
    matchingEntity.setStatus(requiredValue);
    wrongEntity1.setStatus(requiredValue);
    wrongEntity2.setStatus(Project.Status.CANCELLED);
    // Change internal Entity state
    wrongEntity1.getCounter();
    // After the mutation above the single matching record is the one under the `idMatching` ID
    final EntityRecord fineRecord = newStorageRecord(idMatching, newState(idMatching));
    final EntityRecord notFineRecord1 = newStorageRecord(idWrong1, newState(idWrong1));
    final EntityRecord notFineRecord2 = newStorageRecord(idWrong2, newState(idWrong2));
    final EntityRecordWithColumns recordRight = create(fineRecord, matchingEntity);
    final EntityRecordWithColumns recordWrong1 = create(notFineRecord1, wrongEntity1);
    final EntityRecordWithColumns recordWrong2 = create(notFineRecord2, wrongEntity2);
    final RecordStorage<I> storage = getStorage();
    storage.write(idMatching, recordRight);
    storage.write(idWrong1, recordWrong1);
    storage.write(idWrong2, recordWrong2);
    final Map<I, EntityRecord> readRecords = storage.readAll(query, FieldMask.getDefaultInstance());
    Verify.assertSize(1, readRecords);
    final I singleId = readRecords.keySet().iterator().next();
    assertEquals(idMatching, singleId);
    final EntityRecord singleRecord = readRecords.values().iterator().next();
    assertEquals(fineRecord, singleRecord);
}
Also used : EntityFilters(io.spine.client.EntityFilters) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) EntityRecord(io.spine.server.entity.EntityRecord) Project(io.spine.test.storage.Project) Version(io.spine.base.Version) Int32Value(com.google.protobuf.Int32Value) Test(org.junit.Test)

Example 3 with Int32Value

use of com.google.protobuf.Int32Value in project core-java by SpineEventEngine.

the class IdentifiersShould method convert_to_string_integer_id_wrapped_into_message.

@Test
public void convert_to_string_integer_id_wrapped_into_message() {
    final Integer value = 1024;
    final Int32Value id = forInteger(value);
    final String expected = value.toString();
    final String actual = idToString(id);
    assertEquals(expected, actual);
}
Also used : Wrapper.forInteger(io.spine.protobuf.Wrapper.forInteger) Int32Value(com.google.protobuf.Int32Value) Identifiers.idToString(io.spine.base.Identifiers.idToString) Wrapper.forString(io.spine.protobuf.Wrapper.forString) Test(org.junit.Test)

Example 4 with Int32Value

use of com.google.protobuf.Int32Value in project core-java by SpineEventEngine.

the class ProcessManagerShould method throw_exception_if_dispatch_unknown_command.

@Test(expected = IllegalStateException.class)
public void throw_exception_if_dispatch_unknown_command() {
    final Int32Value unknownCommand = Int32Value.getDefaultInstance();
    final CommandEnvelope envelope = CommandEnvelope.of(requestFactory.command().create(unknownCommand));
    processManager.dispatchCommand(envelope);
}
Also used : Int32Value(com.google.protobuf.Int32Value) CommandEnvelope(io.spine.envelope.CommandEnvelope) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Example 5 with Int32Value

use of com.google.protobuf.Int32Value in project core-java by SpineEventEngine.

the class QueryBuilderShould method create_queries_with_param.

@Test
public void create_queries_with_param() {
    final String columnName = "myImaginaryColumn";
    final Object columnValue = 42;
    final Query query = factory().query().select(TestEntity.class).where(eq(columnName, columnValue)).build();
    assertNotNull(query);
    final Target target = query.getTarget();
    assertFalse(target.getIncludeAll());
    final EntityFilters entityFilters = target.getFilters();
    final Map<String, Any> columnFilters = entityFilters.getColumnFilterMap();
    assertSize(1, columnFilters);
    final Any actualValue = columnFilters.get(columnName);
    assertNotNull(columnValue);
    final Int32Value messageValue = AnyPacker.unpack(actualValue);
    final int actualGenericValue = messageValue.getValue();
    assertEquals(columnValue, actualGenericValue);
}
Also used : Target(io.spine.client.Target) Query(io.spine.client.Query) EntityFilters(io.spine.client.EntityFilters) Int32Value(com.google.protobuf.Int32Value) Matchers.containsString(org.hamcrest.Matchers.containsString) Any(com.google.protobuf.Any) Test(org.junit.Test)

Aggregations

Int32Value (com.google.protobuf.Int32Value)5 Test (org.junit.Test)5 Any (com.google.protobuf.Any)2 EntityFilters (io.spine.client.EntityFilters)2 Identifiers.idToString (io.spine.base.Identifiers.idToString)1 Version (io.spine.base.Version)1 Query (io.spine.client.Query)1 Target (io.spine.client.Target)1 CommandEnvelope (io.spine.envelope.CommandEnvelope)1 Wrapper.forInteger (io.spine.protobuf.Wrapper.forInteger)1 Wrapper.forString (io.spine.protobuf.Wrapper.forString)1 EntityRecord (io.spine.server.entity.EntityRecord)1 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)1 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)1 Project (io.spine.test.storage.Project)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1