use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class CodecSettingsTest method should_return_string_converting_codecs.
@Test
void should_return_string_converting_codecs() {
Config config = TestConfigUtils.createTestConfig("dsbulk.codec");
CodecSettings settings = new CodecSettings(config);
settings.init();
ConvertingCodecFactory codecFactory = settings.createCodecFactory(false, false);
assertThat(codecFactory.createConvertingCodec(DataTypes.BOOLEAN, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToBooleanCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.TINYINT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToByteCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.SMALLINT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToShortCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.INT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToIntegerCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.BIGINT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToLongCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.FLOAT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToFloatCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.DOUBLE, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToDoubleCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.VARINT, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToBigIntegerCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.DECIMAL, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToBigDecimalCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.DATE, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToLocalDateCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.TIME, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToLocalTimeCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.TIMESTAMP, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToInstantCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.UUID, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToUUIDCodec.class);
assertThat(codecFactory.createConvertingCodec(DataTypes.TIMEUUID, GenericType.STRING, true)).isNotNull().isInstanceOf(StringToUUIDCodec.class);
}
use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class CodecSettingsTest method should_return_codecs_honoring_overflow_strategy.
@Test
void should_return_codecs_honoring_overflow_strategy() {
Config config = TestConfigUtils.createTestConfig("dsbulk.codec", "overflowStrategy", "TRUNCATE");
CodecSettings settings = new CodecSettings(config);
settings.init();
ConvertingCodecFactory codecFactory = settings.createCodecFactory(false, false);
ConvertingCodec<String, Byte> codec = codecFactory.createConvertingCodec(DataTypes.TINYINT, GenericType.STRING, true);
assertThat(codec.externalToInternal("128")).isEqualTo((byte) 127);
}
use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class JsonNodeToMapCodecTest method setUp.
@BeforeEach
void setUp() {
ConversionContext context = new TextConversionContext().setNullStrings("NULL").setFormatNumbers(true).setRoundingMode(HALF_EVEN);
ConvertingCodecFactory codecFactory = new ConvertingCodecFactory(context);
codec = (JsonNodeToMapCodec<Double, List<String>>) codecFactory.<JsonNode, Map<Double, List<String>>>createConvertingCodec(DataTypes.mapOf(DataTypes.DOUBLE, DataTypes.listOf(DataTypes.TEXT)), JSON_NODE_TYPE, true);
}
use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class JsonNodeToSetCodecTest method setUp.
@BeforeEach
void setUp() {
ConversionContext context = new TextConversionContext().setNullStrings("NULL");
ConvertingCodecFactory codecFactory = new ConvertingCodecFactory(context);
codec1 = (JsonNodeToSetCodec<Double>) codecFactory.<JsonNode, Set<Double>>createConvertingCodec(DataTypes.setOf(DataTypes.DOUBLE), JSON_NODE_TYPE, true);
codec2 = (JsonNodeToSetCodec<String>) codecFactory.<JsonNode, Set<String>>createConvertingCodec(DataTypes.setOf(DataTypes.TEXT), JSON_NODE_TYPE, true);
}
use of com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory in project dsbulk by datastax.
the class JsonNodeToShortCodecTest method setUp.
@BeforeEach
void setUp() {
ConversionContext context = new TextConversionContext().setNullStrings("NULL").setFormatNumbers(true);
ConvertingCodecFactory codecFactory = new ConvertingCodecFactory(context);
codec = (JsonNodeToShortCodec) codecFactory.<JsonNode, Short>createConvertingCodec(DataTypes.SMALLINT, JSON_NODE_TYPE, true);
}
Aggregations