use of com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder in project java-driver by datastax.
the class TermTest method should_generate_literal_terms.
@Test
public void should_generate_literal_terms() {
assertThat(literal(1)).hasCql("1");
assertThat(literal("foo")).hasCql("'foo'");
assertThat(literal(ImmutableList.of(1, 2, 3))).hasCql("[1,2,3]");
TupleType tupleType = DataTypes.tupleOf(DataTypes.INT, DataTypes.TEXT);
TupleValue tupleValue = tupleType.newValue().setInt(0, 1).setString(1, "foo");
assertThat(literal(tupleValue)).hasCql("(1,'foo')");
UserDefinedType udtType = new UserDefinedTypeBuilder(CqlIdentifier.fromCql("ks"), CqlIdentifier.fromCql("user")).withField(CqlIdentifier.fromCql("first_name"), DataTypes.TEXT).withField(CqlIdentifier.fromCql("last_name"), DataTypes.TEXT).build();
UdtValue udtValue = udtType.newValue().setString("first_name", "Jane").setString("last_name", "Doe");
assertThat(literal(udtValue)).hasCql("{first_name:'Jane',last_name:'Doe'}");
assertThat(literal(null)).hasCql("NULL");
assertThat(literal(Charsets.UTF_8, new CharsetCodec())).hasCql("'UTF-8'");
assertThat(literal(Charsets.UTF_8, CharsetCodec.TEST_REGISTRY)).hasCql("'UTF-8'");
}
Aggregations