Skip to content

Commit

Permalink
Deprecate YqlType.of() and YqlPrimitiveType.of() for removal; the…
Browse files Browse the repository at this point in the history
…se don't honor the `@Column` annotation

...Stop using these methods in all tests but the `YqlTypeAllTypesTest`
  • Loading branch information
nvamelichev committed Feb 21, 2024
1 parent c7a297c commit 2ef62db
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private Set<String> collectKeyFields(Collection<? extends Entity.Id<T>> ids) {
@Override
protected String declarations() {
var valuesDeclaration = values.keySet().stream()
.map(e -> getDeclaration("$" + e.getPath(), YqlType.of(e.getType()).getYqlTypeName()))
.map(e -> getDeclaration("$" + e.getPath(), YqlType.of(e).getYqlTypeName()))
.collect(joining());

var keysDeclaration = getKeyParams().stream()
Expand Down Expand Up @@ -106,7 +106,7 @@ public List<YqlStatementParam> getParams() {

private List<YqlStatementParam> getValuesParams() {
return this.values.keySet().stream()
.map(x -> new YqlStatementParam(YqlType.of(x.getType()), x.getPath(), false))
.map(x -> new YqlStatementParam(YqlType.of(x), x.getPath(), false))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,13 @@ public static void resetStringDefaultTypeToDefaults() {
VALUE_DEFAULT_YQL_TYPES.put(FieldValueType.ENUM, new ValueYqlTypeSelector(FieldValueType.ENUM, PrimitiveTypeId.STRING, null));
}

/**
* @deprecated Nothing in YOJ calls {@code YqlPrimitiveType.of(Type)} any more.
* <p>Please use {@link #of(JavaField) YqlPrimitiveType.of(JavaField)} because it correcly
* respects the customizations specified in the {@link Column &#64;Column} annotation.
*/
@NonNull
@Deprecated(forRemoval = true)
public static YqlPrimitiveType of(Type javaType) {
return resolveYqlType(javaType, FieldValueType.forJavaType(javaType), null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
public interface YqlType {
ValueProtos.Type.Builder getYqlTypeBuilder();

/**
* @deprecated Nothing in YOJ calls {@code YqlType.of(Type)} any more.
* <p>Please use {@link #of(JavaField) YqlType.of(JavaField)} because it correcly
* respects the customizations specified in the {@link Column &#64;Column} annotation.
*/
@NonNull
@Deprecated(forRemoval = true)
static YqlPrimitiveType of(Type javaType) {
return YqlPrimitiveType.of(javaType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,47 @@ public class YqlTypeTest {

@Test
public void fromYqlMustThrowConversionExceptionIfValueIsNonDeserializable() {
record WithNonDeserializableObject(NonDeserializableObject object) {
}

Schema<WithNonDeserializableObject> schema = new Schema<>(WithNonDeserializableObject.class) {
};

assertThatExceptionOfType(ConversionException.class)
.isThrownBy(() ->
YqlType.of(NonDeserializableObject.class).fromYql(ValueProtos.Value.newBuilder()
YqlType.of(schema.getField("object")).fromYql(ValueProtos.Value.newBuilder()
.setTextValue("{}")
.build())
);
}

@Test
public void toYqlMustThrowConversionExceptionIfValueIsNonSerializable() {
record WithNonSerializableObject(NonSerializableObject object) {
}

Schema<WithNonSerializableObject> schema = new Schema<>(WithNonSerializableObject.class) {
};

assertThatExceptionOfType(ConversionException.class)
.isThrownBy(() -> YqlType.of(NonSerializableObject.class).toYql(new NonSerializableObject()));
.isThrownBy(() -> YqlType.of(schema.getField("object")).toYql(new NonSerializableObject()));
}

@Test
public void unknownEnumValuesAreDeserializedAsNull() {
assertThat(YqlType.of(EmptyEnum.class).fromYql(ValueProtos.Value.newBuilder().setTextValue("UZHOS").build()))
record WithEmptyEnum(EmptyEnum emptyEnum) {
}

Schema<WithEmptyEnum> schema = new Schema<>(WithEmptyEnum.class) {
};

assertThat(YqlType.of(schema.getField("emptyEnum")).fromYql(ValueProtos.Value.newBuilder().setTextValue("UZHOS").build()))
.isNull();
}

@Test
public void testSimpleListResponse() {
Schema schema = new Schema(TestResponse.class) {
Schema<TestResponse> schema = new Schema<>(TestResponse.class) {
};
var actual = YqlType.of(schema.getField("simpleListValue")).fromYql(
ValueProtos.Value.newBuilder()
Expand Down

0 comments on commit 2ef62db

Please sign in to comment.