use of ru.sbtqa.tag.api.EndpointEntry in project page-factory-2 by sbtqa.
the class PlaceholderUtils method replaceJsonTemplatePlaceholders.
/**
* Replace Json template placeholders in string on parameters
*
* @param jsonString replace placeholders in this json string
* @param parameters replace these parameters
* @return json string with replaced placeholders
*/
public static String replaceJsonTemplatePlaceholders(EndpointEntry entry, String jsonString, Map<String, Object> parameters) {
Set<Map.Entry<String, Object>> mandatoryValues = parameters.entrySet().stream().filter(stringObjectEntry -> stringObjectEntry.getValue() != null).collect(Collectors.toSet());
for (Map.Entry<String, Object> parameter : mandatoryValues) {
String parameterName = parameter.getKey();
Object parameterValue = parameter.getValue();
if (isFieldExists(entry, parameterName)) {
Field declaredField = FieldUtils.getAllFieldsList(entry.getClass()).stream().filter(field -> field.getName().equals(parameterName)).findFirst().orElseThrow(() -> new AutotestError("This error should never appear"));
jsonString = replacePlaceholder(jsonString, declaredField, parameterName, parameterValue);
} else {
jsonString = replacePlaceholder(jsonString, null, parameterName, parameterValue);
}
}
return jsonString;
}
use of ru.sbtqa.tag.api.EndpointEntry 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);
}
}
Aggregations