Skip to main content
summaryrefslogtreecommitdiffstats
blob: d41454bb91ade75e3162a5b311585baef6589ae4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<%@ jet 
package="org.eclipse.jubula.client.api.converter" 
imports="java.util.*
			org.apache.commons.lang.StringUtils
			org.eclipse.jubula.client.api.converter.exceptions.InvalidNodeNameException
			org.eclipse.jubula.client.api.converter.utils.CompNameLoader
			org.eclipse.jubula.client.api.converter.utils.ProjectCache
			org.eclipse.jubula.client.api.converter.utils.Utils
			org.eclipse.jubula.client.core.model.ICapPO
		   org.eclipse.jubula.client.core.model.IExecTestCasePO
			org.eclipse.jubula.client.core.model.INodePO
			org.eclipse.jubula.client.core.model.IParamDescriptionPO
			org.eclipse.jubula.client.core.model.IProjectPO
			org.eclipse.jubula.client.core.model.IRefTestSuitePO
		   org.eclipse.jubula.client.core.model.ISpecTestCasePO
			org.eclipse.jubula.client.core.model.ITestSuitePO
		   org.eclipse.jubula.client.ui.rcp.Plugin
		   org.eclipse.jubula.toolkit.common.businessprocess.ToolkitSupportBP
		   org.eclipse.jubula.toolkit.common.xml.businessprocess.ComponentBuilder
		   org.eclipse.jubula.tools.internal.constants.StringConstants
		   org.eclipse.jubula.tools.internal.exception.JBException
		   org.eclipse.jubula.tools.internal.xml.businessmodell.ConcreteComponent
		   org.eclipse.jubula.tools.internal.xml.businessmodell.CompSystem
			org.eclipse.jubula.tools.internal.xml.businessmodell.Component
		   org.slf4j.Logger
			org.slf4j.LoggerFactory"
class="NodeGenerator"%>
<%
Logger log = LoggerFactory.getLogger(NodeGenerator.class);

NodeInfo info = (NodeInfo)argument;
String className = info.getClassName();
INodePO node = info.getNode();
Iterator<INodePO> iterator = node.getNodeListIterator();
String packageBase = info.getPackageBasePath();
IProjectPO project = null;
try {
	project = ProjectCache.get(node.getParentProjectId());
} catch (JBException e) {
	Plugin.getDefault().writeErrorLineToConsole(
                        "Error while loading project.", true);
   return StringConstants.EMPTY;
}
String projectName = null;
try {
    projectName = Utils.translateToPackageName(project);
} catch (InvalidNodeNameException e) {
    log.error(e.getLocalizedMessage());
}
String fqName = Utils.getFullyQualifiedTranslatedName(node, packageBase, projectName);
String packageName = StringUtils.substringBeforeLast(fqName, StringConstants.DOT);
%>
package <%=packageName%>;

import org.eclipse.jubula.client.AUT;

public class <%=className%> {
	
	public static void execute() {
		AUT aut = null;
	
		<%while (iterator.hasNext()) {
			INodePO child = iterator.next();
			if (child instanceof ICapPO) {
				ICapPO cap = (ICapPO) child;
				String componentFromCap = cap.getComponentType();
				CompNameLoader loader = new CompNameLoader(componentFromCap);
				String actionName = loader.get(cap.getActionName());
				boolean hasDefaultMapping = loader.get("hasDefaultMapping").equals("true");
				String componentNameToCreate;
				String factoryName;
				if (hasDefaultMapping) {
					String toolkitID = info.getDefaultToolkit();
					factoryName = Utils.getFactoryName(toolkitID);
					ConcreteComponent cc = null;
			      CompSystem compSystem = ComponentBuilder.getInstance().getCompSystem();
			      Component c = compSystem.getComponentForType(componentFromCap);
			      if (c instanceof ConcreteComponent) {
			          cc = (ConcreteComponent)c;            
			      }
			      ConcreteComponent componentToCreate = ToolkitSupportBP.getMostConcreteRealizingComponentInToolkit(toolkitID, cc);
					CompNameLoader newLoader = new CompNameLoader(componentToCreate.getType());
					componentNameToCreate = newLoader.get("componentTypeName");
				} else {
					factoryName = loader.get("factoryName");
					componentNameToCreate = loader.get("componentTypeName");
				}
				if (actionName != null) {%>
		aut.execute(
			<%=factoryName%>.create<%=componentNameToCreate%>(<%if (!hasDefaultMapping) {%>null<%}%>)
				.<%=actionName%>(
				<%Iterator<IParamDescriptionPO> paramIterator = cap.getParameterList().iterator();
					while (paramIterator.hasNext()) {
						IParamDescriptionPO param = paramIterator.next();%>
					null<%if(paramIterator.hasNext()){%>,<%}%>
					<%}%>
				),
			null);
				<%} else {%>
		// TODO: You tried to convert the client action <%=cap.getActionName()%> for the component <%=cap.getComponentType()%>.
				<%}%>
			<%} else if (child instanceof IExecTestCasePO) {
				IExecTestCasePO exec = (IExecTestCasePO)child;
				ISpecTestCasePO spec = exec.getSpecTestCase();
				String testCaseName = StringConstants.EMPTY;
				try {
					project = ProjectCache.get(spec.getParentProjectId());
				} catch (JBException e) {
					Plugin.getDefault().writeErrorLineToConsole(
				                        "Error while loading project.", true);
				   return StringConstants.EMPTY;
				}
				try {
				    projectName = Utils.translateToPackageName(project);
				} catch (InvalidNodeNameException e) {
				    log.error(e.getLocalizedMessage());
				}
				testCaseName = Utils.getFullyQualifiedTranslatedName(spec, packageBase, projectName);%>
		<%=testCaseName%>.execute();
			<%} else if (child instanceof IRefTestSuitePO) {
				IRefTestSuitePO ref = (IRefTestSuitePO)child;
				ITestSuitePO testSuite = ref.getTestSuite();
				String testSuiteName = StringConstants.EMPTY;
				try {
				project = ProjectCache.get(testSuite.getParentProjectId());
				} catch (JBException e) {
					Plugin.getDefault().writeErrorLineToConsole(
				                        "Error while loading project.", true);
				   return StringConstants.EMPTY;
				}
				try {
				    projectName = Utils.translateToPackageName(project);
				} catch (InvalidNodeNameException e) {
				    log.error(e.getLocalizedMessage());
				}
				testSuiteName = Utils.getFullyQualifiedTranslatedName(testSuite, packageBase, projectName);%>
		<%=testSuiteName%>.execute();
			<%}%>
		<%}%>
	}
}

Back to the top