Source Code Cross Referenced for TestMethods.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » ihm » main » datawrapper » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Test Coverage » salome tmf » org.objectweb.salome_tmf.ihm.main.datawrapper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SalomeTMF is a Test Management Framework
003:         * Copyright (C) 2005 France Telecom R&D
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *
019:         * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.ihm.main.datawrapper;
025:
026:        import java.awt.Component;
027:        import java.io.BufferedWriter;
028:        import java.io.File;
029:        import java.io.FileWriter;
030:        import java.io.IOException;
031:        import java.sql.Date;
032:        import java.sql.Time;
033:        import java.util.ArrayList;
034:        import java.util.GregorianCalendar;
035:        import java.util.HashMap;
036:        import java.util.HashSet;
037:        import java.util.Hashtable;
038:        import java.util.Iterator;
039:        import java.util.Properties;
040:        import java.util.Set;
041:        import java.util.Vector;
042:
043:        import javax.swing.JOptionPane;
044:
045:        import org.java.plugin.Extension;
046:        import org.objectweb.salome_tmf.api.Api;
047:        import org.objectweb.salome_tmf.api.ApiConstants;
048:        import org.objectweb.salome_tmf.api.Util;
049:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
050:        import org.objectweb.salome_tmf.data.Action;
051:        import org.objectweb.salome_tmf.data.AutomaticTest;
052:        import org.objectweb.salome_tmf.data.Campaign;
053:        import org.objectweb.salome_tmf.data.DataConstants;
054:        import org.objectweb.salome_tmf.data.DataSet;
055:        import org.objectweb.salome_tmf.data.Environment;
056:        import org.objectweb.salome_tmf.data.Execution;
057:        import org.objectweb.salome_tmf.data.ExecutionResult;
058:        import org.objectweb.salome_tmf.data.ExecutionTestResult;
059:        import org.objectweb.salome_tmf.data.ManualTest;
060:        import org.objectweb.salome_tmf.data.Parameter;
061:        import org.objectweb.salome_tmf.data.Project;
062:        import org.objectweb.salome_tmf.data.Script;
063:        import org.objectweb.salome_tmf.data.SimpleData;
064:        import org.objectweb.salome_tmf.data.Test;
065:        import org.objectweb.salome_tmf.ihm.languages.Language;
066:        import org.objectweb.salome_tmf.ihm.main.AutomaticExecution;
067:        import org.objectweb.salome_tmf.ihm.main.ExecutionView;
068:        import org.objectweb.salome_tmf.ihm.main.ManualExecution;
069:        import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
070:        import org.objectweb.salome_tmf.ihm.models.ScriptExecutionException;
071:        import org.objectweb.salome_tmf.ihm.tools.Tools;
072:        import org.objectweb.salome_tmf.plugins.core.ScriptEngine;
073:        import org.objectweb.salome_tmf.plugins.core.TestDriver;
074:
075:        public class TestMethods implements  ApiConstants, DataConstants {
076:
077:            //  static CallScript c = null;
078:            static ScriptEngine pEngine = null;
079:            static TestDriver driver = null;
080:
081:            public static String notValuedParamListCreation(HashSet setOfParam,
082:                    Environment env, DataSet dataSet,
083:                    ArrayList notValuedParamList) {
084:                String message = "";
085:                for (Iterator iter = setOfParam.iterator(); iter.hasNext();) {
086:                    Parameter param = (Parameter) iter.next();
087:                    if (!env.containsParameterInModel(param)
088:                            && !dataSet.getParametersHashMapFromModel()
089:                                    .containsKey(param.getNameFromModel())) {
090:                        notValuedParamList.add(param);
091:                        message = message + "* " + param.getNameFromModel()
092:                                + "\n";
093:                    } else if (!env.containsParameterInModel(param)
094:                            && dataSet.getParametersHashMapFromModel()
095:                                    .containsKey(param.getNameFromModel())
096:                            && dataSet.getParameterValueFromModel(
097:                                    param.getNameFromModel()).equals(
098:                                    DataConstants.PARAM_VALUE_FROM_ENV)) {
099:                        notValuedParamList.add(param);
100:                        message = message + "* " + param.getNameFromModel()
101:                                + "\n";
102:                    }
103:                }
104:                return message;
105:            }
106:
107:            public static String notValuedParamListInDataSet(
108:                    HashSet setOfParam, DataSet dataSet,
109:                    ArrayList notValuedParamList) {
110:                String message = "";
111:                for (Iterator iter = setOfParam.iterator(); iter.hasNext();) {
112:                    Parameter param = (Parameter) iter.next();
113:                    if (!dataSet.getParametersHashMapFromModel().containsKey(
114:                            param.getNameFromModel())) {
115:                        notValuedParamList.add(param);
116:                        message = message + "* " + param.getNameFromModel()
117:                                + "\n";
118:                    }
119:                }
120:                return message;
121:            }
122:
123:            /**
124:             * M?thode pour appeler un script bsh
125:             * @param args les param?tres du script
126:             * @param script le script
127:             */
128:            public static String callScript(HashMap params, Script script,
129:                    AutomaticTest test, Campaign campaign, Project project,
130:                    Environment env, ExecutionResult execResult,
131:                    Execution exec, ExecutionTestResult execTestResult)
132:                    throws ScriptExecutionException {
133:                String result = null;
134:                File file = null;
135:                String scriptFile = "";
136:
137:                try {
138:                    if (Api.isConnected()) {
139:                        try {
140:                            if (script.getTypeFromModel().equals(POST_SCRIPT)) {
141:                                //file = exec.getExecScriptFromDB(script.getNameFromModel(),POST_SCRIPT);
142:                                file = exec.getExecScriptFromDB(POST_SCRIPT);
143:                            } else if (script.getTypeFromModel().equals(
144:                                    PRE_SCRIPT)) {
145:                                //file = exec.getExecScriptFromDB(script.getNameFromModel(), PRE_SCRIPT);
146:                                file = exec.getExecScriptFromDB(PRE_SCRIPT);
147:                            } else if (script.getTypeFromModel().equals(
148:                                    INIT_SCRIPT)) {
149:                                //file = env.getEnvScriptFromDB(script.getNameFromModel());
150:                                file = env.getEnvScriptFromDB();
151:                            } else {
152:                                //file = test.getTestScriptFromDB(script.getNameFromModel());
153:                                file = test.getTestScriptFromDB();
154:                            }
155:                            //c = new CallScript(Tools.speedpurge(file.getAbsolutePath()));
156:                            scriptFile = Tools.speedpurge(file
157:                                    .getAbsolutePath());
158:                        } catch (Exception exception) {
159:                            Tools.ihmExceptionView(exception);
160:                        }
161:
162:                    } else {
163:                        //c = new CallScript(Tools.speedpurge(script.getName()));
164:                        scriptFile = Tools
165:                                .speedpurge(script.getNameFromModel());
166:                    }
167:                } catch (Exception e) {
168:                    if (Api.isDEBUG()) {
169:                        e.printStackTrace();
170:                    }
171:                    if (script.getTypeFromModel().equals(TEST_SCRIPT)) {
172:                        result = UNKNOWN;
173:                        fileCreationAndAttachToExecResult(execResult,
174:                                execTestResult, e.toString(), exec, Language
175:                                        .getInstance().getText("erreur_exec_")
176:                                        + test.getNameFromModel());
177:                    } else {
178:                        throw new ScriptExecutionException(e);
179:                    }
180:                    return result;
181:                }
182:
183:                // Hashtable pParams = new Hashtable(params);
184:                Hashtable pParams = getParamHashtable(params, exec, script
185:                        .getTypeFromModel());
186:                //if (script.getClassPath() != null) {
187:                //	obj.eval("addClassPath(\""+ Tools.speedpurge(script.getClassPath()) +"\")");
188:                //}
189:                pParams.put("date", new Date(GregorianCalendar.getInstance()
190:                        .getTimeInMillis()));
191:                pParams.put("time", new Time(GregorianCalendar.getInstance()
192:                        .getTimeInMillis()));
193:                //On ajoute une r?f?rence sur l'obejt de r?sultat de test
194:
195:                //obj.eval("setAccessibility(true)"); // turn off access restrictions
196:                pParams.put("salome_projectName", project.getNameFromModel());
197:                pParams.put("salome_ProjectObject", project);
198:                pParams.put("salome_debug", new Boolean(false));
199:                if (execResult != null) {
200:                    pParams.put("salome_ExecResultObject", execResult);
201:                }
202:                if (execTestResult != null) {
203:                    pParams.put("salome_ExecTestResultObject", execTestResult);
204:                }
205:                if (campaign != null) {
206:                    pParams.put("salome_CampagneName", campaign
207:                            .getNameFromModel());
208:                    pParams.put("salome_CampagneObject", campaign);
209:                } else {
210:                    pParams.put("salome_CampagneName", "");
211:                }
212:                if (env != null) {
213:                    pParams.put("salome_environmentName", env
214:                            .getNameFromModel()); // Add MM
215:                    pParams.put("salome_environmentObject", env); // Add MM
216:                } else {
217:                    pParams.put("salome_environmentName", ""); // Add MM
218:                }
219:                if (exec != null) {
220:                    pParams.put("salome_ExecName", exec.getNameFromModel()); // Add MM
221:                    pParams.put("salome_ExecObject", exec); // Add MM
222:                } else {
223:                    pParams.put("salome_ExecName", "");
224:                }
225:                if (test != null) {
226:                    pParams.put("salome_TestName", test.getNameFromModel());
227:                    pParams.put("salome_TestObject", test);
228:                    if (test.getTestListFromModel() != null) {
229:                        pParams.put("salome_SuiteTestName", test
230:                                .getTestListFromModel().getNameFromModel());
231:                        pParams.put("salome_SuiteTestObject", test
232:                                .getTestListFromModel());
233:                    } else {
234:                        pParams.put("salome_SuiteTestName", "");
235:                    }
236:                    if (test.getTestListFromModel().getFamilyFromModel() != null) {
237:                        pParams.put("salome_FamilyName", test
238:                                .getTestListFromModel().getFamilyFromModel()
239:                                .getNameFromModel());
240:                        pParams.put("salome_FamilyObject", test
241:                                .getTestListFromModel().getFamilyFromModel());
242:                    } else {
243:                        pParams.put("salome_FamilyName", "");
244:                    }
245:                } else {
246:                    pParams.put("salome_TestName", "");
247:                    pParams.put("salome_SuiteTestName", "");
248:                }
249:
250:                pParams.put("testLog", "");
251:                pParams.put("Verdict", "");
252:
253:                // valuation des parametres de tests
254:                if (params != null) {
255:                    Set keysSet = params.keySet();
256:                    for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
257:                        String paramName;
258:                        Object o = iter.next();
259:                        if (o instanceof  SimpleData) {
260:                            paramName = ((SimpleData) o).getNameFromModel();
261:                        } else {
262:                            paramName = (String) o;
263:                        }
264:                        Object val = params.get(o);
265:                        Object exitval = pParams.get(paramName);
266:
267:                        if (exitval == null) {
268:                            pParams.put(paramName, params.get(o));
269:                            Util.log("[callScript] "
270:                                    + Language.getInstance().getText(
271:                                            "valeur_de_") + paramName + " = "
272:                                    + val);
273:                        } else {
274:                            Util.log("[callScript] "
275:                                    + Language.getInstance().getText(
276:                                            "valeur_de_") + paramName + " = "
277:                                    + exitval);
278:                        }
279:
280:                    }
281:                }
282:
283:                // Lancement du script
284:                int plugScriptType = -1;
285:                //Script pScript = null;
286:                pEngine = null;
287:                driver = null;
288:                String plugArg = "";
289:                String log;
290:                int status = -3;
291:                try {
292:                    if (script.getTypeFromModel().equals(PRE_SCRIPT)) {
293:                        //script = exec.getInitScript();
294:                        pEngine = script
295:                                .getScriptEngine(
296:                                        (Extension) SalomeTMFContext
297:                                                .getInstance().associatedExtension
298:                                                .get(script
299:                                                        .getScriptExtensionFromModel()),
300:                                        SalomeTMFContext.getInstance()
301:                                                .getUrlBase(), SalomeTMFContext
302:                                                .getInstance()
303:                                                .getPluginManager());
304:                        plugScriptType = ScriptEngine.PRE_SCRIPT;
305:                        plugArg = script.getPlugArgFromModel();
306:                    } else if (script.getTypeFromModel().equals(POST_SCRIPT)) {
307:                        //script = exec.getPostScript();
308:                        pEngine = script
309:                                .getScriptEngine(
310:                                        (Extension) SalomeTMFContext
311:                                                .getInstance().associatedExtension
312:                                                .get(script
313:                                                        .getScriptExtensionFromModel()),
314:                                        SalomeTMFContext.getInstance()
315:                                                .getUrlBase(), SalomeTMFContext
316:                                                .getInstance()
317:                                                .getPluginManager());
318:                        plugScriptType = ScriptEngine.POST_SCRIPT;
319:                        plugArg = script.getPlugArgFromModel();
320:                    } else if (script.getTypeFromModel().equals(INIT_SCRIPT)) {
321:                        //script = exec.getPostScript();
322:                        pEngine = script
323:                                .getScriptEngine(
324:                                        (Extension) SalomeTMFContext
325:                                                .getInstance().associatedExtension
326:                                                .get(script
327:                                                        .getScriptExtensionFromModel()),
328:                                        SalomeTMFContext.getInstance()
329:                                                .getUrlBase(), SalomeTMFContext
330:                                                .getInstance()
331:                                                .getPluginManager());
332:                        plugScriptType = ScriptEngine.ENV_SCRIPT;
333:                        plugArg = script.getPlugArgFromModel();
334:                    } else {
335:                        driver = test
336:                                .ActivateExtention((Extension) SalomeTMFContext
337:                                        .getInstance().associatedExtension
338:                                        .get(test.getExtensionFromModel()),
339:                                        SalomeTMFContext.getInstance()
340:                                                .getUrlBase(), SalomeTMFContext
341:                                                .getInstance()
342:                                                .getPluginManager());
343:                        plugArg = test.getScriptFromModel()
344:                                .getPlugArgFromModel();
345:                    }
346:
347:                    if (driver != null) {
348:                        status = driver.runTest(scriptFile, test, pParams,
349:                                plugArg);
350:                        log = driver.getTestLog();
351:                        // Erreur; -1 : Inconclusif; 2 : Fail; 1 : Pass 0
352:                        if (status == -1) {
353:                            result = FAIL;
354:                            execResult.addFailInModel(1);
355:                            if (log == null) {
356:                                log = "unknow";
357:                            }
358:                            fileCreationAndAttachToExecResult(execResult,
359:                                    execTestResult, log, exec, Language
360:                                            .getInstance().getText(
361:                                                    "erreur_exec_")
362:                                            + test.getNameFromModel());
363:                        } else if (status == 0) {
364:                            result = SUCCESS;
365:                            execResult.addSuccessInModel(1);
366:                        }
367:                        if (status == 1) {
368:                            result = FAIL;
369:                            execResult.addFailInModel(1);
370:                        }
371:                        if (status == 2) {
372:                            result = UNKNOWN;
373:                            execResult.addUnknowInModel(1);
374:                        }
375:                        if (log != null && !log.equals("")) {
376:                            fileCreationAndAttachToExecResult(execResult,
377:                                    execTestResult, log, exec, "log_exec_"
378:                                            + test.getNameFromModel());
379:                        }
380:                    } else if (pEngine != null) {
381:                        try {
382:                            status = pEngine.runScript(plugScriptType,
383:                                    scriptFile, script, pParams, plugArg);
384:                        } catch (Exception e) {
385:                            e.printStackTrace();
386:                            status = -1;
387:                        }
388:                        //log = pEngine.
389:                        if (status != 0) {
390:                            throw new ScriptExecutionException(new Exception(
391:                                    pEngine.getScriptLog()));
392:                        }
393:
394:                    } else
395:                        throw new Exception("No plugin foud");
396:                } catch (Exception ePlug) {
397:                    if (Api.isDEBUG()) {
398:                        ePlug.printStackTrace();
399:                    }
400:                    log = ePlug.toString();
401:                    if (driver != null) {
402:                        if (status == -3) {
403:                            result = FAIL;
404:                            execResult.addFailInModel(1);
405:                        }
406:                        fileCreationAndAttachToExecResult(execResult,
407:                                execTestResult, log, exec, Language
408:                                        .getInstance().getText("erreur_exec_")
409:                                        + test.getNameFromModel());
410:                    } else {
411:                        if (status == -3) {
412:                            result = UNKNOWN;
413:                            execResult.addUnknowInModel(1);
414:                        }
415:                        throw new ScriptExecutionException(ePlug);
416:                    }
417:                }
418:                Util.log("[callScript] stop");
419:                //if (file != null) file.delete();
420:
421:                return result;
422:            }
423:
424:            public static void fileCreationAndAttachToExecResult(
425:                    ExecutionResult execResult,
426:                    ExecutionTestResult execTestResult, String text,
427:                    Execution exec, String fileName) {
428:
429:                Properties sys = System.getProperties();
430:                String tempDir = sys.getProperty("java.io.tmpdir");
431:                String fs = sys.getProperty("file.separator");
432:                tempDir = tempDir + fs + ApiConstants.PATH_TO_ADD_TO_TEMP;
433:                int num = 0;
434:                String pFileName = tempDir + fs + fileName + ".txt";
435:                File errorFile = new File(pFileName);
436:                while (errorFile.exists()) {
437:                    pFileName = tempDir + fs + fileName + num + ".txt";
438:                    errorFile = new File(pFileName);
439:                    num++;
440:                    //errorFile.delete();
441:                }
442:                try {
443:                    errorFile.createNewFile();
444:
445:                    //BufferedWriter a besoin d un FileWriter,
446:                    //les 2 vont ensemble, on donne comme argument le nom du fichier
447:                    //true signifie qu on ajoute dans le fichier (append), on ne marque pas par dessus
448:                    FileWriter fw = new FileWriter(pFileName, true);
449:
450:                    // le BufferedWriter output auquel on donne comme argument le FileWriter fw cree juste au dessus
451:                    BufferedWriter output = new BufferedWriter(fw);
452:
453:                    //on marque dans le fichier ou plutot dans le BufferedWriter qui sert comme un tampon(stream)
454:                    output.write(text);
455:                    //on peut utiliser plusieurs fois methode write
456:
457:                    output.flush();
458:                    //ensuite flush envoie dans le fichier, ne pas oublier cette methode pour le BufferedWriter
459:
460:                    output.close();
461:                    //et on le ferme
462:
463:                } catch (IOException ioe) {
464:                    if (Api.isDEBUG()) {
465:                        ioe.printStackTrace();
466:                    }
467:                    Util.log(Language.getInstance().getText(
468:                            "erreur_lors_de_la_création_du_fichier_d'erreur:_")
469:                            + ioe);
470:                    //on "catch" l exception ici si il y en a une, et on l affiche sur la console
471:                    return;
472:                }
473:
474:                if (execTestResult == null && execResult != null) {
475:                    execResult.addAttchmentInModel(errorFile);
476:                    //execResult.setAttachmentMap(attachMap);
477:                } else if (execTestResult != null) {
478:                    //execTestResult.setAttachmentMap(attachMap);
479:                    execTestResult.addAttchmentInModel(errorFile);
480:                }
481:
482:            }
483:
484:            /**
485:             * @return
486:             */
487:            public static void annulScript() {
488:                try {
489:                    if (driver != null) {
490:                        driver.stopTest();
491:                    } else if (pEngine != null) {
492:                        pEngine.stopScript();
493:                    }
494:                } catch (Exception e) {
495:                    if (Api.isDEBUG()) {
496:                        e.printStackTrace();
497:                    }
498:                    e.printStackTrace();
499:                }
500:            }
501:
502:            /**
503:             * Reprise d'une exécution
504:             * @param exec
505:             * @param finalExecResult
506:             * @param pComponent
507:             * @param stopOnError
508:             */
509:            public static void continueExecution(Execution exec,
510:                    ExecutionResult finalExecResult, Component pComponent,
511:                    boolean stopOnError, boolean onlyNotExec,
512:                    boolean onlyAssigned, boolean forModif) {
513:                //Campaign pCamp = DataModel.getCurrentCampaign();
514:                Campaign pCamp = exec.getCampagneFromModel();
515:                if (finalExecResult.getTestsResultMapFromModel().size() != pCamp
516:                        .getTestListFromModel().size()) {
517:                    SalomeTMFContext.getInstance().showMessage(
518:                            Language.getInstance().getText("Update_data"),
519:                            Language.getInstance().getText("Erreur_!"),
520:                            JOptionPane.ERROR_MESSAGE);
521:                    return;
522:                }
523:                finalExecResult.setExecutionDateInModel(new Date(
524:                        GregorianCalendar.getInstance().getTimeInMillis()));
525:                finalExecResult.setTesterInModel(DataModel.currentUser
526:                        .getLastNameFromModel()
527:                        + " " + DataModel.currentUser.getFirstNameFromModel());
528:
529:                Vector pAllTestToExecute = new Vector();
530:                //Liste des tests groupés en sous-listes (manuels/automatiques)
531:                ArrayList splittedListOfTest = Tools
532:                        .getListOfTestManualOrAutomatic(pCamp
533:                                .getTestListFromModel(), finalExecResult,
534:                                pAllTestToExecute, true, onlyNotExec,
535:                                onlyAssigned, forModif);
536:                Vector listExec = new Vector();
537:                // On parcourt la liste des sous-listes
538:                try {
539:                    for (int h = 0; h < splittedListOfTest.size(); h++) {
540:                        if (((ArrayList) splittedListOfTest.get(h)).get(0) instanceof  ManualTest) {
541:                            listExec.add(new ManualExecution(
542:                                    (ArrayList) splittedListOfTest.get(h),
543:                                    exec, finalExecResult, true));
544:
545:                        } else {
546:                            //Sous liste de tests automatiques
547:                            ArrayList automaticTestList = (ArrayList) splittedListOfTest
548:                                    .get(h);
549:                            listExec.add(new AutomaticExecution(
550:                                    automaticTestList, exec, finalExecResult));
551:                        }
552:                    }
553:                } catch (Exception e) {
554:                    e.printStackTrace();
555:                    SalomeTMFContext.getInstance().showMessage(
556:                            Language.getInstance().getText("Update_data"),
557:                            Language.getInstance().getText("Erreur_!"),
558:                            JOptionPane.ERROR_MESSAGE);
559:                    return;
560:                }
561:                //new callExecThread(listExec, exec, splittedListOfTest, selectedRowIndex, attachToBeSuppress, false, finalExecResult, null, pAllTestToExecute.toArray()).start();
562:                if (listExec.size() > 0) {
563:                    new CallExecThread(listExec, exec, splittedListOfTest,
564:                            false, finalExecResult, null, pAllTestToExecute
565:                                    .toArray(), pComponent, stopOnError, false)
566:                            .start();
567:                } else {
568:                    SalomeTMFContext.getInstance().showMessage(
569:                            Language.getInstance()
570:                                    .getText("aucun_test_assigne"),
571:                            Language.getInstance().getText("Attention_!"),
572:                            JOptionPane.WARNING_MESSAGE);
573:                    return;
574:                }
575:            }
576:
577:            /**
578:             * Lancement des exécutions  
579:             * @param pListExec
580:             * @param pComponent
581:             * @param stopOnError
582:             */
583:            public static void runExecution(ArrayList pListExec,
584:                    Component pComponent, boolean stopOnError,
585:                    boolean onlyAssigned) {
586:                //Campaign pCapaign = exec.getCampagne();
587:                Execution pExec;
588:                Campaign pCapaign;
589:                // il doit y avoir au moins une exécution sélectionnée
590:                int nbExec = pListExec.size();
591:                if (nbExec > 0) {
592:                    String message = "";
593:                    for (int i = 0; i < nbExec; i++) { // FOR 1
594:                        HashSet setOfParam = new HashSet();
595:                        pExec = (Execution) pListExec.get(i);
596:                        pCapaign = pExec.getCampagneFromModel();
597:                        // Récupération de tous les paramétres de la campagne
598:                        for (int k = 0; k < pCapaign.getTestListFromModel()
599:                                .size(); k++) {
600:                            Test test = (Test) pCapaign.getTestListFromModel()
601:                                    .get(k);
602:                            for (int j = 0; j < test
603:                                    .getParameterListFromModel().size(); j++) {
604:                                setOfParam.add(test.getParameterListFromModel()
605:                                        .get(j));
606:                            }
607:                        }
608:                        // On vérifie que tous les paramètres ont une valuation;
609:                        ArrayList notValuedParamList = new ArrayList();
610:                        message = TestMethods.notValuedParamListInDataSet(
611:                                setOfParam, pExec.getDataSetFromModel(),
612:                                notValuedParamList);
613:                        if (notValuedParamList.size() > 0) {
614:                            message = Language.getInstance().getText(
615:                                    "Les_paramètres_:\n")
616:                                    + message
617:                                    + Language.getInstance().getText(
618:                                            "de_l'exécution_<")
619:                                    + pExec.getNameFromModel()
620:                                    + Language.getInstance().getText(
621:                                            ">_ne_sont_pas_valués.");
622:                        }
623:                    }
624:
625:                    if (!message.equals("") && pComponent != null) {
626:                        SalomeTMFContext.getInstance().showMessage(
627:                                Language.getInstance().getText("Attention_!\n")
628:                                        + message,
629:                                Language.getInstance().getText("Attention_!"),
630:                                JOptionPane.INFORMATION_MESSAGE);
631:                        /*JOptionPane.showMessageDialog(pComponent,
632:                        		Language.getInstance().getText("Attention_!\n") + message,
633:                        		Language.getInstance().getText("Attention_!"),
634:                        		JOptionPane.INFORMATION_MESSAGE);
635:                         */
636:                    }
637:
638:                    CallExecThread precCallExecThread = null;
639:                    String listres = "";
640:                    // on parcourt la liste des exécutions selectionnées
641:                    for (int i = nbExec - 1; i >= 0; i--) { // FOR 1
642:                        // Execution courante
643:                        pExec = (Execution) pListExec.get(i);
644:                        pCapaign = pExec.getCampagneFromModel();
645:                        Util.log(">>>>EXEC LANCEE = "
646:                                + pExec.getNameFromModel());
647:                        // R?sultat d'ex?cution final
648:                        String prefix = "";
649:                        if (onlyAssigned) {
650:                            prefix = "user-";
651:                        }
652:
653:                        ExecutionResult finalExecResult = new ExecutionResult(
654:                                prefix
655:                                        + pExec.getNameFromModel()
656:                                        + "_"
657:                                        + pExec
658:                                                .getExecutionResultListFromModel()
659:                                                .size(), "", pExec);
660:                        listres += finalExecResult.getNameFromModel() + ", ";
661:                        finalExecResult.setNumberOfFailInModel(0);
662:                        finalExecResult.setNumberOfSuccessInModel(0);
663:                        finalExecResult.setNumberOfUnknowInModel(0);
664:                        finalExecResult.setExecutionDateInModel(new Date(
665:                                GregorianCalendar.getInstance()
666:                                        .getTimeInMillis()));
667:                        finalExecResult
668:                                .setTesterInModel(DataModel.currentUser
669:                                        .getLastNameFromModel()
670:                                        + " "
671:                                        + DataModel.currentUser
672:                                                .getFirstNameFromModel());
673:
674:                        Tools.initExecutionResultMap(pCapaign
675:                                .getTestListFromModel(), finalExecResult,
676:                                pCapaign);
677:                        boolean continueExec = false;
678:                        boolean noError = true;
679:                        if (onlyAssigned) {
680:                            //create execResultINDB and continue execution
681:                            finalExecResult
682:                                    .setExecutionStatusInModel(INCOMPLETED);
683:                            int transNumber = -1;
684:                            try {
685:                                transNumber = Api.beginTransaction(110,
686:                                        ApiConstants.INSERT_EXECUTION_RESULT);
687:                                pExec.addExecutionResultInDB(finalExecResult,
688:                                        DataModel.currentUser);
689:                                ArrayList list = pCapaign
690:                                        .getTestListFromModel();
691:                                for (int j = 0; j < list.size(); j++) {
692:                                    Test pTest = (Test) list.get(j);
693:                                    finalExecResult
694:                                            .addExecTestResultInDB(pTest);
695:                                    if (pTest instanceof  ManualTest) {
696:                                        ArrayList actionList = ((ManualTest) pTest)
697:                                                .getActionListFromModel(false);
698:                                        for (int k = 0; k < actionList.size(); k++) {
699:                                            Action act = (Action) actionList
700:                                                    .get(k);
701:                                            finalExecResult
702:                                                    .addExecActionResultInDB(
703:                                                            pTest, act);
704:                                        }
705:                                    }
706:                                }
707:                                Api.commitTrans(transNumber);
708:                                continueExec = true;
709:                            } catch (Exception e) {
710:                                noError = false;
711:                                e.printStackTrace();
712:                                Api.forceRollBackTrans(transNumber);
713:                            }
714:                        }
715:                        if (noError) {
716:                            Vector pAllTestToExecute = new Vector();
717:                            ArrayList splittedListOfTest;
718:                            if (onlyAssigned) {
719:                                splittedListOfTest = Tools
720:                                        .getListOfTestManualOrAutomatic(
721:                                                pCapaign.getTestListFromModel(),
722:                                                finalExecResult,
723:                                                pAllTestToExecute,
724:                                                continueExec, false,
725:                                                onlyAssigned, false);
726:                            } else {
727:                                splittedListOfTest = Tools
728:                                        .getListOfTestManualOrAutomatic(
729:                                                pCapaign.getTestListFromModel(),
730:                                                null, pAllTestToExecute,
731:                                                continueExec, false,
732:                                                onlyAssigned, false);
733:                            }
734:                            Vector listExec = new Vector();
735:                            // On parcourt la liste des sous-listes
736:                            for (int h = 0; h < splittedListOfTest.size(); h++) {
737:                                if (((ArrayList) splittedListOfTest.get(h))
738:                                        .get(0) instanceof  ManualTest) {
739:                                    // Sous liste de tests manuels
740:                                    listExec.add(new ManualExecution(
741:                                            (ArrayList) splittedListOfTest
742:                                                    .get(h), pExec,
743:                                            finalExecResult, false));
744:
745:                                } else {
746:                                    //Sous liste de tests automatiques
747:                                    ArrayList automaticTestList = (ArrayList) splittedListOfTest
748:                                            .get(h);
749:                                    listExec.add(new AutomaticExecution(
750:                                            automaticTestList, pExec,
751:                                            finalExecResult));
752:                                }
753:                            }
754:
755:                            precCallExecThread = new CallExecThread(listExec,
756:                                    pExec, splittedListOfTest, true,
757:                                    finalExecResult, precCallExecThread,
758:                                    pAllTestToExecute.toArray(), pComponent,
759:                                    stopOnError, onlyAssigned);
760:                        }
761:
762:                        //} // FIN FOR 1 ?
763:                        if (onlyAssigned) {
764:                            SalomeTMFContext.getInstance().showMessage(
765:                                    Language.getInstance().getText(
766:                                            "Messages_para_exec1")
767:                                            + "\n"
768:                                            + listres
769:                                            + "\n"
770:                                            + Language.getInstance().getText(
771:                                                    "Messages_para_exec2"),
772:                                    Language.getInstance().getText(
773:                                            "Attention_!"),
774:                                    JOptionPane.INFORMATION_MESSAGE);
775:                            //Update IHM
776:                            ((ExecutionView) pComponent).updateIHMTable(true,
777:                                    pExec, finalExecResult);
778:                            pExec.addExecutionResultInModel(finalExecResult);
779:                        } else {
780:                            precCallExecThread.start();
781:                        }
782:                    } // FIN FOR 1
783:                } else {
784:                    if (pComponent != null) {
785:                        SalomeTMFContext
786:                                .getInstance()
787:                                .showMessage(
788:                                        Language
789:                                                .getInstance()
790:                                                .getText(
791:                                                        "Vous_devez_sélectionner_au_moins_une_exécution..."),
792:                                        Language.getInstance().getText(
793:                                                "Attention_!"),
794:                                        JOptionPane.WARNING_MESSAGE);
795:                        /*JOptionPane.showMessageDialog(pComponent,
796:                        		Language.getInstance().getText("Vous_devez_sélectionner_au_moins_une_exécution..."),
797:                        		Language.getInstance().getText("Attention_!"),
798:                        		JOptionPane.WARNING_MESSAGE);*/
799:                    }
800:                }
801:            }
802:
803:            static Hashtable getParamHashtable(HashMap map, Execution ptrExec,
804:                    String type) {
805:                if (type.equals(INIT_SCRIPT)) {
806:                    return new Hashtable(map);
807:                }
808:                Environment ptrEnv = ptrExec.getEnvironmentFromModel();
809:                DataSet dataSet = ptrExec.getDataSetFromModel();
810:                Hashtable valuedParam = new Hashtable();
811:                if (dataSet != null) {
812:                    Set dataSetKeysSet = dataSet
813:                            .getParametersHashMapFromModel().keySet();
814:                    for (Iterator iter = dataSetKeysSet.iterator(); iter
815:                            .hasNext();) {
816:                        String paramName = (String) iter.next();
817:                        Parameter element = DataModel.getCurrentProject()
818:                                .getParameterFromModel(paramName);
819:                        String value = dataSet
820:                                .getParameterValueFromModel(element
821:                                        .getNameFromModel());
822:                        if (value
823:                                .startsWith(DataConstants.PARAM_VALUE_FROM_ENV)) {
824:                            value = ptrEnv.getParameterValue(paramName);
825:                            if (value == null) {
826:                                value = "";
827:                            }
828:                        }
829:                        valuedParam.put(paramName, value);
830:                    }
831:                }
832:                return valuedParam;
833:            }
834:        } // Fin de la classe TestMethods
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.