Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9add971c19f8bffda5b6b79cedcf15a082d4c9ca (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<%@ 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.ParamUtils
			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.api.gen.internal.utils.NameLoader
		   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();
Locale locale = info.getLanguage();
Iterator<INodePO> iterator = node.getNodeListIterator();
String packageBase = info.getPackageBasePath();
NameLoader nameLoader = NameLoader.getInstance();
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(
	<%if (node instanceof ISpecTestCasePO) {
		ISpecTestCasePO tc = (ISpecTestCasePO) node;
		Iterator<IParamDescriptionPO> paramIterator = tc.getParameterListIter();
		while (paramIterator.hasNext()) {
			IParamDescriptionPO param = paramIterator.next();
			String paramType = nameLoader.findTypeForParameter(param.getType(), StringConstants.EMPTY);
			String paramName = param.getName();%>
		<%=paramType%> <%=paramName%><%if(paramIterator.hasNext()){%>,<%}%>
		<%}%>
	<%}%>
	) {
		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;
				ConcreteComponent cc = null;
		      CompSystem compSystem = ComponentBuilder.getInstance().getCompSystem();
		      Component c = compSystem.getComponentForType(componentFromCap);
		      if (c instanceof ConcreteComponent) {
		          cc = (ConcreteComponent)c;            
		      }
				if (hasDefaultMapping) {
					String toolkitID = info.getDefaultToolkit();
					factoryName = Utils.getFactoryName(toolkitID);
			      ConcreteComponent componentToCreate = ToolkitSupportBP.getMostAbstractRealizingComponentInToolkit(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> childParamIterator = cap.getParameterListIter();
				while (childParamIterator.hasNext()) {
					IParamDescriptionPO param = childParamIterator.next();
					String paramType = param.getUniqueId();
					String enumType = nameLoader.getEnumForParam(paramType);
					String paramValue = ParamUtils.getValueForParam(cap, param, locale);
					Boolean isEnum = enumType != null;%>
				<%if (isEnum) {%><%=enumType%>.valueOf(<%}%><%=paramValue%><%if (isEnum) {%>)<%}%><%if(childParamIterator.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(
				<%Iterator<IParamDescriptionPO> childParamIterator = exec.getParameterListIter();
				while (childParamIterator.hasNext()) {
					IParamDescriptionPO param = childParamIterator.next();
					String paramValue = ParamUtils.getValueForParam(exec, param, locale);%>
				<%=paramValue%><%if(childParamIterator.hasNext()){%>,<%}%>
				<%}%>
				);
			<%} 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