use of ru.sbtqa.tag.api.exception.RestPluginException in project page-factory-2 by sbtqa.
the class ReflectionUtils method set.
public static void set(EndpointEntry endpoint, Field field, Object value) {
try {
Object convertedValue;
// If field type is BodyArray, parse it
if (field.getType().equals(BodyArray.class)) {
Type genericType = field.getGenericType();
Map<TypeVariable<?>, Type> actualTypeArguments = TypeUtils.getTypeArguments((ParameterizedType) genericType);
Class<?> typeArgument = (Class<?>) actualTypeArguments.values().toArray()[0];
convertedValue = field.getType().getConstructor(String.class, Class.class).newInstance(value, typeArgument);
} else {
convertedValue = ConvertUtils.convert(value, field.getType());
}
field.setAccessible(true);
field.set(endpoint, convertedValue);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException ex) {
throw new RestPluginException(format("Body with name \"%s\" is not available", field.getName()), ex);
}
}
use of ru.sbtqa.tag.api.exception.RestPluginException in project page-factory-2 by sbtqa.
the class EndpointEntryReflection method validate.
/**
* Invoke method annotated with {@link Validation}.
* Works if endpoint contains only one validation rule
*
* @param params params to pass to validation rule method
*/
public void validate(Object... params) {
if (validations.size() < 2) {
Method validation = validations.values().stream().findFirst().orElseThrow(() -> new RestPluginException(format("There is no validation rules in \"%s\" endpoint", entryTitle)));
invoke(validation, endpoint, params);
} else {
throw new RestPluginException(format("There is more then 1 validation rule in \"%s\" endpoint. Please specify validation rule with it title", entryTitle));
}
}
use of ru.sbtqa.tag.api.exception.RestPluginException in project page-factory-2 by sbtqa.
the class EndpointManager method bootstrapEndpoint.
private static EndpointEntry bootstrapEndpoint(Class<?> entry) {
try {
Constructor<EndpointEntry> constructor = (Constructor<EndpointEntry>) entry.getConstructor();
constructor.setAccessible(true);
EndpointEntry endpoint = constructor.newInstance();
EndpointContext.setCurrentEndpoint(endpoint);
return endpoint;
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
throw new RestPluginException("Can't initialize current entry parameters", ex);
}
}
use of ru.sbtqa.tag.api.exception.RestPluginException in project page-factory-2 by sbtqa.
the class MutatorApplicator method getMutator.
private Method getMutator(EndpointEntry endpoint, Field field) {
Mutator mutator = field.getAnnotation(Mutator.class);
Class container = mutator.clazz() == EmptyClass.class ? endpoint.getClass() : mutator.clazz();
Method setter = Arrays.stream(container.getMethods()).filter(method -> Objects.equals(method.getName(), mutator.method())).findFirst().orElseThrow(() -> new RestPluginException(format("Mutator method \"%s\" is not found", mutator.method())));
setter.setAccessible(true);
return setter;
}
Aggregations