Skip to main content
summaryrefslogtreecommitdiffstats
blob: 772847db1d797c03756c1ac1c2adbb5e3533e031 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<%@ 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.IEventExecTestCasePO
         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.IParameterInterfacePO
         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.ITestJobPO
         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.eclipse.jubula.client.api.converter.annotations.NodeType
         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();
String uuid = node.getGuid();
String comment = node.getComment();
boolean hasComment = StringUtils.isNotBlank(comment);
String taskId = node.getTaskId();
boolean hasTaskId = StringUtils.isNotBlank(taskId);
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);
String ctdsPath = Utils.getProjectPath(info.getPackageBasePath(), projectName);

NodeType type = NodeType.UNKNOWN;
if (node instanceof ISpecTestCasePO) {
    type = NodeType.TEST_CASE;
} else if (node instanceof ITestJobPO) {
    type = NodeType.TEST_JOB;
} else if (node instanceof ITestSuitePO) {
    type = NodeType.TEST_SUITE;
}

%>
package <%=packageName%>;

import org.eclipse.jubula.client.AUT;
import org.eclipse.jubula.client.api.converter.annotations.SrcNode;
import org.eclipse.jubula.client.api.converter.annotations.NodeType;

import <%=ctdsPath%>.CTDS;

@SrcNode(UUID = "<%=uuid%>",
         type = NodeType.<%=type%><%if (hasTaskId) {%>, taskId = "<%=taskId%>"<%}%>)
public class <%=className%> {
    
    <%if (hasComment) {%>/** <%=comment%> */<%}%>
    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();
            boolean isActive = child.isActive();
            comment = child.getComment();
            hasComment = StringUtils.isNotBlank(comment);
        
        if (hasComment) {%>// <%=comment%><%}
            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) {%>
        
        <%if (!isActive) {%>//<%}%>aut.execute(
            
            <%if (!isActive) {%>//<%}%><%=factoryName%>.create<%=componentNameToCreate%>(<%if (!hasDefaultMapping) {%>null<%}%>)
                
                <%if (!isActive) {%>//<%}%>.<%=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, 0, locale);
                    Boolean isEnum = enumType != null;
                    String enumLookupMethodName = isEnum && (!enumType.endsWith(".Operator")) ? "valueOf": "literalAsEnum";%>
                    
                <%if (!isActive) {%>//<%}%><%if (isEnum) {%><%=enumType%>.<%=enumLookupMethodName%>(<%}%><%=paramValue%><%if (isEnum) {%>)<%}%>
                    
                <%if(childParamIterator.hasNext()){%><%if (!isActive) {%>//<%}%>,<%}%>
                <%}
                if (!isActive) {%>//<%}%>),
            
            <%if (!isActive) {%>//<%}%>null);
            
                <%} else {%>
        
        // TODO: Client action <%=cap.getActionName()%>.

                <%}%>
            <%} else if (child instanceof IExecTestCasePO) {
                IExecTestCasePO exec = (IExecTestCasePO)child;
                ISpecTestCasePO spec = exec.getSpecTestCase();
                for (IEventExecTestCasePO eventTC : spec.getAllEventEventExecTC()) {
                    String type = eventTC.getEventType();
                    String reentryProp = eventTC.getReentryProp().toString();
                    String eventHandlerName = StringConstants.EMPTY;
                    ISpecTestCasePO specEventHandler = eventTC.getSpecTestCase();
                    try {
                        project = ProjectCache.get(specEventHandler.getParentProjectId());
                    } catch (JBException e) {
                        Plugin.getDefault().writeErrorLineToConsole(
                                            "Error while loading project.", true);
                    }
                    try {
                        projectName = Utils.translateToPackageName(project);
                    } catch (InvalidNodeNameException e) {
                        log.error(e.getLocalizedMessage());
                    }
                    eventHandlerName = Utils.getFullyQualifiedTranslatedName(specEventHandler, packageBase, projectName);
                    Iterator<IParamDescriptionPO> childParamIterator;
                    IParameterInterfacePO dataCube = eventTC.getReferencedDataCube();%>
        // TODO: The following test case used an Event Handler which you have to replace manually:
        //       Type: <%=type%>
        //       Re-Entry Property: <%=reentryProp%>
        //       Used Test Case:
                    <%if (dataCube == null) {
                      int rowCount = eventTC.getDataManager().getDataSetCount();
                      int row = 0;
                      do {%>
        //            <%=eventHandlerName%>.execute(
                          <%childParamIterator = eventTC.getParameterListIter();
                          while (childParamIterator.hasNext()) {
                              IParamDescriptionPO param = childParamIterator.next();
                              String paramValue = ParamUtils.getValueForParam(eventTC, param, row, locale);%>
        //                <%=paramValue%><%if(childParamIterator.hasNext()){%>,<%}%>
                          <%}%>
                          <%row++;%>
        //            );
                      <%} while(row < rowCount);
                    }
                }
                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);
                Iterator<IParamDescriptionPO> childParamIterator;
                IParameterInterfacePO dataCube = exec.getReferencedDataCube();
              if (dataCube == null) {
                int rowCount = exec.getDataManager().getDataSetCount();
                int row = 0;
                do {%>
        
        <%if (!isActive) {%>//<%}%><%=testCaseName%>.execute(
                    <%childParamIterator = exec.getParameterListIter();
                    while (childParamIterator.hasNext()) {
                        IParamDescriptionPO param = childParamIterator.next();
                        String paramValue = ParamUtils.getValueForParam(exec, param, row, locale);%>
            
            <%if (!isActive) {%>//<%}%><%=paramValue%><%if(childParamIterator.hasNext()){%>
            
            <%if (!isActive) {%>//<%}%>,<%}%>
                    <%}%>
                    <%row++;%>
        
        <%if (!isActive) {%>//<%}%>);
                <%} while(row < rowCount);
              } else {
                String dataCubeName = null;
                try {
                    dataCubeName = Utils.determineClassName(dataCube);
                } catch (InvalidNodeNameException e) {
                    log.error("Invalid Data Set Name", e);
                }%>
        for (CTDS.<%=dataCubeName%> row : CTDS.<%=dataCubeName%>.data) {
            
            <%if (!isActive) {%>//<%}%><%=testCaseName%>.execute(
                
                    <%childParamIterator = exec.getParameterListIter();
                    while (childParamIterator.hasNext()) {
                        IParamDescriptionPO param = childParamIterator.next();
                
                if (!isActive) {%>//<%}%>row.<%=param.getName()%><%if(childParamIterator.hasNext()){%>,<%}%>
                
                    <%}%>
                <%if (!isActive) {%>//<%}%>);
        }
              <%}%>
        
            <%} 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);%>
        
        <%if (!isActive) {%>/* <%}%><%=testSuiteName%>.execute();<%if (!isActive) {%>*/<%}%>
        
            <%}%>
        <%}%>
    }
}

Back to the top