Search in sources :

Example 11 with Endpoint

use of io.irontest.models.endpoint.Endpoint in project irontest by zheng-wang.

the class TestcaseDAO method duplicate.

/**
 * Clone the test case and its contents.
 * @param oldTestcaseId id of the test case to be cloned
 * @param targetFolderId id of the folder in which the new test case will be created
 * @return ID of the new test case
 */
@Transaction
public long duplicate(long oldTestcaseId, long targetFolderId) throws JsonProcessingException {
    Testcase oldTestcase = findById_Complete_NoTransaction(oldTestcaseId);
    // resolve new test case name
    String newTestcaseName = oldTestcase.getName();
    if (oldTestcase.getParentFolderId() == targetFolderId) {
        int copyIndex = 1;
        newTestcaseName = oldTestcase.getName() + " - Copy";
        while (_nameExistsInFolder(newTestcaseName, targetFolderId)) {
            copyIndex++;
            newTestcaseName = oldTestcase.getName() + " - Copy (" + copyIndex + ")";
        }
    }
    // duplicate the test case record
    Testcase newTestcase = new Testcase();
    newTestcase.setName(newTestcaseName);
    newTestcase.setDescription(oldTestcase.getDescription());
    newTestcase.setParentFolderId(targetFolderId);
    newTestcase = insert_NoTransaction(newTestcase);
    // duplicate user defined properties
    udpDAO().duplicateByTestcase(oldTestcaseId, newTestcase.getId());
    // duplicate test steps
    for (Teststep oldTeststep : oldTestcase.getTeststeps()) {
        Teststep newTeststep = new Teststep();
        newTeststep.setName(oldTeststep.getName());
        newTeststep.setTestcaseId(newTestcase.getId());
        newTeststep.setSequence(oldTeststep.getSequence());
        newTeststep.setType(oldTeststep.getType());
        newTeststep.setDescription(oldTeststep.getDescription());
        newTeststep.setAction(oldTeststep.getAction());
        if (oldTeststep.getRequestType() == TeststepRequestType.TEXT) {
            newTeststep.setRequest(oldTeststep.getRequest());
        } else {
            newTeststep.setRequest(teststepDAO().getBinaryRequestById(oldTeststep.getId()));
        }
        newTeststep.setRequestType(oldTeststep.getRequestType());
        newTeststep.setRequestFilename(oldTeststep.getRequestFilename());
        newTeststep.setOtherProperties(oldTeststep.getOtherProperties());
        Endpoint oldEndpoint = oldTeststep.getEndpoint();
        if (oldEndpoint != null) {
            Endpoint newEndpoint = new Endpoint();
            newTeststep.setEndpoint(newEndpoint);
            if (oldEndpoint.isManaged()) {
                newEndpoint.setId(oldEndpoint.getId());
            } else {
                newEndpoint.setName(oldEndpoint.getName());
                newEndpoint.setType(oldEndpoint.getType());
                newEndpoint.setDescription(oldEndpoint.getDescription());
                newEndpoint.setUrl(oldEndpoint.getUrl());
                newEndpoint.setUsername(oldEndpoint.getUsername());
                newEndpoint.setPassword(oldEndpoint.getPassword());
                newEndpoint.setOtherProperties(oldEndpoint.getOtherProperties());
            }
        }
        long newTeststepId = teststepDAO().insert_NoTransaction(newTeststep, null);
        // duplicate assertions
        for (Assertion oldAssertion : oldTeststep.getAssertions()) {
            Assertion newAssertion = new Assertion();
            newAssertion.setTeststepId(newTeststepId);
            newAssertion.setName(oldAssertion.getName());
            newAssertion.setType(oldAssertion.getType());
            newAssertion.setOtherProperties(oldAssertion.getOtherProperties());
            assertionDAO().insert_NoTransaction(newAssertion);
        }
    }
    return newTestcase.getId();
}
Also used : Teststep(io.irontest.models.teststep.Teststep) Testcase(io.irontest.models.Testcase) Endpoint(io.irontest.models.endpoint.Endpoint) Assertion(io.irontest.models.assertion.Assertion) Endpoint(io.irontest.models.endpoint.Endpoint)

Example 12 with Endpoint

use of io.irontest.models.endpoint.Endpoint in project irontest by zheng-wang.

the class TeststepDAO method deleteById_NoTransaction.

protected void deleteById_NoTransaction(long id) {
    Teststep teststep = findById_NoTransaction(id);
    _deleteById(id);
    // decrement sequence number of all next test steps
    batchMove(teststep.getTestcaseId(), (short) (teststep.getSequence() + 1), Short.MAX_VALUE, STEP_MOVE_DIRECTION_UP);
    Endpoint endpoint = teststep.getEndpoint();
    if (endpoint != null && !endpoint.isManaged()) {
        // delete the teststep's endpoint if it exists and is unmanaged
        endpointDAO().deleteById(endpoint.getId());
    }
}
Also used : Endpoint(io.irontest.models.endpoint.Endpoint)

Example 13 with Endpoint

use of io.irontest.models.endpoint.Endpoint in project irontest by zheng-wang.

the class TeststepDAO method populateTeststepWithMoreInfo.

private void populateTeststepWithMoreInfo(Teststep teststep) {
    Endpoint endpoint = endpointDAO().findById(teststep.getEndpoint().getId());
    teststep.setEndpoint(endpoint);
    teststep.setAssertions(assertionDAO().findByTeststepId(teststep.getId()));
}
Also used : Endpoint(io.irontest.models.endpoint.Endpoint)

Example 14 with Endpoint

use of io.irontest.models.endpoint.Endpoint in project irontest by zheng-wang.

the class TeststepDAO method insert_NoTransaction.

/**
 * This method considers test step insertion from both Create (test step) button on UI and test case duplicating.
 * @param teststep
 * @param appMode
 * @return
 * @throws JsonProcessingException
 */
public long insert_NoTransaction(Teststep teststep, AppMode appMode) throws JsonProcessingException {
    Endpoint endpoint = teststep.getEndpoint();
    if (endpoint == null) {
        // from test step creation on UI
        endpoint = endpointDAO().createUnmanagedEndpoint_NoTransaction(teststep.getType(), appMode);
    } else if (endpoint.getId() == 0) {
        // from test case duplicating
        long endpointId = endpointDAO().insertUnmanagedEndpoint_NoTransaction(endpoint);
        endpoint.setId(endpointId);
    }
    Object request = teststep.getRequest() instanceof String ? ((String) teststep.getRequest()).getBytes() : teststep.getRequest();
    String otherProperties = new ObjectMapper().writeValueAsString(teststep.getOtherProperties());
    long id = _insert(teststep, request, teststep.getRequestType().toString(), endpoint == null ? null : endpoint.getId(), otherProperties);
    if (teststep.getName() == null) {
        // from test step creation on UI
        teststep.setName("Step " + id);
    }
    updateNameForInsert(id, teststep.getName());
    return id;
}
Also used : Endpoint(io.irontest.models.endpoint.Endpoint) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with Endpoint

use of io.irontest.models.endpoint.Endpoint in project irontest by zheng-wang.

the class TeststepMapper method map.

public Teststep map(int index, ResultSet rs, StatementContext ctx) throws SQLException {
    List<String> fields = IronTestUtils.getFieldsPresentInResultSet(rs);
    Teststep teststep = null;
    String type = rs.getString("type");
    if (fields.contains("other_properties") && rs.getString("other_properties") != null) {
        String tempTeststepJSON = "{\"type\":\"" + type + "\",\"otherProperties\":" + rs.getString("other_properties") + "}";
        try {
            teststep = new ObjectMapper().readValue(tempTeststepJSON, Teststep.class);
        } catch (IOException e) {
            throw new SQLException("Failed to deserialize other_properties JSON.", e);
        }
    } else {
        teststep = new Teststep();
    }
    teststep.setId(rs.getLong("id"));
    teststep.setTestcaseId(rs.getLong("testcase_id"));
    teststep.setSequence(rs.getShort("sequence"));
    teststep.setName(rs.getString("name"));
    teststep.setType(type);
    teststep.setDescription(rs.getString("description"));
    teststep.setAction(fields.contains("action") ? rs.getString("action") : null);
    // this line must go before the 'if (fields.contains("request")) {' block
    teststep.setRequestType(fields.contains("request_type") ? TeststepRequestType.getByText(rs.getString("request_type")) : null);
    if (fields.contains("request")) {
        // no use of retrieving request file here
        Object request = teststep.getRequestType() == TeststepRequestType.FILE ? null : rs.getBytes("request") == null ? null : new String(rs.getBytes("request"));
        teststep.setRequest(request);
    }
    teststep.setRequestFilename(fields.contains("request_filename") ? rs.getString("request_filename") : null);
    if (fields.contains("endpoint_id")) {
        Endpoint endpoint = new Endpoint();
        endpoint.setId(rs.getLong("endpoint_id"));
        teststep.setEndpoint(endpoint);
    }
    teststep.setEndpointProperty(fields.contains("endpoint_property") ? rs.getString("endpoint_property") : null);
    return teststep;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) Endpoint(io.irontest.models.endpoint.Endpoint) SQLException(java.sql.SQLException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Endpoint (io.irontest.models.endpoint.Endpoint)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Teststep (io.irontest.models.teststep.Teststep)3 SQLException (java.sql.SQLException)3 Environment (io.irontest.models.Environment)2 IOException (java.io.IOException)2 DataTable (io.irontest.models.DataTable)1 Testcase (io.irontest.models.Testcase)1 UserDefinedProperty (io.irontest.models.UserDefinedProperty)1 Assertion (io.irontest.models.assertion.Assertion)1 MQEndpointProperties (io.irontest.models.endpoint.MQEndpointProperties)1 SOAPEndpointProperties (io.irontest.models.endpoint.SOAPEndpointProperties)1 HTTPHeader (io.irontest.models.teststep.HTTPHeader)1 SOAPTeststepProperties (io.irontest.models.teststep.SOAPTeststepProperties)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1