Search in sources :

Example 11 with TestCaseVariable

use of com.twinsoft.convertigo.beans.variables.TestCaseVariable in project convertigo by convertigo.

the class DefaultInternalTranslator method buildInputDocument.

public void buildInputDocument(Context context, Object inputData) throws Exception {
    Engine.logContext.debug("Making input document");
    Map<String, Object> request = GenericUtils.cast(inputData);
    InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context);
    // Indicates whether variable values were generated using strict mode or nor(text/childs only)
    inputDocumentBuilder.transactionVariablesElement.setAttribute("strictMode", Boolean.toString(bStrictMode));
    for (Entry<String, Object> entry : request.entrySet()) {
        String parameterName = entry.getKey();
        Object parameterObject = entry.getValue();
        if (!inputDocumentBuilder.handleSpecialParameter(parameterName, parameterObject)) {
            if (parameterObject instanceof String[]) {
                inputDocumentBuilder.addVariable(parameterName, (String[]) parameterObject);
            } else {
                addParameterObject(context.inputDocument, inputDocumentBuilder.transactionVariablesElement, parameterName, parameterObject);
            }
        }
    }
    TestCase tc = TestCase.getTestCase(request, context.projectName);
    if (tc != null) {
        for (TestCaseVariable var : tc.getVariables()) {
            String parameterName = var.getName();
            Object parameterObject = var.getValueOrNull();
            if (parameterObject == null) {
                // ignore variables set to <null>
                continue;
            }
            if (!request.containsKey(parameterName) && !inputDocumentBuilder.handleSpecialParameter(parameterName, parameterObject)) {
                if (parameterObject instanceof XMLVector) {
                    String[] strings = ((XMLVector<?>) parameterObject).toArray(new String[0]);
                    inputDocumentBuilder.addVariable(parameterName, strings);
                } else {
                    addParameterObject(context.inputDocument, inputDocumentBuilder.transactionVariablesElement, parameterName, parameterObject);
                }
            }
        }
    }
    Engine.logContext.info("Input document created");
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) TestCase(com.twinsoft.convertigo.beans.core.TestCase) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable)

Example 12 with TestCaseVariable

use of com.twinsoft.convertigo.beans.variables.TestCaseVariable in project convertigo by convertigo.

the class DefaultServletTranslator method buildInputDocument.

public void buildInputDocument(Context context, Object inputData) throws Exception {
    Engine.logContext.debug("Making input document");
    HttpServletRequest request = (HttpServletRequest) inputData;
    InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context);
    // We transform the HTTP post data into XML data.
    Enumeration<?> parameterNames = request.getParameterNames();
    // Sometimes, because of a bug about bad recycling of request facade objects in Tomcat,
    // the HTTP parameters parsing is not realized, and then parameterNames is empty. In
    // such a case, a (bad) workaround is to decode by ourselves the query string in GET
    // or the HTTP body in POST...
    // Map<String, String[]> reparsedParameters = (Map<String, String[]>) request.getAttribute(ServletRequester.REPARSED_PARAMETERS_ATTRIBUTE);
    // boolean bReparsedParameters = (reparsedParameters != null);
    // if (bReparsedParameters) {
    // parameterNames = reparsedParameters.keys();
    // }
    boolean isHandleComplex = "true".equals(request.getParameter("__handleComplex"));
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        String[] parameterValues = request.getParameterValues(parameterName);
        if (!inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValues)) {
            inputDocumentBuilder.addVariable(parameterName, parameterValues, isHandleComplex);
        }
    }
    TestCase tc = TestCase.getTestCase(request, context.projectName);
    if (tc != null) {
        for (TestCaseVariable var : tc.getVariables()) {
            String parameterName = var.getName();
            if (request.getParameter(parameterName) == null) {
                Object parameterObject = var.getValueOrNull();
                String[] parameterValues = (parameterObject instanceof XMLVector<?>) ? ((XMLVector<?>) parameterObject).toArray(new String[0]) : new String[] { (String) parameterObject };
                if (!inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValues)) {
                    inputDocumentBuilder.addVariable(parameterName, parameterValues, isHandleComplex);
                }
            }
        }
    }
    Engine.logContext.debug("Input document created");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) TestCase(com.twinsoft.convertigo.beans.core.TestCase) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable)

Aggregations

TestCaseVariable (com.twinsoft.convertigo.beans.variables.TestCaseVariable)12 TestCase (com.twinsoft.convertigo.beans.core.TestCase)7 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)5 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)3 TestCaseMultiValuedVariable (com.twinsoft.convertigo.beans.variables.TestCaseMultiValuedVariable)3 EngineException (com.twinsoft.convertigo.engine.EngineException)3 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)2 Sequence (com.twinsoft.convertigo.beans.core.Sequence)2 TransactionWithVariables (com.twinsoft.convertigo.beans.core.TransactionWithVariables)2 Variable (com.twinsoft.convertigo.beans.core.Variable)2 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)2 HttpStatementMultiValuedVariable (com.twinsoft.convertigo.beans.variables.HttpStatementMultiValuedVariable)2 HttpStatementVariable (com.twinsoft.convertigo.beans.variables.HttpStatementVariable)2 RequestableHttpMultiValuedVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable)2 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)2 RequestableMultiValuedVariable (com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable)2 StepMultiValuedVariable (com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable)2 StepVariable (com.twinsoft.convertigo.beans.variables.StepVariable)2 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)2