Search in sources :

Example 16 with TestCase

use of com.twinsoft.convertigo.beans.core.TestCase 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 17 with TestCase

use of com.twinsoft.convertigo.beans.core.TestCase 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

TestCase (com.twinsoft.convertigo.beans.core.TestCase)17 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)8 Sequence (com.twinsoft.convertigo.beans.core.Sequence)8 Transaction (com.twinsoft.convertigo.beans.core.Transaction)7 TestCaseVariable (com.twinsoft.convertigo.beans.variables.TestCaseVariable)7 Connector (com.twinsoft.convertigo.beans.core.Connector)6 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)6 EngineException (com.twinsoft.convertigo.engine.EngineException)6 Variable (com.twinsoft.convertigo.beans.core.Variable)5 WalkHelper (com.twinsoft.convertigo.engine.helpers.WalkHelper)5 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)4 Criteria (com.twinsoft.convertigo.beans.core.Criteria)4 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)4 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)4 Sheet (com.twinsoft.convertigo.beans.core.Sheet)4 Statement (com.twinsoft.convertigo.beans.core.Statement)4 TransactionWithVariables (com.twinsoft.convertigo.beans.core.TransactionWithVariables)4 HTTPStatement (com.twinsoft.convertigo.beans.statements.HTTPStatement)4 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)4 ExtractionRule (com.twinsoft.convertigo.beans.core.ExtractionRule)3