use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.
the class RegularTestcaseRunner method run.
@Override
public TestcaseRun run() throws JsonProcessingException {
RegularTestcaseRun testcaseRun = new RegularTestcaseRun();
preProcessingForIIBTestcase();
startTestcaseRun(testcaseRun);
if (isTestcaseHasWaitForProcessingCompletionAction()) {
// milliseconds
long secondFraction = getTestcaseRunContext().getTestcaseRunStartTime().getTime() % 1000;
long millisecondsUntilNextSecond = 1000 - secondFraction;
Teststep waitStep = getTestcase().getTeststeps().get(0);
waitStep.setName("Wait " + millisecondsUntilNextSecond + " milliseconds");
waitStep.setOtherProperties(new WaitTeststepProperties(millisecondsUntilNextSecond));
}
// run test steps
for (Teststep teststep : getTestcase().getTeststeps()) {
testcaseRun.getStepRuns().add(runTeststep(teststep));
}
// test case run ends
testcaseRun.setDuration(new Date().getTime() - testcaseRun.getStartTime().getTime());
LOGGER.info("Finish running test case: " + getTestcase().getName());
for (TeststepRun teststepRun : testcaseRun.getStepRuns()) {
if (TestResult.FAILED == teststepRun.getResult()) {
testcaseRun.setResult(TestResult.FAILED);
break;
}
}
// persist test case run details into database
getTestcaseRunDAO().insert(testcaseRun);
// prepare return object for UI (reduced contents for performance)
List<TeststepRun> teststepRunsForUI = new ArrayList<>();
for (TeststepRun stepRun : testcaseRun.getStepRuns()) {
TeststepRun teststepRunForUI = new TeststepRun();
teststepRunForUI.setId(stepRun.getId());
teststepRunForUI.setResult(stepRun.getResult());
Teststep teststepForUI = new Teststep();
teststepForUI.setId(stepRun.getTeststep().getId());
teststepRunForUI.setTeststep(teststepForUI);
teststepRunsForUI.add(teststepRunForUI);
}
RegularTestcaseRun testcaseRunForUI = new RegularTestcaseRun();
testcaseRunForUI.setId(testcaseRun.getId());
testcaseRunForUI.setResult(testcaseRun.getResult());
testcaseRunForUI.setStepRuns(teststepRunsForUI);
return testcaseRunForUI;
}
use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.
the class TestcaseRunner method preProcessingForIIBTestcase.
protected void preProcessingForIIBTestcase() {
for (Teststep teststep : testcase.getTeststeps()) {
if (Teststep.TYPE_IIB.equals(teststep.getType()) && Teststep.ACTION_WAIT_FOR_PROCESSING_COMPLETION.equals(teststep.getAction())) {
testcaseHasWaitForProcessingCompletionAction = true;
}
}
if (testcaseHasWaitForProcessingCompletionAction) {
Teststep waitStep = new Teststep();
waitStep.setType(Teststep.TYPE_WAIT);
testcase.getTeststeps().add(0, waitStep);
}
}
use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.
the class TeststepRunner method resolveReferenceableStringProperties.
/**
* Resolve as many string property references as possible. For unresolved references, throw exception in the end.
* @throws IOException
*/
private void resolveReferenceableStringProperties() throws IOException {
List<String> undefinedStringProperties = new ArrayList<String>();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
// resolve property references in teststep.otherProperties
String otherPropertiesJSON = objectMapper.writeValueAsString(teststep.getOtherProperties());
MapValueLookup propertyReferenceResolver = new MapValueLookup(referenceableStringProperties, true);
String resolvedOtherPropertiesJSON = new StrSubstitutor(propertyReferenceResolver).replace(otherPropertiesJSON);
undefinedStringProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
String tempStepJSON = "{\"type\":\"" + teststep.getType() + "\",\"otherProperties\":" + resolvedOtherPropertiesJSON + "}";
Teststep tempStep = objectMapper.readValue(tempStepJSON, Teststep.class);
teststep.setOtherProperties(tempStep.getOtherProperties());
// resolve property references in teststep.request (text type)
if (teststep.getRequestType() == TeststepRequestType.TEXT) {
propertyReferenceResolver = new MapValueLookup(referenceableStringProperties, false);
teststep.setRequest(new StrSubstitutor(propertyReferenceResolver).replace((String) teststep.getRequest()));
undefinedStringProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
}
if (!undefinedStringProperties.isEmpty()) {
throw new RuntimeException("String properties " + undefinedStringProperties + " not defined.");
}
}
use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.
the class TeststepRunDAO method insert_NoTransaction.
public void insert_NoTransaction(long testcaseRunId, Long testcaseIndividualRunId, TeststepRun teststepRun) throws JsonProcessingException {
// remove contents that are not to be serialized into the teststep column
Teststep teststep = teststepRun.getTeststep();
teststep.getAssertions().clear();
Endpoint endpoint = teststep.getEndpoint();
if (endpoint != null) {
endpoint.setPassword(null);
}
ObjectMapper objectMapper = new ObjectMapper();
long id = _insert(testcaseRunId, testcaseIndividualRunId, objectMapper.writeValueAsString(teststep), objectMapper.writeValueAsString(teststepRun.getResponse()), teststepRun.getInfoMessage(), teststepRun.getErrorMessage(), objectMapper.writeValueAsString(teststepRun.getAssertionVerifications()), teststepRun.getStartTime(), teststepRun.getDuration(), teststepRun.getResult().toString());
teststepRun.setId(id);
}
use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.
the class TeststepRunMapper method map.
public TeststepRun map(int index, ResultSet rs, StatementContext ctx) throws SQLException {
TeststepRun teststepRun = new TeststepRun();
ObjectMapper objectMapper = new ObjectMapper();
teststepRun.setStartTime(rs.getTimestamp("starttime"));
teststepRun.setDuration(rs.getLong("duration"));
teststepRun.setResult(TestResult.getByText(rs.getString("result")));
Teststep teststep = null;
try {
teststep = objectMapper.readValue(rs.getString("teststep"), Teststep.class);
} catch (IOException e) {
throw new SQLException("Failed to deserialize teststep JSON.", e);
}
teststepRun.setTeststep(teststep);
// Use LinkedHashMap here instead of Object (for covering specific response type like DBAPIResponse),
// because TeststepRun is used for displaying report, so JSON representation of the response is sufficient.
LinkedHashMap response = null;
try {
response = objectMapper.readValue(rs.getString("response"), LinkedHashMap.class);
} catch (IOException e) {
throw new SQLException("Failed to deserialize response JSON.", e);
}
teststepRun.setResponse(response);
teststepRun.setInfoMessage(rs.getString("info_message"));
teststepRun.setErrorMessage(rs.getString("error_message"));
List<AssertionVerification> assertionVerifications = null;
try {
assertionVerifications = new ObjectMapper().readValue(rs.getString("assertion_verifications"), new TypeReference<List<AssertionVerification>>() {
});
} catch (IOException e) {
throw new SQLException("Failed to deserialize stepruns JSON.", e);
}
teststepRun.setAssertionVerifications(assertionVerifications);
return teststepRun;
}
Aggregations