Search in sources :

Example 6 with Assertion

use of io.irontest.models.assertion.Assertion 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)

Example 7 with Assertion

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

the class TeststepDAO method updateAssertions.

private void updateAssertions(Teststep teststep) throws JsonProcessingException {
    AssertionDAO assertionDAO = assertionDAO();
    List<Long> newAssertionIds = new ArrayList<Long>();
    for (Assertion assertion : teststep.getAssertions()) {
        if (assertion.getId() == null) {
            // insert the assertion
            assertion.setTeststepId(teststep.getId());
            newAssertionIds.add(assertionDAO.insert_NoTransaction(assertion));
        } else {
            // update the assertion
            newAssertionIds.add(assertion.getId());
            assertionDAO.update_NoTransaction(assertion);
        }
    }
    // delete assertions whose id is not in the newAssertionIds list;
    // if newAssertionIds list is empty, delete all assertions
    newAssertionIds.add(-1L);
    assertionDAO.deleteByTeststepIdIfIdNotIn(teststep.getId(), newAssertionIds);
}
Also used : ArrayList(java.util.ArrayList) Assertion(io.irontest.models.assertion.Assertion)

Aggregations

Assertion (io.irontest.models.assertion.Assertion)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 AssertionVerifier (io.irontest.core.assertion.AssertionVerifier)2 AssertionVerificationResult (io.irontest.models.assertion.AssertionVerificationResult)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 MQTeststepActionDataBackup (io.irontest.core.MQTeststepActionDataBackup)1 MapValueLookup (io.irontest.core.MapValueLookup)1 DataTable (io.irontest.models.DataTable)1 Testcase (io.irontest.models.Testcase)1 UserDefinedProperty (io.irontest.models.UserDefinedProperty)1 AssertionVerification (io.irontest.models.assertion.AssertionVerification)1 IntegerEqualAssertionProperties (io.irontest.models.assertion.IntegerEqualAssertionProperties)1 Endpoint (io.irontest.models.endpoint.Endpoint)1 TeststepRun (io.irontest.models.testrun.TeststepRun)1 Teststep (io.irontest.models.teststep.Teststep)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 PermitAll (javax.annotation.security.PermitAll)1