Source Code Cross Referenced for SimpleJunitPlugin.java in  » Test-Coverage » salome-tmf » salomeTMF_plug » simpleJunit » 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 » salomeTMF_plug.simpleJunit 
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 salomeTMF_plug.simpleJunit;
025:
026:        import java.awt.event.ActionEvent;
027:        import java.awt.event.ActionListener;
028:        import java.io.BufferedOutputStream;
029:        import java.io.File;
030:        import java.io.FileInputStream;
031:        import java.io.FileOutputStream;
032:        import java.net.URL;
033:        import java.util.Enumeration;
034:        import java.util.Hashtable;
035:        import java.util.Properties;
036:        import java.util.Vector;
037:
038:        import javax.swing.JMenu;
039:        import javax.swing.JMenuItem;
040:        import javax.swing.tree.DefaultMutableTreeNode;
041:
042:        import org.java.plugin.ExtensionPoint;
043:        import org.java.plugin.Plugin;
044:        import org.java.plugin.PluginDescriptor;
045:        import org.java.plugin.PluginManager;
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.data.Attachment;
050:        import org.objectweb.salome_tmf.data.AutomaticTest;
051:        import org.objectweb.salome_tmf.data.Family;
052:        import org.objectweb.salome_tmf.data.Project;
053:        import org.objectweb.salome_tmf.data.Script;
054:        import org.objectweb.salome_tmf.data.SimpleData;
055:        import org.objectweb.salome_tmf.data.Test;
056:        import org.objectweb.salome_tmf.data.TestList;
057:        import org.objectweb.salome_tmf.ihm.main.SalomeTMFPanels;
058:        import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
059:        import org.objectweb.salome_tmf.ihm.tools.Tools;
060:        import org.objectweb.salome_tmf.plugins.IPlugObject;
061:        import org.objectweb.salome_tmf.plugins.core.Common;
062:        import org.objectweb.salome_tmf.plugins.core.ReqManager;
063:        import org.objectweb.salome_tmf.plugins.core.TestDriver;
064:
065:        import salomeTMF_plug.simpleJunit.languages.Language;
066:
067:        /**
068:         *
069:         * @author  marchemi
070:         */
071:        public class SimpleJunitPlugin extends Plugin implements  TestDriver,
072:                Common {
073:
074:            String url_txt = null;
075:
076:            String id_plugin;
077:
078:            String MSG_ERR_EDIT = Language.getInstance().getText(
079:                    "Erreur_lors_de_l'ouverture_du_fichier_jUnit_de_tests");
080:            String MSG_ERR_WRITE = Language.getInstance().getText(
081:                    "Erreur_lors_de_l'ecriture_du_fichier_de_tests_jUnit");
082:            String MSG_ERR_CREATE = Language.getInstance().getText(
083:                    "Erreur_lors_de_la_recherche_des_methodes_de_tests");
084:
085:            /**** CLASS UTIL ****/
086:            IJunitAnalyser currentJunitAnalyser;
087:
088:            private IPlugObject pIPlugObject;
089:
090:            /** Creates a new instance of SimpleJunitPlugin */
091:            public SimpleJunitPlugin(PluginManager manager,
092:                    PluginDescriptor descr) {
093:                super (manager, descr);
094:                id_plugin = descr.getId() + ".TestDriver";
095:            }
096:
097:            /********************* extends Plugin**********************************/
098:
099:            /**
100:             * @see org.java.plugin.Plugin()
101:             */
102:            protected void doStart() throws Exception {
103:                Util.log("[SimpleJunitPlugin:doStart] chargement du plugin");
104:            }
105:
106:            /**
107:             * @see org.java.plugin.Plugin()
108:             */
109:            protected void doStop() throws Exception {
110:                // no-op
111:            }
112:
113:            /*********************** Interface TestDriver ****************************/
114:
115:            /**
116:             * @see salome.plugins.core.TestDriver
117:             */
118:            public void initTestDriver(URL urlSalome) {
119:                String _urlSalome = urlSalome.toString();
120:                url_txt = _urlSalome.substring(0, _urlSalome.lastIndexOf("/"));
121:            }
122:
123:            /**
124:             * @see salome.plugins.core.TestDriver
125:             */
126:            public void getHelp() {
127:                Util.log("Junit TestDriver");
128:            }
129:
130:            /**
131:             * @see salome.plugins.core.TestDriverpTestResult
132:             */
133:            public String getDefaultTestDiverAgument() {
134:                return "";
135:            }
136:
137:            /**
138:             * @see salome.plugins.core.TestDriver
139:             */
140:            public String modifyTestDiverAgument(String oldArg) {
141:                return "";
142:            }
143:
144:            /**
145:             * @see salome.plugins.core.TestDriver
146:             */
147:            public int runTest(String testScript,
148:                    org.objectweb.salome_tmf.data.AutomaticTest pTest,
149:                    Hashtable argTest, String plugArg) throws Exception {
150:                File pFile = new File(testScript);
151:                FileInputStream pFileInputStream = new FileInputStream(pFile);
152:                Properties test_prop = new Properties();
153:                test_prop.load(pFileInputStream);
154:                String strID = test_prop.getProperty("attachment_id");
155:                String strAttachment = test_prop.getProperty("attachment_name");
156:                String strClass = test_prop.getProperty("junit_class");
157:                String meth = test_prop.getProperty("test_meth");
158:                String version = test_prop.getProperty("junit_version");
159:                pFileInputStream.close();
160:                Util
161:                        .log("[SimpleJunitPlugin:runTest] attachment_id = "
162:                                + strID);
163:                Util.log("[SimpleJunitPlugin:runTest] attachment_name = "
164:                        + strAttachment);
165:                Util.log("[SimpleJunitPlugin:runTest] junit_class = "
166:                        + strClass);
167:                Util.log("[SimpleJunitPlugin:runTest] test_meth = " + meth);
168:                Util.log("[SimpleJunitPlugin:runTest] junit_version = "
169:                        + version);
170:                if (version != null) {
171:                    version = version.trim();
172:                    if (version.equals("4.x")) {
173:                        if (!(currentJunitAnalyser instanceof  Junit4ClassAnalyser)) {
174:                            currentJunitAnalyser = new Junit4ClassAnalyser(this );
175:                        }
176:                    } else {
177:                        //3.x
178:                        if (!(currentJunitAnalyser instanceof  Junit3ClassAnalyser)) {
179:                            currentJunitAnalyser = new Junit3ClassAnalyser(this );
180:                        }
181:                    }
182:                } else {
183:                    if (!(currentJunitAnalyser instanceof  Junit3ClassAnalyser)) {
184:                        currentJunitAnalyser = new Junit3ClassAnalyser(this );
185:                    }
186:                }
187:                return currentJunitAnalyser.runTest(strID, strAttachment,
188:                        strClass, meth, testScript, pTest, argTest, plugArg);
189:            }
190:
191:            /**
192:             * @see salome.plugins.core.TestDriver
193:             */
194:            public String getTestLog() {
195:                if (currentJunitAnalyser != null) {
196:                    return currentJunitAnalyser.getTestLog();
197:                }
198:                return "";
199:            }
200:
201:            /**
202:             * @see salome.plugins.core.TestDriver
203:             */
204:            public void stopTest() throws Exception {
205:                if (currentJunitAnalyser != null) {
206:                    currentJunitAnalyser.stopTest();
207:                }
208:
209:            }
210:
211:            /**
212:             * Odre d'édition du test
213:             */
214:            public void editTest(String testScript,
215:                    org.objectweb.salome_tmf.data.AutomaticTest pTest,
216:                    Hashtable arg, String plugParam) throws Exception {
217:                try {
218:                    File pFile = new File(testScript);
219:                    FileInputStream pFileInputStream = new FileInputStream(
220:                            pFile);
221:                    Properties test_prop = new Properties();
222:                    test_prop.load(pFileInputStream);
223:                    //Utile.getPropertiesFile(testScript);
224:                    String strID = test_prop.getProperty("attachment_id");
225:                    String strAttachment = test_prop
226:                            .getProperty("attachment_name");
227:                    String strClass = test_prop.getProperty("junit_class");
228:                    String meth = test_prop.getProperty("test_meth");
229:                    String version = test_prop.getProperty("junit_version");
230:                    pFileInputStream.close();
231:
232:                    File script = ChoiceOrEdit(pTest, false, pFile, strID,
233:                            strAttachment, strClass, meth, version);
234:                    if (script != null) {
235:                        Script pScript = pTest.getScriptFromModel();
236:                        pScript.updateInDB(script);
237:                    }
238:
239:                } catch (Exception e) {
240:                    e.printStackTrace();
241:                    Tools.ihmExceptionView(e);
242:                }
243:            }
244:
245:            public void updateTestScriptFromImport(String testScript,
246:                    org.objectweb.salome_tmf.data.AutomaticTest pTest) {
247:                updateTestScript(testScript, pTest);
248:            }
249:
250:            public String updateTestScript(String testScript,
251:                    org.objectweb.salome_tmf.data.AutomaticTest pTest) {
252:                String strNewId = "";
253:                try {
254:
255:                    File pFile = new File(testScript);
256:                    FileInputStream pFileInputStream = new FileInputStream(
257:                            pFile);
258:                    Properties test_prop = new Properties();
259:                    test_prop.load(pFileInputStream);
260:                    //Utile.getPropertiesFile(testScript);
261:                    String strID = test_prop.getProperty("attachment_id");
262:                    String strAttachment = test_prop
263:                            .getProperty("attachment_name");
264:                    String strClass = test_prop.getProperty("junit_class");
265:                    String meth = test_prop.getProperty("test_meth");
266:                    String version = test_prop.getProperty("junit_version");
267:                    pFileInputStream.close();
268:
269:                    Hashtable tabAttach = new Hashtable(DataModel
270:                            .getCurrentProject().getAttachmentMapFromModel());
271:                    Enumeration e = tabAttach.elements();
272:                    boolean trouve = false;
273:                    while (e.hasMoreElements() && !trouve) {
274:                        Attachment pAttach = (Attachment) e.nextElement();
275:                        if (pAttach.getDescriptionFromModel().equals(
276:                                JunitTester.junitDescAttach)
277:                                && pAttach.getNameFromModel().equals(
278:                                        strAttachment)) {
279:                            strNewId = "" + pAttach.getIdBdd();
280:                            trouve = true;
281:                        }
282:                    }
283:                    //ADD PROJECT PATH
284:
285:                    String toWrite = "attachment_id = " + strNewId + "\n";
286:                    toWrite += "attachment_name = " + strAttachment + "\n";
287:                    toWrite += "junit_class = " + strClass + "\n";
288:                    toWrite += "test_meth = " + meth + "\n";
289:                    toWrite += "junit_version = " + version + "\n";
290:                    File newFile = writeJunitFile(pFile, pTest, toWrite);
291:                    Script pScript = pTest.getScriptFromModel();
292:                    pScript.updateInDB(newFile);
293:
294:                } catch (Exception e) {
295:
296:                }
297:                return strNewId;
298:            }
299:
300:            /**
301:             * Choix d'un test
302:             * @return le test choisi
303:             */
304:            public java.io.File choiceTest(
305:                    org.objectweb.salome_tmf.data.AutomaticTest pTest) {
306:                return ChoiceOrEdit(pTest, true, null, "", "", "", "", "");
307:            }
308:
309:            public void onDeleteTestScript(
310:                    org.objectweb.salome_tmf.data.AutomaticTest pTest) {
311:
312:            }
313:
314:            java.io.File ChoiceOrEdit(AutomaticTest pTest, boolean choice,
315:                    File pFile, String strID, String strAttachment,
316:                    String strClass, String meth, String version) {
317:                JunitTester pJunitTester = new JunitTester(null, true, pTest,
318:                        choice, strID, strAttachment, strClass, meth, version);
319:                if (pJunitTester.execute()) {
320:                    Util.log("[SimpleJunitPlugin:editTest] ok pressed");
321:                    Attachment pNewattach = pJunitTester.getNewAttachment();
322:                    Attachment pSelectedattach = pJunitTester
323:                            .getSelectedAttachment();
324:                    String toWrite = "attachment_id = ";
325:                    if (pSelectedattach != null) {
326:                        if (pSelectedattach.equals(pNewattach)) {
327:                            if (!addAttachmentToProject(pNewattach, DataModel
328:                                    .getCurrentProject()))
329:                                return null;
330:                        }
331:                        toWrite += pSelectedattach.getIdBdd() + "\n";
332:                        toWrite += "attachment_name = "
333:                                + pSelectedattach.getNameFromModel() + "\n";
334:                    } else {
335:                        toWrite += "\nattachment_name = \n";
336:                    }
337:                    toWrite += "junit_class = " + pJunitTester.getJunitClass()
338:                            + "\n";
339:                    toWrite += "test_meth = " + pJunitTester.getJunitMeth()
340:                            + "\n";
341:                    version = pJunitTester.getJunitVersion();
342:                    if (version != null) {
343:                        toWrite += "junit_version = " + version + "\n";
344:                        version = version.trim();
345:                        if (version.equals("4.x")) {
346:                            if (!(currentJunitAnalyser instanceof  Junit4ClassAnalyser)) {
347:                                currentJunitAnalyser = new Junit4ClassAnalyser(
348:                                        this );
349:                            }
350:                        } else {
351:                            //3.x
352:                            if (!(currentJunitAnalyser instanceof  Junit3ClassAnalyser)) {
353:                                currentJunitAnalyser = new Junit3ClassAnalyser(
354:                                        this );
355:                            }
356:                        }
357:                    }
358:                    try {
359:                        File f = writeJunitFile(pFile, pTest, toWrite);
360:                        return f;
361:                    } catch (Exception e) {
362:                        Tools.ihmExceptionView(e);
363:                        e.printStackTrace();
364:                        return null;
365:                    }
366:                } else {
367:                    Util.log("[SimpleJunitPlugin:editTest] cancel pressed");
368:                    return null;
369:                }
370:            }
371:
372:            File writeJunitFile(File pFile,
373:                    org.objectweb.salome_tmf.data.AutomaticTest pTest,
374:                    String toWtrite) throws Exception {
375:                String fileName;
376:                if (pFile == null) {
377:                    Properties sys = System.getProperties();
378:                    String tmpDir = sys.getProperty("java.io.tmpdir");
379:                    String fs = sys.getProperty("file.separator");
380:                    fileName = tmpDir + fs + pTest.getNameFromModel()
381:                            + ".junit";
382:                    pFile = new File(fileName);
383:                } else {
384:                    fileName = pFile.getAbsolutePath();
385:                    pFile.delete();
386:                    pFile.createNewFile();
387:                }
388:                Util.log("[SimpleJunitPlugin:writeJunitFile] write " + toWtrite
389:                        + ", in " + fileName);
390:                FileOutputStream fos = new FileOutputStream(pFile);
391:                BufferedOutputStream bos = new BufferedOutputStream(fos);
392:                byte[] b = toWtrite.getBytes();
393:                bos.write(b, 0, b.length);
394:                bos.flush();
395:                bos.close();
396:                //return null;
397:                return pFile;
398:            }
399:
400:            boolean addAttachmentToProject(Attachment pAttach, Project pProject) {
401:                if (Api.isConnected()) {
402:                    try {
403:                        pProject.addAttachementInDBAndModel(pAttach);
404:                        Util
405:                                .log("[SimpleJunitPlugin:addAttachmentToSuite] add attach in DB & model : "
406:                                        + pAttach);
407:
408:                    } catch (Exception exception) {
409:                        Tools.ihmExceptionView(exception);
410:                        return false;
411:                    }
412:                }
413:
414:                return true;
415:            }
416:
417:            void createJunitSuitePerformed() {
418:                Project pProject = DataModel.getCurrentProject();
419:                TestList pTestList = null;
420:                Family pFamily = null;
421:                Test pTest = null;
422:                DefaultMutableTreeNode pNode = SalomeTMFPanels
423:                        .getTestDynamicTree().getSelectedNode();
424:                if (pNode == null) {
425:                    return;
426:                } else {
427:                    SimpleData pData = (SimpleData) pNode.getUserObject();
428:                    if (pData instanceof  Family) {
429:                        pFamily = (Family) pData;
430:                    } else if (pData instanceof  TestList) {
431:                        pTestList = (TestList) pData;
432:                    } else if (pData instanceof  Test) {
433:                        pTest = (Test) pData;
434:                    }
435:                }
436:
437:                if (pTestList != null) {
438:                    Util.log("Test List selected = "
439:                            + pTestList.getNameFromModel());
440:                    JunitTester pJunitTester = new JunitTester(null, true,
441:                            pProject, true, "", "", "", "");
442:                    if (pJunitTester.execute()) {
443:                        Util.log("[SimpleJunitPlugin:editTest] ok pressed");
444:                        Attachment pNewattach = pJunitTester.getNewAttachment();
445:                        Attachment pSelectedattach = pJunitTester
446:                                .getSelectedAttachment();
447:                        String toWrite = "attachment_id = ";
448:                        if (pSelectedattach != null) {
449:                            if (pSelectedattach.equals(pNewattach)) {
450:                                if (!addAttachmentToProject(pNewattach,
451:                                        DataModel.getCurrentProject()))
452:                                    return;
453:                            }
454:                            toWrite += pSelectedattach.getIdBdd() + "\n";
455:                            toWrite += "attachment_name = "
456:                                    + pSelectedattach.getNameFromModel() + "\n";
457:                        } else {
458:                            toWrite += "\nattachment_name = \n";
459:                        }
460:                        toWrite += "junit_class = "
461:                                + pJunitTester.getJunitClass() + "\n";
462:                        String version = pJunitTester.getJunitVersion();
463:                        if (version != null) {
464:                            toWrite += "junit_version = " + version + "\n";
465:                            version = version.trim();
466:                            if (version.equals("4.x")) {
467:                                if (!(currentJunitAnalyser instanceof  Junit4ClassAnalyser)) {
468:                                    currentJunitAnalyser = new Junit4ClassAnalyser(
469:                                            this );
470:                                }
471:                            } else {
472:                                //3.x
473:                                if (!(currentJunitAnalyser instanceof  Junit3ClassAnalyser)) {
474:                                    currentJunitAnalyser = new Junit3ClassAnalyser(
475:                                            this );
476:                                }
477:                            }
478:                        }
479:                        try {
480:                            if (!pTestList.isInBase()) {
481:                                pTestList.updateInModel(pJunitTester
482:                                        .getJunitClass(), "JUNIT " + version
483:                                        + " TEST SUITE");
484:                                pFamily.addTestListInDB(pTestList);
485:                            }
486:                            currentJunitAnalyser.createJunitTest(
487:                                    pSelectedattach, pJunitTester
488:                                            .getJunitClass(), pTestList,
489:                                    toWrite);
490:                        } catch (Exception e1) {
491:                            Tools.ihmExceptionView(e1);
492:                        }
493:
494:                    }
495:                }
496:            }
497:
498:            void createBeanshellJunitSuitePerformed() {
499:                Project pProject = DataModel.getCurrentProject();
500:                TestList pTestList = null;
501:                Family pFamily = null;
502:                Test pTest = null;
503:                DefaultMutableTreeNode pNode = SalomeTMFPanels
504:                        .getTestDynamicTree().getSelectedNode();
505:                if (pNode == null) {
506:                    return;
507:                } else {
508:                    SimpleData pData = (SimpleData) pNode.getUserObject();
509:                    if (pData instanceof  Family) {
510:                        pFamily = (Family) pData;
511:                    } else if (pData instanceof  TestList) {
512:                        pTestList = (TestList) pData;
513:                    } else if (pData instanceof  Test) {
514:                        pTest = (Test) pData;
515:                    }
516:                }
517:
518:                if (pTestList == null) {
519:                    if (pTest != null) {
520:                        pTestList = pTest.getTestListFromModel();
521:                    }
522:                    if (pTestList == null && pFamily != null) {
523:                        pTestList = new TestList("tmp", "JUNIT TEST SUITE");
524:                    }
525:                }
526:
527:                if (pTestList != null) {
528:                    Util.log("Test List selected = "
529:                            + pTestList.getNameFromModel());
530:                    JunitTester pJunitTester = new JunitTester(null, true,
531:                            pProject, true, "", "", "", "");
532:                    if (pJunitTester.execute()) {
533:                        Util.log("[SimpleJunitPlugin:editTest] ok pressed");
534:                        Attachment pNewattach = pJunitTester.getNewAttachment();
535:                        Attachment pSelectedattach = pJunitTester
536:                                .getSelectedAttachment();
537:                        if (pSelectedattach != null) {
538:                            if (pSelectedattach.equals(pNewattach)) {
539:                                if (!addAttachmentToProject(pNewattach,
540:                                        DataModel.getCurrentProject()))
541:                                    return;
542:
543:                            }
544:                        }
545:                        String version = pJunitTester.getJunitVersion();
546:                        if (version.equals("4.x")) {
547:                            if (!(currentJunitAnalyser instanceof  Junit4ClassAnalyser)) {
548:                                currentJunitAnalyser = new Junit4ClassAnalyser(
549:                                        this );
550:                            }
551:                        } else {
552:                            //3.x
553:                            if (!(currentJunitAnalyser instanceof  Junit3ClassAnalyser)) {
554:                                currentJunitAnalyser = new Junit3ClassAnalyser(
555:                                        this );
556:                            }
557:                        }
558:                        try {
559:                            if (!pTestList.isInBase()) {
560:                                pTestList.updateInModel(pJunitTester
561:                                        .getJunitClass(), "JUNIT " + version
562:                                        + " TEST SUITE");
563:                                pFamily.addTestListInDB(pTestList);
564:                            }
565:                            currentJunitAnalyser.createBeanShellJunitTest(
566:                                    pSelectedattach, pJunitTester
567:                                            .getJunitClass(), pTestList);
568:                        } catch (Exception e) {
569:                            Tools.ihmExceptionView(e);
570:                        }
571:                    }
572:                }
573:            }
574:
575:            /********************* interface common ********************/
576:
577:            String getTestName(String name, TestList pSuite, int index) {
578:                if (pSuite.getTestFromModel(name) != null) {
579:                    index++;
580:                    name = name + index;
581:                    return getTestName(name, pSuite, index);
582:                } else {
583:                    return name;
584:                }
585:            }
586:
587:            void addTest(String name, TestList pSuite, String toWrite) {
588:                String[] idReqs = {};
589:                addTest(name, "Junit TestCase", idReqs, pSuite, toWrite);
590:            }
591:
592:            void addTest(String name, String description, String[] idReqs,
593:                    TestList pSuite, String toWrite) {
594:                name = getTestName(name, pSuite, 0);
595:                AutomaticTest pTest = new AutomaticTest(name, description,
596:                        id_plugin);
597:                pTest.setConceptorLoginInModel(DataModel.getCurrentUser()
598:                        .getLoginFromModel());
599:                if (Api.isConnected()) {
600:                    try {
601:                        pSuite.addTestInDBAndModel(pTest);
602:                    } catch (Exception e1) {
603:                        Tools.ihmExceptionView(e1);
604:                        return;
605:                    }
606:                }
607:                File file = null;
608:                try {
609:                    Util
610:                            .log("[SimpleJunitPlugin:AddTest] Create test Script file");
611:                    file = writeJunitFile(null, pTest, toWrite);
612:                } catch (Exception e2) {
613:                    Tools.ihmExceptionView(e2);
614:                    e2.printStackTrace();
615:                    return;
616:                }
617:                Script pScript = new Script(file.getName(), "Junit test script");
618:                pScript.setLocalisation(file.getAbsolutePath());
619:                pScript.setTypeInModel(ApiConstants.TEST_SCRIPT);
620:                pScript
621:                        .setScriptExtensionInModel(pTest
622:                                .getExtensionFromModel());
623:                //pScript.setPlugArg("");
624:
625:                if (Api.isConnected()) {
626:                    try {
627:                        pTest.addScriptInDBAndModel(pScript, file);
628:                        Util
629:                                .log("[SimpleJunitPlugin:AddTest] Add Script : "
630:                                        + pScript.getNameFromModel()
631:                                        + " to DB & Model");
632:                    } catch (Exception e3) {
633:                        Tools.ihmExceptionView(e3);
634:                        return;
635:                    }
636:                }
637:
638:                //add associated requirements
639:                Vector<ReqManager> reqManagers = pIPlugObject.getReqManagers();
640:                for (ReqManager reqManager : reqManagers) {
641:                    for (String idReqString : idReqs) {
642:                        int idReq = new Integer(idReqString).intValue();
643:                        reqManager.addReqLinkWithTest(pTest, idReq);
644:                    }
645:                }
646:            }
647:
648:            public void activatePluginInCampToolsMenu(javax.swing.JMenu jMenu) {
649:            }
650:
651:            public void activatePluginInDataToolsMenu(javax.swing.JMenu jMenu) {
652:            }
653:
654:            public void activatePluginInDynamicComponent(Integer integer) {
655:            }
656:
657:            public void activatePluginInStaticComponent(Integer integer) {
658:            }
659:
660:            public void allPluginActived(ExtensionPoint commonExtensions,
661:                    ExtensionPoint testDriverExtensions,
662:                    ExtensionPoint scriptEngineExtensions,
663:                    ExtensionPoint bugTrackerExtensions) {
664:
665:            }
666:
667:            public void activatePluginInTestToolsMenu(javax.swing.JMenu jMenu) {
668:                //TODO
669:                JMenu junitSubMenu = new JMenu("Plugin Junit");
670:                JMenuItem junitNatifItem = new JMenuItem(Language.getInstance()
671:                        .getText("Créer_une_suite_de_tests_Junit_(native)"));
672:                junitNatifItem.addActionListener(new ActionListener() {
673:                    public void actionPerformed(ActionEvent e) {
674:                        createJunitSuitePerformed();
675:                    }
676:                });
677:                JMenuItem junitBeanshellItem = new JMenuItem(
678:                        Language
679:                                .getInstance()
680:                                .getText(
681:                                        "Créer_une_suite_de_tests_Junit_(plug-in_beanshell)"));
682:                junitBeanshellItem.addActionListener(new ActionListener() {
683:                    public void actionPerformed(ActionEvent e) {
684:                        createBeanshellJunitSuitePerformed();
685:                    }
686:                });
687:
688:                junitSubMenu.add(junitNatifItem);
689:                junitSubMenu.add(junitBeanshellItem);
690:                jMenu.addSeparator();
691:                jMenu.add(junitSubMenu);
692:            }
693:
694:            public void freeze() {
695:            }
696:
697:            public java.util.Vector getUsedUIComponents() {
698:                return null;
699:            }
700:
701:            public void init(Object pIPlugObject) {
702:                this .pIPlugObject = (IPlugObject) pIPlugObject;
703:            }
704:
705:            public boolean isActivableInCampToolsMenu() {
706:                return false;
707:            }
708:
709:            public boolean isActivableInDataToolsMenu() {
710:                return false;
711:            }
712:
713:            public boolean isActivableInTestToolsMenu() {
714:                return true;
715:            }
716:
717:            public boolean isFreezable() {
718:                return false;
719:            }
720:
721:            public boolean isFreezed() {
722:                return false;
723:            }
724:
725:            public void unFreeze() {
726:            }
727:
728:            public boolean usesOtherUIComponents() {
729:                return false;
730:            }
731:
732:            public IPlugObject getPIPlugObject() {
733:                return pIPlugObject;
734:            }
735:
736:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.