Source Code Cross Referenced for TestList.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » data » 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.data 
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 Marche Mikael
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.data;
025:
026:        import java.io.File;
027:        import java.util.ArrayList;
028:        import java.util.Collections;
029:        import java.util.Comparator;
030:        import java.util.Hashtable;
031:        import java.util.Vector;
032:
033:        import org.objectweb.salome_tmf.api.Api;
034:        import org.objectweb.salome_tmf.api.ApiConstants;
035:        import org.objectweb.salome_tmf.api.data.AutomaticTestWrapper;
036:        import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
037:        import org.objectweb.salome_tmf.api.data.ManualTestWrapper;
038:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
039:        import org.objectweb.salome_tmf.api.data.SuiteWrapper;
040:        import org.objectweb.salome_tmf.api.data.TestWrapper;
041:        import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
042:        import org.objectweb.salome_tmf.api.sql.ISQLTestList;
043:
044:        public class TestList extends WithAttachment {
045:
046:            transient static ISQLTestList pISQLTestList = null;
047:
048:            protected ArrayList testList;
049:            protected Family family;
050:            protected int order;
051:
052:            public TestList(String name, String description) {
053:                super (name, description);
054:                testList = new ArrayList();
055:                family = null;
056:                order = -1;
057:                if (pISQLTestList == null) {
058:                    pISQLTestList = Api.getISQLObjectFactory()
059:                            .getISQLTestList();
060:                }
061:            }
062:
063:            public TestList(SuiteWrapper pSuite) {
064:                super (pSuite.getName(), pSuite.getDescription());
065:                idBdd = pSuite.getIdBDD();
066:                testList = new ArrayList();
067:                family = null;
068:                order = pSuite.getOrder();
069:                if (pISQLTestList == null) {
070:                    pISQLTestList = Api.getISQLObjectFactory()
071:                            .getISQLTestList();
072:                }
073:            }
074:
075:            public TestList(Family family, SuiteWrapper pSuite) {
076:                this (pSuite);
077:                this .family = family;
078:            }
079:
080:            public void reloadBaseFromDB() throws Exception {
081:                if (!isInBase()) {
082:                    throw new Exception("TestList " + name + " is not in BDD");
083:                }
084:                SuiteWrapper pSuiteWrapper = pISQLTestList.getTestList(idBdd);
085:                name = pSuiteWrapper.getName();
086:                order = pSuiteWrapper.getOrder();
087:                description = pSuiteWrapper.getDescription();
088:            }
089:
090:            public void reloadFromDB() throws Exception {
091:                reloadBaseFromDB();
092:
093:                reloadAttachmentDataFromDB(false);
094:            }
095:
096:            /**************************************************************************/
097:            /** 						MUTATEURS ET ACCESSEURS						***/
098:            /**************************************************************************/
099:
100:            public Family getFamilyFromModel() {
101:                return family;
102:            }
103:
104:            /*
105:            public void setFamilyInModel(Family newFamily) {
106:            	family = newFamily;
107:            } */
108:
109:            /***************************** Basic Operation *********************************/
110:
111:            /* Used By Family */
112:            void addInDB(int idFamily) throws Exception {
113:                if (isInBase()) {
114:                    throw new Exception("TestList " + name + " already in BDD");
115:                }
116:                if (idFamily == -1) {
117:                    idFamily = family.getIdBdd();
118:                    if (idFamily == -1) {
119:                        throw new Exception("Family is not set");
120:                    }
121:                }
122:                idBdd = pISQLTestList.insert(idFamily, name, description);
123:                order = pISQLTestList.getTestList(idBdd).getOrder();
124:                Project.pCurrentProject.notifyChanged(
125:                        ApiConstants.INSERT_SUITE, this );
126:            }
127:
128:            /* Used By Family */
129:            void addInModel(Family newFamily) {
130:                family = newFamily;
131:            }
132:
133:            /* Used By Family */
134:            void addInDBAndModel(Family newFamily) throws Exception {
135:                addInDB(newFamily.getIdBdd());
136:                addInModel(newFamily);
137:            }
138:
139:            public void updateInDB(String newName, String newDesc)
140:                    throws Exception {
141:                if (!isInBase()) {
142:                    throw new Exception("TestList " + name + " is not in BDD");
143:                }
144:                pISQLTestList.update(idBdd, newName, newDesc);
145:                Project.pCurrentProject.notifyChanged(
146:                        ApiConstants.UPDATE_SUITE, this , new String(name),
147:                        newName);
148:            }
149:
150:            public void updateInModel(String newName, String newDesc) {
151:                name = newName;
152:                description = newDesc;
153:            }
154:
155:            public void updateInDBAndModel(String newName, String newDesc)
156:                    throws Exception {
157:                updateInDB(newName, newDesc);
158:                updateInModel(newName, newDesc);
159:            }
160:
161:            public void updateOrderInDBAndModel(boolean inc) throws Exception {
162:                if (!isInBase()) {
163:                    throw new Exception("TestList " + name + " is not in BDD");
164:                }
165:                order = pISQLTestList.updateOrder(idBdd, inc);
166:            }
167:
168:            /* Used By Family */
169:            void deleteInDB() throws Exception {
170:                if (!isInBase()) {
171:                    throw new Exception("TestList " + name + " is not in BDD");
172:                }
173:                pISQLTestList.delete(idBdd);
174:                Project.pCurrentProject.notifyChanged(
175:                        ApiConstants.DELETE_SUITE, this );
176:            }
177:
178:            /* Used By Family */
179:            void deleteInModel() {
180:                clearAttachInModel();
181:                for (int i = 0; i < testList.size(); i++) {
182:                    Test pTest = (Test) testList.get(i);
183:                    pTest.deleteInModel();
184:                    Project.pCurrentProject.notifyChanged(
185:                            ApiConstants.DELETE_TEST, pTest);
186:                }
187:                testList.clear();
188:            }
189:
190:            /* Used By Family */
191:            void deleteInDBAndModel() throws Exception {
192:                deleteInDB();
193:
194:                deleteInModel();
195:            }
196:
197:            /************************* TESTS ******************************/
198:
199:            public void reloadTestsFromDB(Hashtable paramInModel)
200:                    throws Exception {
201:                if (!isInBase()) {
202:                    throw new Exception("TestList " + name + " is not in BDD");
203:                }
204:
205:                for (int i = 0; i < testList.size(); i++) {
206:                    ((Test) testList.get(i)).deleteInModel();
207:                }
208:                testList.clear();
209:                Vector testVector = getTestsWrapperFromDB();
210:                for (int i = 0; i < testVector.size(); i++) {
211:                    TestWrapper testBdd = (TestWrapper) testVector.get(i);
212:                    Test test;
213:                    if (testBdd.getType().equals(ApiConstants.MANUAL)) {
214:                        test = new ManualTest(this , new ManualTestWrapper(
215:                                testBdd));
216:                    } else {
217:                        test = new AutomaticTest(this ,
218:                                new AutomaticTestWrapper(testBdd));
219:                    }
220:                    test.reloadFromDB(false, paramInModel, true);
221:                    addTestInModel(test);
222:                }
223:            }
224:
225:            public ArrayList getTestListFromModel() {
226:                return testList;
227:            }
228:
229:            public void setTestListInModel(ArrayList list) {
230:                testList = list;
231:            }
232:
233:            public void addTestInModel(Test test) {
234:                if (!hasTestInModel(test.getNameFromModel())) {
235:                    testList.add(test);
236:                }
237:                test.addInModel(this );
238:            }
239:
240:            public void addTestInDB(Test test) throws Exception {
241:                test.addInDB(idBdd);
242:            }
243:
244:            public void addTestInDBAndModel(Test test) throws Exception {
245:                addTestInDB(test);
246:                addTestInModel(test);
247:            }
248:
249:            public boolean hasTestInModel(String name) {
250:                for (int i = 0; i < testList.size(); i++) {
251:                    if (((Test) testList.get(i)).getNameFromModel()
252:                            .equals(name)) {
253:                        return true;
254:                    }
255:                }
256:                return false;
257:            }
258:
259:            public void deleteTestInModel(Test test) { //ancien removeTest
260:                testList.remove(test);
261:                test.deleteInModel();
262:                // Do reoder ????
263:                for (int i = 0; i < testList.size(); i++) {
264:                    ((Test) (testList.get(i))).setOrderInModel(i);
265:                }
266:            }
267:
268:            public void deleteTestInDB(Test test) throws Exception { //ancien removeTest
269:                test.deleteInDB();
270:            }
271:
272:            public void deleteTestInDBAndModel(Test test) throws Exception { //ancien removeTest
273:                deleteTestInDB(test);
274:                deleteTestInModel(test);
275:            }
276:
277:            public Test getTestFromModel(String testName) {
278:                for (int i = 0; i < testList.size(); i++) {
279:                    if (((Test) testList.get(i)).getNameFromModel().equals(
280:                            testName)) {
281:                        return (Test) testList.get(i);
282:                    }
283:                }
284:                return null;
285:            }
286:
287:            public Test getTestFromModel(int id) {
288:                for (int i = 0; i < testList.size(); i++) {
289:                    if (((Test) testList.get(i)).getIdBdd() == id) {
290:                        return (Test) testList.get(i);
291:                    }
292:                }
293:                return null;
294:            }
295:
296:            public Vector getTestsWrapperFromDB() throws Exception {
297:                if (!isInBase()) {
298:                    throw new Exception("TestList " + name + " is not in BDD");
299:                }
300:                TestWrapper[] tmpArray = pISQLTestList.getTestsWrapper(idBdd);
301:                Vector tmpVector = new Vector();
302:                for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
303:                    tmpVector.add(tmpArray[tmpI]);
304:                }
305:                return tmpVector;
306:            }
307:
308:            /************************** ATTACHEMENTS **********************/
309:            public void addAttachementInDB(Attachment attach) throws Exception {
310:                if (attach instanceof  FileAttachment) {
311:                    addAttachFileInDB((FileAttachment) attach);
312:                } else {
313:                    addAttachUrlInDB((UrlAttachment) attach);
314:                }
315:            }
316:
317:            void addAttachFileInDB(FileAttachment file) throws Exception {
318:                if (!isInBase()) {
319:                    throw new Exception("TestList " + name + " is not in BDD");
320:                }
321:                File f = file.getLocalFile();
322:                int id = pISQLTestList.addAttachFile(idBdd,
323:                        new SalomeFileWrapper(f), file
324:                                .getDescriptionFromModel());
325:                file.setIdBdd(id);
326:            }
327:
328:            void addAttachUrlInDB(UrlAttachment url) throws Exception {
329:                if (!isInBase()) {
330:                    throw new Exception("TestList " + name + " is not in BDD");
331:                }
332:                int id = pISQLTestList.addAttachUrl(idBdd, url
333:                        .getNameFromModel(), url.getDescriptionFromModel());
334:                url.setIdBdd(id);
335:            }
336:
337:            protected void deleteAttachementInDB(int attachId) throws Exception {
338:                if (!isInBase()) {
339:                    throw new Exception("TestList " + name + " is not in BDD");
340:                }
341:                pISQLTestList.deleteAttach(idBdd, attachId);
342:            }
343:
344:            public void deleteAttachementInDBAndModel(Attachment attach)
345:                    throws Exception {
346:                deleteAttachementInDB(attach.getIdBdd());
347:                deleteAttachmentInModel(attach);
348:            }
349:
350:            public Vector getAttachFilesFromDB() throws Exception {
351:                if (!isInBase()) {
352:                    throw new Exception("TestList " + name + " is not in BDD");
353:                }
354:                FileAttachementWrapper[] tmpArray = pISQLTestList
355:                        .getAllAttachFiles(idBdd);
356:                Vector tmpVector = new Vector();
357:                for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
358:                    tmpVector.add(tmpArray[tmpI]);
359:                }
360:                return tmpVector;
361:            }
362:
363:            public Vector getAttachUrlsFromDB() throws Exception {
364:                if (!isInBase()) {
365:                    throw new Exception("TestList " + name + " is not in BDD");
366:                }
367:                UrlAttachementWrapper[] tmpArray = pISQLTestList
368:                        .getAllAttachUrls(idBdd);
369:                Vector tmpVector = new Vector();
370:                for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
371:                    tmpVector.add(tmpArray[tmpI]);
372:                }
373:                return tmpVector;
374:            }
375:
376:            //////////////////////////////////////////////////////////////////////////////////////
377:            /**
378:             * Retourne vrai si la suite passée en paramètre est présente dans la base
379:             * @param testList un suite de tests
380:             * @return vrai si la suite passée en paramètre est présente dans la base, 
381:             * faux sinon
382:             */
383:            public static boolean isInBase(Family pFamily, TestList testList) {
384:                return isInBase(pFamily, testList.getNameFromModel());
385:            } // Fin de la méthode isInBase/1
386:
387:            public static boolean isInBase(Family pFamily, String testListName) {
388:                try {
389:                    int id = pISQLTestList.getID(pFamily.getIdBdd(),
390:                            testListName);
391:                    if (id > 0) {
392:                        return true;
393:                    }
394:                    return false;
395:                } catch (Exception e) {
396:                }
397:                return false;
398:            } // Fin de la méthode isInBase/1
399:
400:            public boolean existeInBase() throws Exception {
401:                if (!isInBase()) {
402:                    return false;
403:                }
404:                return pISQLTestList.getID(family.getIdBdd(), name) == idBdd;
405:            }
406:
407:            /**** COPIER/COLER ************/
408:
409:            public static TestList getCopie(TestList toCopie) throws Exception {
410:                TestList pCopie = new TestList(toCopie.getNameFromModel(),
411:                        toCopie.getDescriptionFromModel());
412:
413:                TestWrapper[] Alltests = pISQLTestList.getTestsWrapper(toCopie
414:                        .getIdBdd());
415:                int size = Alltests.length;
416:                for (int i = 0; i < size; i++) {
417:                    Test pTest;
418:                    TestWrapper pTestWrapper = Alltests[i];
419:                    if (pTestWrapper.getType().equals(ApiConstants.MANUAL)) {
420:                        pTest = ManualTest.getCopie(new ManualTest(
421:                                new ManualTestWrapper(pTestWrapper)));
422:                    } else {
423:                        pTest = AutomaticTest.getCopie(new AutomaticTest(
424:                                new AutomaticTestWrapper(pTestWrapper)));
425:                    }
426:                    pCopie.addTestInModel(pTest);
427:                }
428:                return pCopie;
429:            }
430:
431:            public static TestList copieIn(TestList toCopie, Family pFamily)
432:                    throws Exception {
433:                TestList pCopie = new TestList(toCopie.getNameFromModel(),
434:                        toCopie.getDescriptionFromModel());
435:                String testListName = toCopie.getNameFromModel();
436:                int i = 0;
437:                while (pCopie.isInBase(pFamily, testListName)) {
438:                    testListName = toCopie.getNameFromModel() + "_" + i;
439:                    i++;
440:                }
441:                pCopie.updateInModel(testListName, toCopie
442:                        .getDescriptionFromModel());
443:                pFamily.addTestListInDBAndModel(pCopie);
444:
445:                TestWrapper[] Alltests = pISQLTestList.getTestsWrapper(toCopie
446:                        .getIdBdd());
447:
448:                int size = Alltests.length;
449:                for (i = 0; i < size; i++) {
450:                    TestWrapper pTestWrapper = Alltests[i];
451:                    if (pTestWrapper.getType().equals(ApiConstants.MANUAL)) {
452:                        ManualTest.copieIn(new ManualTest(
453:                                new ManualTestWrapper(pTestWrapper)), pCopie);
454:                    } else {
455:                        AutomaticTest
456:                                .copieIn(
457:                                        new AutomaticTest(
458:                                                new AutomaticTestWrapper(
459:                                                        pTestWrapper)), pCopie);
460:                    }
461:                }
462:                return pCopie;
463:            }
464:
465:            /******************* TRI ********************************************/
466:
467:            public void triTestInModel() {
468:                Collections.sort(testList, new ComparateurTest());
469:            }
470:
471:            class ComparateurTest implements  Comparator {
472:                public int compare(Object poTest1, Object poTest2) {
473:                    Test pTest1 = (Test) poTest1;
474:                    Test pTest2 = (Test) poTest2;
475:                    if (pTest1.getOrderFromModel() > pTest2.getOrderFromModel()) {
476:                        return 1;
477:                    } else {
478:                        return -1;
479:                    }
480:                }
481:            }
482:
483:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.