use of net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_DATA in project providence by morimekta.
the class MessageRowMapperTest method testDefaultMapping.
@Test
public void testDefaultMapping() {
generator.setFillRate(1.0).setMaxCollectionItems(16).withGenerator(CompactFields.kDescriptor, g -> {
g.setValueGenerator(CompactFields._Field.NAME, ctx -> ctx.getFairy().textProducer().latinWord());
g.setValueGenerator(CompactFields._Field.LABEL, ctx -> ctx.getFairy().textProducer().word());
}).withGenerator(NormalFields.kDescriptor, g -> {
g.setValueGenerator(NormalFields._Field.NAME, ctx -> ctx.getFairy().textProducer().latinWord());
g.setValueGenerator(NormalFields._Field.LABEL, ctx -> ctx.getFairy().textProducer().word());
});
OptionalFields expected = generator.generate(OptionalFields.kDescriptor).mutate().setId(1234).setTimestampS((int) clock.instant().getEpochSecond()).setTimestampMs(clock.instant().getEpochSecond() * 1000).build();
OptionalFields empty = OptionalFields.builder().setId(2345).build();
try (Handle handle = db.getDBI().open()) {
handle.createUpdate("INSERT INTO mappings_v3.default_mappings (" + " id, present, tiny, small, medium, large, real," + " fib, name, data, compact," + " timestamp_s, timestamp_ms," + " binary_message, blob_message, other_message," + " blob_data, base64_data, int_bool" + ") VALUES (" + " :e.id," + " :e.present," + " :e.tiny," + " :e.small," + " :e.medium," + " :e.large," + " :e.real," + " :e.fib," + " :e.name," + " :e.data," + " :e.message," + " :timestamp_s," + " :e.timestamp_ms," + " :e.binary_message," + " :e.blob_message," + " :e.clob_message," + " :e.blob_data," + " :e.base64_data," + " :e.int_bool" + ")").bind("timestamp_s", toField(expected, TIMESTAMP_S, Types.TIMESTAMP)).bindNamedArgumentFinder(forMessage("e", expected, withType(TIMESTAMP_MS, Types.TIMESTAMP), withType(BINARY_MESSAGE, Types.BINARY), withType(BLOB_MESSAGE, Types.BLOB), withType(CLOB_MESSAGE, Types.CLOB), withType(BLOB_DATA, Types.BLOB), withType(BASE64_DATA, Types.VARCHAR))).execute();
handle.createUpdate("INSERT INTO mappings_v3.default_mappings (" + " id, present, tiny, small, medium, large, real," + " fib, name, data, compact," + " timestamp_s, timestamp_ms," + " binary_message, blob_message, other_message," + " blob_data, base64_data, int_bool" + ") VALUES (" + " :id," + " :present," + " :tiny," + " :small," + " :medium," + " :large," + " :real," + " :fib," + " :name," + " :data," + " :message," + " :timestamp_s," + " :timestamp_ms," + " :binary_message," + " :blob_message," + " :clob_message," + " :blob_data," + " :base64_data," + " :int_bool" + ")").bind("timestamp_s", toField(empty, TIMESTAMP_S, Types.TIMESTAMP)).bindNamedArgumentFinder(forMessage(empty, withType(TIMESTAMP_MS, Types.TIMESTAMP), withType(BINARY_MESSAGE, Types.BINARY), withType(BLOB_MESSAGE, Types.BLOB), withType(CLOB_MESSAGE, Types.CLOB), withType(BLOB_DATA, Types.BLOB), withType(BASE64_DATA, Types.VARCHAR), withType(INT_BOOL, Types.INTEGER))).execute();
OptionalFields val = handle.createQuery("SELECT m.* FROM mappings_v3.default_mappings m WHERE id = :id").bind("id", toField(expected, ID)).map(toMessage("default_mappings", OptionalFields.kDescriptor, columnsFromAllFields(), withColumn("compact", MESSAGE), withColumn("other_message", CLOB_MESSAGE))).findFirst().orElseThrow(() -> new AssertionError("No content in default_mappings"));
OptionalFields val2 = handle.createQuery("SELECT * FROM mappings_v3.default_mappings WHERE id = :id").bind("id", toField(empty, ID)).map(toMessage(OptionalFields.kDescriptor, columnsFromAllFields(), withColumn("compact", MESSAGE), withColumn("other_message", CLOB_MESSAGE))).findFirst().orElseThrow(() -> new AssertionError("No content in default_mappings"));
assertThat(val, is(equalToMessage(expected)));
assertThat(val2, is(equalToMessage(empty)));
}
}
use of net.morimekta.test.providence.storage.jdbc.OptionalFields._Field.BLOB_DATA in project providence by morimekta.
the class MessageRowMapperTest method testDefaultMapping.
@Test
public void testDefaultMapping() {
generator.setFillRate(1.0).setMaxCollectionItems(16).withGenerator(CompactFields.kDescriptor, g -> {
g.setValueGenerator(CompactFields._Field.NAME, ctx -> ctx.getFairy().textProducer().latinWord());
g.setValueGenerator(CompactFields._Field.LABEL, ctx -> ctx.getFairy().textProducer().word());
}).withGenerator(NormalFields.kDescriptor, g -> {
g.setValueGenerator(NormalFields._Field.NAME, ctx -> ctx.getFairy().textProducer().latinWord());
g.setValueGenerator(NormalFields._Field.LABEL, ctx -> ctx.getFairy().textProducer().word());
});
OptionalFields expected = generator.generate(OptionalFields.kDescriptor).mutate().setId(1234).setTimestampS((int) clock.instant().getEpochSecond()).setTimestampMs(clock.instant().getEpochSecond() * 1000).build();
OptionalFields empty = OptionalFields.builder().setId(2345).build();
try (Handle handle = db.getDBI().open()) {
handle.createStatement("INSERT INTO mappings.default_mappings (" + " id, present, tiny, small, medium, large, real," + " fib, name, data, compact," + " timestamp_s, timestamp_ms," + " binary_message, blob_message, other_message," + " blob_data, base64_data, int_bool" + ") VALUES (" + " :e.id," + " :e.present," + " :e.tiny," + " :e.small," + " :e.medium," + " :e.large," + " :e.real," + " :e.fib," + " :e.name," + " :e.data," + " :e.message," + " :timestamp_s," + " :e.timestamp_ms," + " :e.binary_message," + " :e.blob_message," + " :e.clob_message," + " :e.blob_data," + " :e.base64_data," + " :e.int_bool" + ")").bind("timestamp_s", ProvidenceJdbi.toField(expected, TIMESTAMP_S, Types.TIMESTAMP)).bindNamedArgumentFinder(ProvidenceJdbi.forMessage("e", expected, ProvidenceJdbi.withType(TIMESTAMP_MS, Types.TIMESTAMP), ProvidenceJdbi.withType(BINARY_MESSAGE, Types.BINARY), ProvidenceJdbi.withType(BLOB_MESSAGE, Types.BLOB), ProvidenceJdbi.withType(CLOB_MESSAGE, Types.CLOB), ProvidenceJdbi.withType(BLOB_DATA, Types.BLOB), ProvidenceJdbi.withType(BASE64_DATA, Types.VARCHAR))).execute();
handle.createStatement("INSERT INTO mappings.default_mappings (" + " id, present, tiny, small, medium, large, real," + " fib, name, data, compact," + " timestamp_s, timestamp_ms," + " binary_message, blob_message, other_message," + " blob_data, base64_data, int_bool" + ") VALUES (" + " :id," + " :present," + " :tiny," + " :small," + " :medium," + " :large," + " :real," + " :fib," + " :name," + " :data," + " :message," + " :timestamp_s," + " :timestamp_ms," + " :binary_message," + " :blob_message," + " :clob_message," + " :blob_data," + " :base64_data," + " :int_bool" + ")").bind("timestamp_s", ProvidenceJdbi.toField(empty, TIMESTAMP_S, Types.TIMESTAMP)).bindNamedArgumentFinder(ProvidenceJdbi.forMessage(empty, ProvidenceJdbi.withType(TIMESTAMP_MS, Types.TIMESTAMP), ProvidenceJdbi.withType(BINARY_MESSAGE, Types.BINARY), ProvidenceJdbi.withType(BLOB_MESSAGE, Types.BLOB), ProvidenceJdbi.withType(CLOB_MESSAGE, Types.CLOB), ProvidenceJdbi.withType(BLOB_DATA, Types.BLOB), ProvidenceJdbi.withType(BASE64_DATA, Types.VARCHAR), ProvidenceJdbi.withType(INT_BOOL, Types.INTEGER))).execute();
OptionalFields val = handle.createQuery("SELECT m.* FROM mappings.default_mappings m WHERE id = :id").bind("id", ProvidenceJdbi.toField(expected, ID)).map(ProvidenceJdbi.toMessage("default_mappings", OptionalFields.kDescriptor, ProvidenceJdbi.columnsFromAllFields(), ProvidenceJdbi.withColumn("compact", MESSAGE), ProvidenceJdbi.withColumn("other_message", CLOB_MESSAGE))).first();
OptionalFields val2 = handle.createQuery("SELECT * FROM mappings.default_mappings WHERE id = :id").bind("id", ProvidenceJdbi.toField(empty, ID)).map(ProvidenceJdbi.toMessage(OptionalFields.kDescriptor, ProvidenceJdbi.columnsFromAllFields(), ProvidenceJdbi.withColumn("compact", MESSAGE), ProvidenceJdbi.withColumn("other_message", CLOB_MESSAGE))).first();
assertThat(val, is(equalToMessage(expected)));
assertThat(val2, is(equalToMessage(empty)));
}
}
Aggregations