use of io.irontest.core.propertyextractor.PropertyExtractorRunner in project irontest by zheng-wang.
the class PropertyExtractorResource method extract.
/**
* This is a stateless operation, i.e. not persisting anything in database.
* @param propertyExtractionRequest
* @return
*/
@POST
@Path("propertyExtractors/{propertyExtractorId}/extract")
@PermitAll
public PropertyExtractionResult extract(PropertyExtractionRequest propertyExtractionRequest) throws IOException {
PropertyExtractor propertyExtractor = propertyExtractionRequest.getPropertyExtractor();
// gather referenceable string properties
long testcaseId = propertyExtractorDAO.findTestcaseIdById(propertyExtractor.getId());
List<UserDefinedProperty> testcaseUDPs = udpDAO.findByTestcaseId(testcaseId);
Map<String, String> referenceableStringProperties = IronTestUtils.udpListToMap(testcaseUDPs);
Set<String> udpNames = referenceableStringProperties.keySet();
DataTable dataTable = dataTableDAO.getTestcaseDataTable(testcaseId, true);
if (dataTable.getRows().size() > 0) {
IronTestUtils.checkDuplicatePropertyNameBetweenDataTableAndUPDs(udpNames, dataTable);
referenceableStringProperties.putAll(dataTable.getStringPropertiesInRow(0));
}
PropertyExtractorRunner propertyExtractorRunner = PropertyExtractorRunnerFactory.getInstance().create(propertyExtractor, referenceableStringProperties);
String propertyExtractionInput = propertyExtractionRequest.getInput();
PropertyExtractionResult result = new PropertyExtractionResult();
try {
result.setPropertyValue(propertyExtractorRunner.extract(propertyExtractionInput));
} catch (Exception e) {
LOGGER.error("Failed to extract property", e);
result.setError(e.getMessage());
}
return result;
}
use of io.irontest.core.propertyextractor.PropertyExtractorRunner in project irontest by zheng-wang.
the class TestcaseRunner method extractPropertiesOutOfAPIResponse.
/**
* Extract properties out of API response, and make the properties visible to the next test step run.
*/
private Map<String, String> extractPropertiesOutOfAPIResponse(String teststepType, List<PropertyExtractor> propertyExtractors, Object apiResponse, Map<String, String> referenceableStringProperties) throws Exception {
Map<String, String> extractedProperties = new HashMap<>();
for (PropertyExtractor propertyExtractor : propertyExtractors) {
String propertyExtractionInput = null;
if (Teststep.TYPE_HTTP.equals(teststepType)) {
HTTPAPIResponse httpApiResponse = (HTTPAPIResponse) apiResponse;
if (PropertyExtractor.TYPE_COOKIE.equals(propertyExtractor.getType())) {
Optional<HTTPHeader> setCookieHeader = httpApiResponse.getHttpHeaders().stream().filter(httpHeader -> HttpHeader.SET_COOKIE.asString().equals(httpHeader.getName())).findFirst();
propertyExtractionInput = setCookieHeader.isPresent() ? setCookieHeader.get().getValue() : null;
} else {
propertyExtractionInput = httpApiResponse.getHttpBody();
}
}
PropertyExtractorRunner propertyExtractorRunner = PropertyExtractorRunnerFactory.getInstance().create(propertyExtractor, referenceableStringProperties);
String propertyValue = propertyExtractorRunner.extract(propertyExtractionInput);
extractedProperties.put(propertyExtractor.getPropertyName(), propertyValue);
}
return extractedProperties;
}
Aggregations