Package uk.co.jemos.podam.common
Class BeanValidationStrategy
- java.lang.Object
-
- uk.co.jemos.podam.common.BeanValidationStrategy
-
- All Implemented Interfaces:
AttributeStrategy<Object>
public class BeanValidationStrategy extends Object implements AttributeStrategy<Object>
This strategy fills attributes and parameters annotated with Java bean validation annotations- Author:
- daivanov
-
-
Field Summary
Fields Modifier and Type Field Description private Class<?>attributeTypeexpected return type of an attributeprivate static org.slf4j.LoggerLOG
-
Constructor Summary
Constructors Constructor Description BeanValidationStrategy(Class<?> attributeType)Constructor for the strategy
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private ObjectdecimalToReturnType(BigDecimal result)Converts intermediate decimal value to the actual attribute type, for example, string representation of this decimalstatic <T> TfindTypeFromList(List<?> list, Class<T> type)Utility to find an item of a desired type in the given listObjectgetValue(Class<?> attrType, List<Annotation> annotations)It returns aCalendarobjects complying with Java bean validation annotations.private BigDecimalgetValueInRange(BigDecimal min, BigDecimal max)Produces random decimal value within specified rangeprivate ObjecttimestampToReturnType(Long result)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
attributeType
private Class<?> attributeType
expected return type of an attribute
-
-
Constructor Detail
-
BeanValidationStrategy
public BeanValidationStrategy(Class<?> attributeType)
Constructor for the strategy- Parameters:
attributeType- expected return type of an attribute
-
-
Method Detail
-
getValue
public Object getValue(Class<?> attrType, List<Annotation> annotations) throws PodamMockeryException
It returns aCalendarobjects complying with Java bean validation annotations. It returns a value of the given type- Specified by:
getValuein interfaceAttributeStrategy<Object>- Parameters:
attrType- an attribute's typeannotations- list of annotations attached to an attribute- Returns:
- A value of the given type
- Throws:
PodamMockeryException
-
findTypeFromList
public static <T> T findTypeFromList(List<?> list, Class<T> type)
Utility to find an item of a desired type in the given list- Type Parameters:
T- Return type of item to find- Parameters:
list- List to search intype- Type to find in the list- Returns:
- First element from the list of desired type
-
getValueInRange
private BigDecimal getValueInRange(BigDecimal min, BigDecimal max)
Produces random decimal value within specified range- Parameters:
min- minimum value of rangemax- maximum value of range- Returns:
- decimal value in the specified range
-
decimalToReturnType
private Object decimalToReturnType(BigDecimal result)
Converts intermediate decimal value to the actual attribute type, for example, string representation of this decimal- Parameters:
result-BigDecimalintermediate result to convert to the real attribute type- Returns:
- actual attribute type object
-
-