use of com.palantir.conjure.spec.FieldDefinition in project conjure by palantir.
the class UnionDefinitionValidatorTest method testUnionMemberKeyMustNotHaveTrailingUnderscore.
@Test
public void testUnionMemberKeyMustNotHaveTrailingUnderscore() {
FieldDefinition fieldDefinition = FieldDefinition.builder().fieldName(FieldName.of("foo_")).type(Type.primitive(PrimitiveType.STRING)).build();
assertThatThrownBy(() -> UnionDefinitionValidator.validateAll(UnionDefinition.builder().union(fieldDefinition).typeName(TypeName.of("string", "")).build())).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Union member key must not end with an underscore: foo_");
}
use of com.palantir.conjure.spec.FieldDefinition in project conjure by palantir.
the class UnionDefinitionValidatorTest method testUnionMemberKeyMustNotBeEmpty.
@Test
public void testUnionMemberKeyMustNotBeEmpty() {
FieldDefinition fieldDefinition = FieldDefinition.builder().fieldName(FieldName.of("")).type(Type.primitive(PrimitiveType.STRING)).build();
assertThatThrownBy(() -> UnionDefinitionValidator.validateAll(UnionDefinition.builder().union(fieldDefinition).typeName(TypeName.of("string", "")).build())).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Union member key must not be empty");
}
use of com.palantir.conjure.spec.FieldDefinition in project conjure by palantir.
the class UnionDefinitionValidatorTest method testUnionMemberKeyMustNotBeIllegalJavaIdentifier.
@Test
public void testUnionMemberKeyMustNotBeIllegalJavaIdentifier() {
ImmutableList.of("%foo", "foo@").forEach(key -> {
FieldDefinition fieldDefinition = FieldDefinition.builder().fieldName(FieldName.of(key)).type(Type.primitive(PrimitiveType.STRING)).build();
assertThatThrownBy(() -> UnionDefinitionValidator.validateAll(UnionDefinition.builder().union(fieldDefinition).typeName(TypeName.of("string", "")).build())).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith(String.format("Union member key must be a valid Java identifier: %s", key));
});
}
use of com.palantir.conjure.spec.FieldDefinition in project conjure by palantir.
the class ErrorDefinitionValidatorTest method testUniqueArgNamesValidator.
@Test
public void testUniqueArgNamesValidator() {
FieldDefinition safeArg1 = FieldDefinition.builder().fieldName(FieldName.of("fooBar")).type(Type.primitive(PrimitiveType.STRING)).build();
FieldDefinition unsafeArg1 = FieldDefinition.builder().fieldName(FieldName.of("foo-bar")).type(Type.primitive(PrimitiveType.STRING)).build();
ErrorDefinition definition1 = ErrorDefinition.builder().errorName(TypeName.of("Foo", "package")).namespace(ErrorNamespace.of("Test")).code(ErrorCode.INVALID_ARGUMENT).safeArgs(safeArg1).unsafeArgs(unsafeArg1).build();
assertThatThrownBy(() -> ErrorDefinitionValidator.validate(definition1)).isInstanceOf(IllegalArgumentException.class).hasMessage("ErrorDefinition must not contain duplicate field names (modulo case normalization): " + "foo-bar vs fooBar");
FieldDefinition safeArg2 = FieldDefinition.builder().fieldName(FieldName.of("foo-bar")).type(Type.primitive(PrimitiveType.STRING)).build();
FieldDefinition unsafeArg2 = FieldDefinition.builder().fieldName(FieldName.of("foo_bar")).type(Type.primitive(PrimitiveType.STRING)).build();
ErrorDefinition definition2 = ErrorDefinition.builder().errorName(TypeName.of("Foo", "package")).namespace(ErrorNamespace.of("Test")).code(ErrorCode.INVALID_ARGUMENT).safeArgs(safeArg2).unsafeArgs(unsafeArg2).build();
assertThatThrownBy(() -> ErrorDefinitionValidator.validate(definition2)).isInstanceOf(IllegalArgumentException.class).hasMessage("ErrorDefinition must not contain duplicate field names (modulo case normalization): " + "foo-bar vs foo_bar");
}
use of com.palantir.conjure.spec.FieldDefinition in project conjure by palantir.
the class FieldDefinitionValidatorTest method testNoComplexKeysInMaps.
@Test
public void testNoComplexKeysInMaps() {
String illegalFieldName = "asdf";
Type complexKeyType = Type.list(ListType.of(Type.primitive(PrimitiveType.STRING)));
FieldDefinition fieldDefinition = FieldDefinition.builder().fieldName(FieldName.of(illegalFieldName)).type(Type.map(MapType.of(complexKeyType, Type.primitive(PrimitiveType.STRING)))).docs(Documentation.of("docs")).build();
assertThatThrownBy(() -> FieldDefinitionValidator.validate(fieldDefinition)).isInstanceOf(IllegalStateException.class).hasMessageContaining(illegalFieldName).hasMessageContaining(complexKeyType.toString());
}
Aggregations