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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations