org.jboss.jandex.FieldInfo Java Examples

The following examples show how to use org.jboss.jandex.FieldInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JandexProtoGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<ClassInfo> extractDataClasses(Collection<ClassInfo> input, String targetDirectory) {
    Set<ClassInfo> dataModelClasses = new HashSet<>();
    for (ClassInfo modelClazz : input) {
        try {
            for (FieldInfo pd : modelClazz.fields()) {

                if (pd.type().name().toString().startsWith("java.lang")
                        || pd.type().name().toString().equals(Date.class.getCanonicalName())) {
                    continue;
                }

                dataModelClasses.add(index.getClassByName(pd.type().name()));
            }

            generateModelClassProto(modelClazz, targetDirectory);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    return dataModelClasses;
}
 
Example #2
Source File: Types.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static Set<Type> getProducerFieldTypeClosure(FieldInfo producerField, BeanDeployment beanDeployment) {
    Set<Type> types;
    Type fieldType = producerField.type();
    if (fieldType.kind() == Kind.PRIMITIVE || fieldType.kind() == Kind.ARRAY) {
        types = new HashSet<>();
        types.add(fieldType);
        types.add(OBJECT_TYPE);
    } else {
        ClassInfo fieldClassInfo = getClassByName(beanDeployment.getIndex(), producerField.type());
        if (fieldClassInfo == null) {
            throw new IllegalArgumentException("Producer field type not found in index: " + producerField.type().name());
        }
        if (Kind.CLASS.equals(fieldType.kind())) {
            types = getTypeClosure(fieldClassInfo, producerField, Collections.emptyMap(), beanDeployment, null);
        } else if (Kind.PARAMETERIZED_TYPE.equals(fieldType.kind())) {
            types = getTypeClosure(fieldClassInfo, producerField,
                    buildResolvedMap(fieldType.asParameterizedType().arguments(), fieldClassInfo.typeParameters(),
                            Collections.emptyMap(), beanDeployment.getIndex()),
                    beanDeployment, null);
        } else {
            throw new IllegalArgumentException("Unsupported return type");
        }
    }
    return restrictBeanTypes(types, beanDeployment.getAnnotations(producerField));
}
 
Example #3
Source File: JpaSecurityDefinition.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public static FieldOrMethod getFieldOrMethod(Index index, ClassInfo annotatedClass,
        AnnotationTarget annotatedFieldOrMethod, boolean isPanache) {
    switch (annotatedFieldOrMethod.kind()) {
        case FIELD:
            // try to find a getter for this field
            FieldInfo field = annotatedFieldOrMethod.asField();
            return new FieldOrMethod(field,
                    findGetter(index, annotatedClass, field, Modifier.isPublic(field.flags()) && isPanache));
        case METHOD:
            // skip the field entirely
            return new FieldOrMethod(null, annotatedFieldOrMethod.asMethod());
        default:
            throw new IllegalArgumentException(
                    "annotatedFieldOrMethod must be a field or method: " + annotatedFieldOrMethod);
    }
}
 
Example #4
Source File: MethodNameParser.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Looks for the field in either the class itself or in a superclass that is annotated with @MappedSuperClass
 */
private FieldInfo getAssociatedEntityClassField(String associatedEntityFieldName, ClassInfo associatedEntityClassInfo) {
    FieldInfo fieldInfo = associatedEntityClassInfo.field(associatedEntityFieldName);
    if (fieldInfo != null) {
        return fieldInfo;
    }
    if (DotNames.OBJECT.equals(associatedEntityClassInfo.superName())) {
        return null;
    }

    ClassInfo superClassInfo = indexView.getClassByName(associatedEntityClassInfo.superName());
    if (superClassInfo.classAnnotation(DotNames.JPA_MAPPED_SUPERCLASS) == null) {
        return null;
    }

    return getAssociatedEntityClassField(associatedEntityFieldName, superClassInfo);
}
 
Example #5
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**********************************************************************/

    @Test
    public void testStringNotBlankNotNull() {
        FieldInfo targetField = targetClass.field("stringNotBlankNotNull");
        Schema parentSchema = new SchemaImpl();
        String propertyKey = "TESTKEY";

        testTarget.notBlank(targetField, schema);
        testTarget.notNull(targetField, schema, propertyKey, (target, name) -> {
            parentSchema.addRequired(name);
        });

        assertEquals("\\S", schema.getPattern());
        assertEquals(Boolean.FALSE, schema.getNullable());
        assertEquals(Arrays.asList(propertyKey), parentSchema.getRequired());
    }
 
Example #6
Source File: ClientProxyGenerator.java    From quarkus with Apache License 2.0 6 votes vote down vote up
Collection<MethodInfo> getDelegatingMethods(BeanInfo bean) {
    Map<Methods.MethodKey, MethodInfo> methods = new HashMap<>();

    if (bean.isClassBean()) {
        Methods.addDelegatingMethods(bean.getDeployment().getIndex(), bean.getTarget().get().asClass(),
                methods);
    } else if (bean.isProducerMethod()) {
        MethodInfo producerMethod = bean.getTarget().get().asMethod();
        ClassInfo returnTypeClass = getClassByName(bean.getDeployment().getIndex(), producerMethod.returnType());
        Methods.addDelegatingMethods(bean.getDeployment().getIndex(), returnTypeClass, methods);
    } else if (bean.isProducerField()) {
        FieldInfo producerField = bean.getTarget().get().asField();
        ClassInfo fieldClass = getClassByName(bean.getDeployment().getIndex(), producerField.type());
        Methods.addDelegatingMethods(bean.getDeployment().getIndex(), fieldClass, methods);
    } else if (bean.isSynthetic()) {
        Methods.addDelegatingMethods(bean.getDeployment().getIndex(), bean.getImplClazz(), methods);
    }
    return methods.values();
}
 
Example #7
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapObjectNullableNoAdditionalProperties() {
    FieldInfo targetField = targetClass.field("mapObjectNullableAndMinPropertiesAndMaxProperties");
    Schema parentSchema = new SchemaImpl();
    String propertyKey = "TESTKEY";

    testTarget.notNull(targetField, schema, propertyKey, (target, name) -> {
        fail("Unexpected call to handler");
    });
    testTarget.sizeObject(targetField, schema);
    testTarget.notEmptyObject(targetField, schema);

    assertEquals(null, schema.getNullable());
    assertEquals(null, schema.getMinProperties());
    assertEquals(null, schema.getMaxProperties());
    assertNull(parentSchema.getRequired());
}
 
Example #8
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapObjectNullableAndMinPropertiesAndMaxProperties() {
    schema.setAdditionalPropertiesBoolean(Boolean.TRUE);

    FieldInfo targetField = targetClass.field("mapObjectNullableAndMinPropertiesAndMaxProperties");
    Schema parentSchema = new SchemaImpl();
    String propertyKey = "TESTKEY";

    testTarget.notNull(targetField, schema, propertyKey, (target, name) -> {
        fail("Unexpected call to handler");
    });
    testTarget.sizeObject(targetField, schema);
    testTarget.notEmptyObject(targetField, schema);

    assertEquals(null, schema.getNullable());
    assertEquals(Integer.valueOf(5), schema.getMinProperties());
    assertEquals(Integer.valueOf(20), schema.getMaxProperties());
    assertNull(parentSchema.getRequired());
}
 
Example #9
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**********************************************************************/

    @Test
    public void testMapObjectNotNullAndNotEmptyAndMaxProperties() {
        schema.setAdditionalPropertiesBoolean(Boolean.TRUE);

        FieldInfo targetField = targetClass.field("mapObjectNotNullAndNotEmptyAndMaxProperties");
        Schema parentSchema = new SchemaImpl();
        String propertyKey = "TESTKEY";

        testTarget.notNull(targetField, schema, propertyKey, (target, name) -> {
            parentSchema.addRequired(name);
        });
        testTarget.sizeObject(targetField, schema);
        testTarget.notEmptyObject(targetField, schema);

        assertEquals(Boolean.FALSE, schema.getNullable());
        assertEquals(Integer.valueOf(1), schema.getMinProperties());
        assertEquals(Integer.valueOf(20), schema.getMaxProperties());
        assertEquals(Arrays.asList(propertyKey), parentSchema.getRequired());
    }
 
Example #10
Source File: AvroProcessor.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@BuildStep
AnnotationsTransformerBuildItem markFieldsAnnotatedWithBuildTimeAvroDataFormatAsInjectable() {
    return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

        public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) {
            return kind == org.jboss.jandex.AnnotationTarget.Kind.FIELD;
        }

        @Override
        public void transform(TransformationContext ctx) {
            FieldInfo fieldInfo = ctx.getTarget().asField();
            if (fieldInfo.annotation(BUILD_TIME_AVRO_DATAFORMAT_ANNOTATION) != null) {
                ctx.transform().add(Inject.class).done();
            }
        }
    });
}
 
Example #11
Source File: StockMethodsAdder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private FieldInfo getIdField(AnnotationTarget idAnnotationTarget) {
    if (idAnnotationTarget instanceof FieldInfo) {
        return idAnnotationTarget.asField();
    }

    MethodInfo methodInfo = idAnnotationTarget.asMethod();
    String propertyName = JavaBeanUtil.getPropertyNameFromGetter(methodInfo.name());
    ClassInfo entityClass = methodInfo.declaringClass();
    FieldInfo field = entityClass.field(propertyName);
    if (field == null) {
        throw new IllegalArgumentException("Entity " + entityClass + " does not appear to have a field backing method"
                + methodInfo.name() + " which is annotated with @Id");
    }
    return field;
}
 
Example #12
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringNotEmptyMaxSize() {
    FieldInfo targetField = targetClass.field("stringNotEmptyMaxSize");

    testTarget.sizeString(targetField, schema);
    testTarget.notEmptyString(targetField, schema);

    assertEquals(Integer.valueOf(1), schema.getMinLength());
    assertEquals(Integer.valueOf(2000), schema.getMaxLength());
    assertEquals(Boolean.FALSE, schema.getNullable());
}
 
Example #13
Source File: MethodNameParser.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private FieldInfo getField(String fieldName) {
    FieldInfo fieldInfo = entityClass.field(fieldName);
    if (fieldInfo == null) {
        for (ClassInfo superClass : mappedSuperClassInfos) {
            fieldInfo = superClass.field(fieldName);
            if (fieldInfo != null) {
                break;
            }
        }
    }
    return fieldInfo;
}
 
Example #14
Source File: MethodNameParser.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private boolean entityContainsField(String fieldName) {
    if (entityClass.field(fieldName) != null) {
        return true;
    }

    for (ClassInfo superClass : mappedSuperClassInfos) {
        FieldInfo fieldInfo = superClass.field(fieldName);
        if (fieldInfo != null) {
            return true;
        }
    }
    return false;
}
 
Example #15
Source File: FieldAccessImplementor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private MethodInfo getSetter(ClassInfo entityClass, FieldInfo field) {
    MethodInfo setter = entityClass.method(JavaBeanUtil.getSetterName(field.name()), field.type());
    if (setter != null) {
        return setter;
    }

    if (entityClass.superName() != null) {
        ClassInfo superClass = index.getClassByName(entityClass.superName());
        if (superClass != null) {
            getSetter(superClass, field);
        }
    }

    return null;
}
 
Example #16
Source File: ClassConfigPropertiesUtil.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void createWriteValue(BytecodeCreator bytecodeCreator, ResultHandle configObject, FieldInfo field,
        MethodInfo setter, boolean useFieldAccess, ResultHandle value) {
    if (useFieldAccess) {
        createFieldWrite(bytecodeCreator, configObject, field, value);
    } else {
        createSetterCall(bytecodeCreator, configObject, setter, value);
    }
}
 
Example #17
Source File: InjectionPointInfo.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static InjectionPointInfo fromField(FieldInfo field, ClassInfo beanClass, BeanDeployment beanDeployment,
        InjectionPointModifier transformer) {
    Set<AnnotationInstance> qualifiers = new HashSet<>();
    Collection<AnnotationInstance> annotations = beanDeployment.getAnnotations(field);
    for (AnnotationInstance annotation : annotations) {
        beanDeployment.extractQualifiers(annotation).forEach(qualifiers::add);
    }
    Type type = resolveType(field.type(), beanClass, field.declaringClass(), beanDeployment);
    return new InjectionPointInfo(type,
            transformer.applyTransformers(type, field, qualifiers), field, -1,
            Annotations.contains(annotations, DotNames.TRANSIENT_REFERENCE));
}
 
Example #18
Source File: InjectionPointInfo.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static InjectionPointInfo fromResourceField(FieldInfo field, ClassInfo beanClass, BeanDeployment beanDeployment,
        InjectionPointModifier transformer) {
    Type type = resolveType(field.type(), beanClass, field.declaringClass(), beanDeployment);
    return new InjectionPointInfo(type,
            transformer.applyTransformers(type, field, new HashSet<>(field.annotations())),
            InjectionPointKind.RESOURCE, field, -1, false);
}
 
Example #19
Source File: AbstractGenerator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
protected boolean isReflectionFallbackNeeded(FieldInfo field, String targetPackage) {
    // Reflection fallback is needed for private fields and non-public fields declared on superclasses located in a different package
    if (Modifier.isPrivate(field.flags())) {
        return true;
    }
    if (Modifier.isProtected(field.flags()) || isPackagePrivate(field.flags())) {
        return !DotNames.packageName(field.declaringClass().name()).equals(targetPackage);
    }
    return false;
}
 
Example #20
Source File: BeanGenerator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static ResultHandle collectInjectionPointAnnotations(ClassOutput classOutput, ClassCreator beanCreator,
        BeanDeployment beanDeployment, MethodCreator constructor, InjectionPointInfo injectionPoint,
        AnnotationLiteralProcessor annotationLiterals, Predicate<DotName> injectionPointAnnotationsPredicate) {
    ResultHandle annotationsHandle = constructor.newInstance(MethodDescriptor.ofConstructor(HashSet.class));
    Collection<AnnotationInstance> annotations;
    if (Kind.FIELD.equals(injectionPoint.getTarget().kind())) {
        FieldInfo field = injectionPoint.getTarget().asField();
        annotations = beanDeployment.getAnnotations(field);
    } else {
        MethodInfo method = injectionPoint.getTarget().asMethod();
        annotations = Annotations.getParameterAnnotations(beanDeployment,
                method, injectionPoint.getPosition());
    }
    for (AnnotationInstance annotation : annotations) {
        if (!injectionPointAnnotationsPredicate.test(annotation.name())) {
            continue;
        }
        ResultHandle annotationHandle;
        if (DotNames.INJECT.equals(annotation.name())) {
            annotationHandle = constructor
                    .readStaticField(FieldDescriptor.of(InjectLiteral.class, "INSTANCE", InjectLiteral.class));
        } else {
            // Create annotation literal if needed
            ClassInfo literalClass = getClassByName(beanDeployment.getIndex(), annotation.name());
            annotationHandle = annotationLiterals.process(constructor,
                    classOutput, literalClass, annotation,
                    Types.getPackageName(beanCreator.getClassName()));
        }
        constructor.invokeInterfaceMethod(MethodDescriptors.SET_ADD, annotationsHandle,
                annotationHandle);
    }
    return annotationsHandle;
}
 
Example #21
Source File: QuteProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to find a property with the specified name, ie. a public non-static non-synthetic field with the given name or a
 * public non-static non-synthetic method with no params and the given name.
 * 
 * @param name
 * @param clazz
 * @param index
 * @return the property or null
 */
private AnnotationTarget findProperty(String name, ClassInfo clazz, IndexView index) {
    while (clazz != null) {
        // Fields
        for (FieldInfo field : clazz.fields()) {
            if (Modifier.isPublic(field.flags()) && !Modifier.isStatic(field.flags())
                    && !ValueResolverGenerator.isSynthetic(field.flags()) && field.name().equals(name)) {
                return field;
            }
        }
        // Methods
        for (MethodInfo method : clazz.methods()) {
            if (Modifier.isPublic(method.flags()) && !Modifier.isStatic(method.flags())
                    && !ValueResolverGenerator.isSynthetic(method.flags()) && (method.name().equals(name)
                            || ValueResolverGenerator.getPropertyName(method.name()).equals(name))) {
                return method;
            }
        }
        DotName superName = clazz.superName();
        if (superName == null) {
            clazz = null;
        } else {
            clazz = index.getClassByName(clazz.superName());
        }
    }
    return null;
}
 
Example #22
Source File: ClassConfigPropertiesUtil.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void populateTypicalProperty(MethodCreator methodCreator, ResultHandle configObject,
        List<ConfigPropertyBuildItemCandidate> configPropertyBuildItemCandidates, ClassInfo currentClassInHierarchy,
        FieldInfo field, boolean useFieldAccess, Type fieldType, MethodInfo setter,
        ResultHandle mpConfig, String fullConfigName) {
    /*
     * We want to support cases where the Config class defines a default value for fields
     * by simply specifying the default value in its constructor
     * For such cases the strategy we follow is that when a requested property does not exist
     * we check the value from the corresponding getter (or read the field value if possible)
     * and if the value is not null we don't fail
     */
    if (shouldCheckForDefaultValue(currentClassInHierarchy, field)) {
        ReadOptionalResponse readOptionalResponse = createReadOptionalValueAndConvertIfNeeded(
                fullConfigName,
                fieldType, field.declaringClass().name(), methodCreator, mpConfig);

        // call the setter if the optional contained data
        createWriteValue(readOptionalResponse.getIsPresentTrue(), configObject, field, setter,
                useFieldAccess,
                readOptionalResponse.getValue());
    } else {
        /*
         * In this case we want a missing property to cause an exception that we don't handle
         * So we call config.getValue making sure to handle collection values
         */
        ResultHandle setterValue = createReadMandatoryValueAndConvertIfNeeded(
                fullConfigName, fieldType,
                field.declaringClass().name(), methodCreator, mpConfig);
        createWriteValue(methodCreator, configObject, field, setter, useFieldAccess, setterValue);

    }
    configPropertyBuildItemCandidates
            .add(new ConfigPropertyBuildItemCandidate(field.name(), fullConfigName, fieldType));
}
 
Example #23
Source File: CamelDeploymentSettingsBuilderProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private boolean annotationTargetIsCamelApi(AnnotationTarget target) {
    /**
     * Verify whether an annotation is applied to org.apache.camel types. If the declaring class
     * has the org.apache.camel package prefix, it is ignored since we are only interested in
     * annotations declared within user classes.
     */
    if (target != null) {
        if (target.kind().equals(Kind.CLASS)) {
            ClassInfo classInfo = target.asClass();
            if (isCamelApi(classInfo.name())) {
                return false;
            }

            Type superType = classInfo.superClassType();
            if (superType != null && isCamelApi(superType.name())) {
                return true;
            }

            return classInfo.interfaceNames().stream().anyMatch(interfaceName -> isCamelApi(interfaceName));
        } else if (target.kind().equals(Kind.FIELD)) {
            FieldInfo fieldInfo = target.asField();
            return !isCamelApi(fieldInfo.declaringClass().name()) && isCamelApi(fieldInfo.type().name());
        } else if (target.kind().equals(Kind.METHOD)) {
            MethodInfo methodInfo = target.asMethod();
            return !isCamelApi(methodInfo.declaringClass().name()) && isCamelApi(methodInfo.returnType().name());
        }
    }
    return false;
}
 
Example #24
Source File: TypeResolver.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
private TypeResolver(String propertyName, FieldInfo field, Deque<Map<String, Type>> resolutionStack) {
    this.propertyName = propertyName;
    this.field = field;
    this.resolutionStack = resolutionStack;

    if (field != null) {
        this.leaf = field.type();
        targets.add(field);
    } else {
        this.leaf = null;
    }
}
 
Example #25
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringNotEmptySizeRange() {
    FieldInfo targetField = targetClass.field("stringNotEmptySizeRange");

    testTarget.sizeString(targetField, schema);
    testTarget.notEmptyString(targetField, schema);

    assertEquals(Integer.valueOf(100), schema.getMinLength());
    assertEquals(Integer.valueOf(2000), schema.getMaxLength());
    assertEquals(Boolean.FALSE, schema.getNullable());
}
 
Example #26
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringNotBlankDigits() {
    FieldInfo targetField = targetClass.field("stringNotBlankDigits");

    testTarget.digits(targetField, schema);
    testTarget.notBlank(targetField, schema);

    assertEquals("^\\d{1,8}([.]\\d{1,10})?$", schema.getPattern());
    assertEquals(Boolean.FALSE, schema.getNullable());
}
 
Example #27
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntegerNegativeOrZeroMinValue() {
    FieldInfo targetField = targetClass.field("integerNegativeOrZeroMinValue");
    testTarget.min(targetField, schema);
    testTarget.negativeOrZero(targetField, schema);

    assertEquals(new BigDecimal("0"), schema.getMaximum());
    assertEquals(null, schema.getExclusiveMaximum());
    assertEquals(new BigDecimal("-999"), schema.getMinimum());
    assertEquals(null, schema.getExclusiveMinimum());
}
 
Example #28
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntegerNegativeNotZeroMinValueExclusive() {
    FieldInfo targetField = targetClass.field("integerNegativeNotZeroMinValue");
    schema.setExclusiveMaximum(Boolean.TRUE);
    schema.setExclusiveMinimum(Boolean.TRUE);

    testTarget.min(targetField, schema);
    testTarget.negative(targetField, schema);

    assertEquals(new BigDecimal("0"), schema.getMaximum());
    assertEquals(Boolean.TRUE, schema.getExclusiveMaximum());
    assertEquals(new BigDecimal("-1000000"), schema.getMinimum());
    assertEquals(Boolean.TRUE, schema.getExclusiveMinimum());
}
 
Example #29
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**********************************************************************/

    @Test
    public void testIntegerNegativeNotZeroMinValue() {
        FieldInfo targetField = targetClass.field("integerNegativeNotZeroMinValue");
        testTarget.min(targetField, schema);
        testTarget.negative(targetField, schema);

        assertEquals(new BigDecimal("-1"), schema.getMaximum());
        assertEquals(null, schema.getExclusiveMaximum());
        assertEquals(new BigDecimal("-1000000"), schema.getMinimum());
        assertEquals(null, schema.getExclusiveMinimum());
    }
 
Example #30
Source File: BeanValidationScannerTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntegerPositiveOrZeroMaxValueExclusive() {
    FieldInfo targetField = targetClass.field("integerPositiveOrZeroMaxValue");
    schema.setExclusiveMaximum(Boolean.TRUE);
    schema.setExclusiveMinimum(Boolean.TRUE);

    testTarget.max(targetField, schema);
    testTarget.positiveOrZero(targetField, schema);

    assertEquals(new BigDecimal("-1"), schema.getMinimum());
    assertEquals(Boolean.TRUE, schema.getExclusiveMinimum());
    assertEquals(new BigDecimal("999"), schema.getMaximum());
    assertEquals(Boolean.TRUE, schema.getExclusiveMaximum());
}