Search in sources :

Example 1 with IntegerEqualAssertionProperties

use of io.irontest.models.assertion.IntegerEqualAssertionProperties in project irontest by zheng-wang.

the class IntegerEqualAssertionVerifier method _verify.

/**
 * @param assertion
 * @param input the Integer that the assertion is verified against
 * @return
 */
@Override
public AssertionVerificationResult _verify(Assertion assertion, Object input) throws Exception {
    AssertionVerificationResult result = new AssertionVerificationResult();
    IntegerEqualAssertionProperties properties = (IntegerEqualAssertionProperties) assertion.getOtherProperties();
    result.setResult(new Integer(properties.getNumber()).equals(input) ? TestResult.PASSED : TestResult.FAILED);
    return result;
}
Also used : AssertionVerificationResult(io.irontest.models.assertion.AssertionVerificationResult) IntegerEqualAssertionProperties(io.irontest.models.assertion.IntegerEqualAssertionProperties)

Example 2 with IntegerEqualAssertionProperties

use of io.irontest.models.assertion.IntegerEqualAssertionProperties 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());
        }
    }
}
Also used : IntegerEqualAssertionProperties(io.irontest.models.assertion.IntegerEqualAssertionProperties) Assertion(io.irontest.models.assertion.Assertion) MQTeststepActionDataBackup(io.irontest.core.MQTeststepActionDataBackup) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

IntegerEqualAssertionProperties (io.irontest.models.assertion.IntegerEqualAssertionProperties)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MQTeststepActionDataBackup (io.irontest.core.MQTeststepActionDataBackup)1 Assertion (io.irontest.models.assertion.Assertion)1 AssertionVerificationResult (io.irontest.models.assertion.AssertionVerificationResult)1