use of com.twinsoft.convertigo.beans.variables.TestCaseVariable in project convertigo by convertigo.
the class ChangeToSingleValuedVariableAction method run.
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
Object databaseObject = treeObject.getObject();
if (databaseObject != null) {
Variable multi = (Variable) databaseObject;
Variable simple = null;
if (databaseObject instanceof TestCaseMultiValuedVariable)
simple = new TestCaseVariable();
if (databaseObject instanceof StepMultiValuedVariable)
simple = new StepVariable();
if (databaseObject instanceof RequestableMultiValuedVariable)
simple = new RequestableVariable();
if (databaseObject instanceof RequestableHttpMultiValuedVariable)
simple = new RequestableHttpVariable();
if (databaseObject instanceof HttpStatementMultiValuedVariable)
simple = new HttpStatementVariable();
if (simple != null) {
if (multi instanceof StepMultiValuedVariable) {
((StepVariable) simple).setSourceDefinition(((StepVariable) multi).getSourceDefinition());
}
if (multi instanceof RequestableVariable) {
((RequestableVariable) simple).setXmlTypeAffectation(((RequestableVariable) multi).getXmlTypeAffectation());
}
if (multi instanceof RequestableHttpVariable) {
// HttpName
((RequestableHttpVariable) simple).setHttpName(((RequestableHttpVariable) multi).getHttpName());
// HttpMethod
((RequestableHttpVariable) simple).setHttpMethod(((RequestableHttpVariable) multi).getHttpMethod());
}
XMLVector<Object> xmlv = GenericUtils.cast(multi.getValueOrNull());
Object value = (xmlv == null) ? null : (xmlv.isEmpty() ? "" : xmlv.get(0).toString());
simple.setValueOrNull(value);
simple.setVisibility(multi.getVisibility());
// Comment
simple.setComment(multi.getComment());
// Description
simple.setDescription(multi.getDescription());
// Required
simple.setRequired(multi.isRequired());
simple.bNew = true;
simple.hasChanged = true;
// Add new variable to parent
DatabaseObject parentDbo = multi.getParent();
parentDbo.add(simple);
// Set correct order
if (parentDbo instanceof TestCase)
((TestCase) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof RequestableStep)
((RequestableStep) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof TransactionWithVariables)
((TransactionWithVariables) parentDbo).insertAtOrder(simple, multi.priority);
if (parentDbo instanceof HTTPStatement)
((HTTPStatement) parentDbo).insertAtOrder(simple, multi.priority);
// Add new variable in Tree
VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, simple);
treeParent.addChild(varTreeObject);
// Delete simple variable
multi.delete();
// Set correct name
simple.setName(multi.getName());
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(simple));
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change simple variable to multi valuated variable!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.variables.TestCaseVariable in project convertigo by convertigo.
the class ChangeToMultiValuedVariableAction method run.
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
Object databaseObject = treeObject.getObject();
if (databaseObject != null) {
Variable simple = (Variable) databaseObject;
Variable multi = null;
if (databaseObject instanceof TestCaseVariable)
multi = new TestCaseMultiValuedVariable();
if (databaseObject instanceof StepVariable)
multi = new StepMultiValuedVariable();
if (databaseObject instanceof RequestableVariable)
multi = new RequestableMultiValuedVariable();
if (databaseObject instanceof RequestableHttpVariable)
multi = new RequestableHttpMultiValuedVariable();
if (databaseObject instanceof HttpStatementVariable)
multi = new HttpStatementMultiValuedVariable();
if (multi != null) {
if (multi instanceof StepVariable) {
((StepVariable) multi).setSourceDefinition(((StepVariable) simple).getSourceDefinition());
}
if (multi instanceof RequestableVariable) {
((RequestableVariable) multi).setXmlTypeAffectation(((RequestableVariable) simple).getXmlTypeAffectation());
}
if (multi instanceof RequestableHttpVariable) {
// HttpName
((RequestableHttpVariable) multi).setHttpName(((RequestableHttpVariable) simple).getHttpName());
// HttpMethod
((RequestableHttpVariable) multi).setHttpMethod(((RequestableHttpVariable) simple).getHttpMethod());
}
Object value = simple.getValueOrNull();
multi.setValueOrNull(value);
multi.setVisibility(simple.getVisibility());
// Comment
multi.setComment(simple.getComment());
// Description
multi.setDescription(simple.getDescription());
// Required
multi.setRequired(simple.isRequired());
multi.bNew = true;
multi.hasChanged = true;
// Add new variable to parent
DatabaseObject parentDbo = simple.getParent();
parentDbo.add(multi);
// Set correct order
if (parentDbo instanceof TestCase)
((TestCase) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof RequestableStep)
((RequestableStep) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof Sequence)
((Sequence) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof TransactionWithVariables)
((TransactionWithVariables) parentDbo).insertAtOrder(multi, simple.priority);
if (parentDbo instanceof HTTPStatement)
((HTTPStatement) parentDbo).insertAtOrder(multi, simple.priority);
// Add new variable in Tree
VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, multi);
treeParent.addChild(varTreeObject);
// Delete simple variable
simple.delete();
// Set correct name
multi.setName(simple.getName());
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(multi));
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change simple variable to multi valuated variable!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.variables.TestCaseVariable in project convertigo by convertigo.
the class TestCase method getAllChildren.
@Override
public List<DatabaseObject> getAllChildren() {
List<DatabaseObject> rep = super.getAllChildren();
List<TestCaseVariable> variables = getAllVariables();
for (TestCaseVariable variable : variables) {
rep.add(variable);
}
return rep;
}
use of com.twinsoft.convertigo.beans.variables.TestCaseVariable in project convertigo by convertigo.
the class TransactionWithVariables method parseInputDocument.
@Override
public void parseInputDocument(Context context) throws EngineException {
super.parseInputDocument(context);
if (context.inputDocument != null && Engine.logContext.isInfoEnabled()) {
Document printDoc = (Document) Visibility.Logs.replaceVariables(getVariablesList(), context.inputDocument);
XMLUtils.logXml(printDoc, Engine.logContext, "Input document");
}
NodeList variableNodes = context.inputDocument.getElementsByTagName("variable");
Element variableNode;
Attr valueAttrNode;
int len = variableNodes.getLength();
String variableName, variableValue, variableMethod;
RequestableVariable variable;
boolean bMulti;
// TODO: handle persistent variables
variables.clear();
for (int i = 0; i < len; i++) {
bMulti = false;
variableNode = (Element) variableNodes.item(i);
variableName = variableNode.getAttribute("name");
variableValue = (variableNode.hasAttribute("value") ? variableNode.getAttribute("value") : null);
valueAttrNode = variableNode.getAttributeNode("value");
variableMethod = null;
// Test case for transaction
if (variableName.indexOf(Parameter.Testcase.getName()) == 0) {
TestCase testcase = getTestCaseByName(variableValue);
if (testcase != null) {
String testCaseVariableName;
Object testCaseVariableValue;
// Add test case variables default value(s)
for (TestCaseVariable testCaseVariable : testcase.getVariables()) {
testCaseVariableName = testCaseVariable.getName();
testCaseVariableValue = testcase.getVariableValue(testCaseVariableName);
if (testCaseVariableValue != null) {
variables.put(testCaseVariableName, testCaseVariableValue);
}
}
} else {
Engine.logBeans.warn("Transaction: there's no testcase named '" + variableValue + "' for '" + getName() + "' transaction");
}
continue;
} else // May be a dynamic transaction variable definition
if ((variableName.indexOf(Parameter.DynamicVariablePost.getName()) == 0) || (variableName.indexOf(Parameter.DynamicVariableGet.getName()) == 0)) {
bMulti = variableNode.getAttribute("multi").equalsIgnoreCase("true");
if (variableName.indexOf(Parameter.DynamicVariablePost.getName()) == 0) {
variableName = variableName.substring(Parameter.DynamicVariablePost.getName().length());
variableMethod = "POST";
} else if (variableName.indexOf(Parameter.DynamicVariableGet.getName()) == 0) {
variableName = variableName.substring(Parameter.DynamicVariableGet.getName().length());
variableMethod = "GET";
}
// retrieve variable definition
variable = (RequestableVariable) getVariable(variableName);
if (variableMethod != null) {
setDynamicVariable(variableName, variableValue, Boolean.valueOf(bMulti), variableMethod);
}
} else // Serialized variables definition
{
variable = (RequestableVariable) getVariable(variableName);
}
// Structured value?
Object scopeValue = null;
if (getProject().isStrictMode()) {
scopeValue = (variableValue != null) ? variableValue : variableNode.getChildNodes();
} else {
if (variableValue != null) {
scopeValue = variableValue;
} else {
String sValue = XMLUtils.prettyPrintElement(variableNode, true, false);
sValue = sValue.replaceAll("<variable name=\"" + variableName + "\">", "");
sValue = sValue.replaceAll("</variable>", "");
scopeValue = sValue;
}
}
// Multivalued variable ?
if ((variable != null) && (variable.isMultiValued())) {
List<Object> current = GenericUtils.cast(variables.get(variableName));
if (current == null) {
current = new ArrayList<Object>();
variables.put(variableName, current);
}
if (variableValue == null || valueAttrNode != null) {
current.add(scopeValue);
}
} else {
variables.put(variableName, scopeValue);
}
}
// Enumeration of all transaction variables
if (Engine.logBeans.isDebugEnabled())
Engine.logBeans.debug("Transaction variables: " + (variables == null ? "none" : Visibility.Logs.replaceVariables(getVariablesList(), variables)));
}
use of com.twinsoft.convertigo.beans.variables.TestCaseVariable in project convertigo by convertigo.
the class Sequence method parseInputDocument.
@Override
public void parseInputDocument(Context context) throws EngineException {
super.parseInputDocument(context);
if (context.inputDocument != null && Engine.logContext.isInfoEnabled()) {
Document printDoc = (Document) Visibility.Logs.replaceVariables(getVariablesList(), context.inputDocument);
XMLUtils.logXml(printDoc, Engine.logContext, "Input document");
}
NodeList variableNodes = context.inputDocument.getElementsByTagName("variable");
int len = variableNodes.getLength();
variables.clear();
for (int i = 0; i < len; i++) {
Element variableNode = (Element) variableNodes.item(i);
String variableName = variableNode.getAttribute("name");
String variableValue = (variableNode.hasAttribute("value") ? variableNode.getAttribute("value") : null);
Attr valueAttrNode = variableNode.getAttributeNode("value");
// Test case for sequence
if (variableName.indexOf(Parameter.Testcase.getName()) == 0) {
TestCase testcase = getTestCaseByName(variableValue);
if (testcase != null) {
String testCaseVariableName;
Object testCaseVariableValue;
// Add test case variables default value(s)
for (TestCaseVariable testCaseVariable : testcase.getVariables()) {
testCaseVariableName = testCaseVariable.getName();
testCaseVariableValue = testcase.getVariableValue(testCaseVariableName);
if (testCaseVariableValue != null) {
variables.put(testCaseVariableName, testCaseVariableValue);
}
}
} else {
if (Engine.logBeans.isInfoEnabled())
Engine.logBeans.warn("Sequence: there's no testcase named '" + variableValue + "' for '" + getName() + "' sequence");
}
continue;
}
// Standard variable case
RequestableVariable variable = (RequestableVariable) getVariable(variableName);
// Structured value?
Object scopeValue = (variableValue != null) ? variableValue : variableNode.getChildNodes();
// Multivalued variable ?
if ((variable != null) && (variable.isMultiValued())) {
List<Object> current = GenericUtils.cast(variables.get(variableName));
if (current == null) {
current = new LinkedList<Object>();
variables.put(variableName, current);
}
if (variableValue == null || valueAttrNode != null) {
current.add(scopeValue);
}
} else {
variables.put(variableName, scopeValue);
}
}
// Enumeration of all sequence variables
if (Engine.logBeans.isDebugEnabled())
Engine.logBeans.debug("Sequence variables: " + (variables == null ? "none" : Visibility.Logs.replaceVariables(getVariablesList(), variables)));
}
Aggregations