use of io.irontest.core.MQTeststepActionDataBackup in project irontest by zheng-wang.
the class TeststepDAO method backupRestoreMQTeststepActionData.
private void backupRestoreMQTeststepActionData(Teststep oldTeststep, Teststep teststep) throws IOException {
long teststepId = teststep.getId();
String oldAction = oldTeststep.getAction();
String newAction = teststep.getAction();
String backupStr = getActionDataBackupById(teststepId);
MQTeststepActionDataBackup backup = null;
MQTeststepActionDataBackup oldBackup = null;
if (backupStr == null) {
backup = new MQTeststepActionDataBackup();
oldBackup = new MQTeststepActionDataBackup();
} else {
ObjectMapper mapper = new ObjectMapper();
backup = mapper.readValue(backupStr, MQTeststepActionDataBackup.class);
oldBackup = mapper.readValue(backupStr, MQTeststepActionDataBackup.class);
}
boolean backupChanged = false;
// backup old action's data
// for assertions, no need to backup primary keys or foreign keys
List<Assertion> oldAssertions = oldTeststep.getAssertions();
for (Assertion oldAssertion : oldAssertions) {
oldAssertion.setId(null);
oldAssertion.setTeststepId(null);
}
if (Teststep.ACTION_CHECK_DEPTH.equals(oldAction)) {
Assertion oldAssertion = oldAssertions.get(0);
backup.setQueueDepthAssertionProperties((IntegerEqualAssertionProperties) oldAssertion.getOtherProperties());
backupChanged = true;
} else if (Teststep.ACTION_DEQUEUE.equals(oldAction)) {
backup.setDequeueAssertions(oldAssertions);
backupChanged = true;
} else if (Teststep.ACTION_ENQUEUE.equals(oldAction) || Teststep.ACTION_PUBLISH.equals(oldAction)) {
if (TeststepRequestType.TEXT == oldTeststep.getRequestType()) {
backup.setTextRequest((String) oldTeststep.getRequest());
backup.setRfh2Header(((MQTeststepProperties) oldTeststep.getOtherProperties()).getRfh2Header());
backupChanged = true;
} else if (TeststepRequestType.FILE == oldTeststep.getRequestType()) {
backup.setFileRequest(getBinaryRequestById(teststepId));
backup.setRequestFilename(oldTeststep.getRequestFilename());
backupChanged = true;
}
}
// persist backup if changed
if (backupChanged) {
backupStr = new ObjectMapper().writeValueAsString(backup);
saveActionDataBackupById(teststepId, backupStr);
}
// setup new action's data
if (Teststep.ACTION_CHECK_DEPTH.equals(newAction)) {
Assertion assertion = new Assertion();
teststep.getAssertions().add(assertion);
assertion.setName("MQ queue depth equals");
assertion.setType(Assertion.TYPE_INTEGER_EQUAL);
// restore old assertion properties if exists
IntegerEqualAssertionProperties oldAssertionProperties = oldBackup.getQueueDepthAssertionProperties();
if (oldAssertionProperties != null) {
assertion.setOtherProperties(oldAssertionProperties);
} else {
assertion.setOtherProperties(new IntegerEqualAssertionProperties(0));
}
} else if (Teststep.ACTION_DEQUEUE.equals(newAction)) {
// restore old assertions if exist
if (oldBackup.getDequeueAssertions() != null) {
teststep.getAssertions().addAll(oldBackup.getDequeueAssertions());
}
} else if (Teststep.ACTION_ENQUEUE.equals(newAction) || Teststep.ACTION_PUBLISH.equals(newAction)) {
if (TeststepRequestType.TEXT == teststep.getRequestType()) {
// restore old message
teststep.setRequest(oldBackup.getTextRequest());
// teststep.otherProperties.rfh2Header should never be null
((MQTeststepProperties) teststep.getOtherProperties()).setRfh2Header(oldBackup.getRfh2Header() == null ? new MQRFH2Header() : oldBackup.getRfh2Header());
} else if (TeststepRequestType.FILE == teststep.getRequestType()) {
// restore old message
updateRequest(teststep.getId(), oldBackup.getFileRequest(), TeststepRequestType.FILE.toString(), oldBackup.getRequestFilename());
}
}
}
Aggregations