Source Code Cross Referenced for AutomaticTest.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.net.URL;
028:        import java.util.ArrayList;
029:        import java.util.HashMap;
030:        import java.util.Hashtable;
031:
032:        import org.java.plugin.Extension;
033:        import org.objectweb.salome_tmf.api.Api;
034:        import org.objectweb.salome_tmf.api.ApiConstants;
035:        import org.objectweb.salome_tmf.api.Util;
036:        import org.objectweb.salome_tmf.api.data.AutomaticTestWrapper;
037:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
038:        import org.objectweb.salome_tmf.api.data.ScriptWrapper;
039:        import org.objectweb.salome_tmf.api.sql.ISQLAutomaticTest;
040:        import org.objectweb.salome_tmf.plugins.JPFManager;
041:        import org.objectweb.salome_tmf.plugins.core.TestDriver;
042:
043:        public class AutomaticTest extends Test {
044:
045:            static ISQLAutomaticTest pISQLAutomaticTest = null;
046:
047:            protected Script script;
048:            protected String testExtension = null;
049:            protected TestDriver driver = null;
050:
051:            public AutomaticTest(String name, String description,
052:                    String testExtension) {
053:                super (name, description);
054:                script = null;
055:                this .testExtension = testExtension;
056:                if (pISQLAutomaticTest == null) {
057:                    pISQLAutomaticTest = Api.getISQLObjectFactory()
058:                            .getISQLAutomaticTest();
059:                }
060:
061:            }
062:
063:            public AutomaticTest(AutomaticTestWrapper pTest) {
064:                super (pTest);
065:                script = null;
066:                this .testExtension = pTest.getTestExtension();
067:                if (pISQLAutomaticTest == null) {
068:                    pISQLAutomaticTest = Api.getISQLObjectFactory()
069:                            .getISQLAutomaticTest();
070:                }
071:            }
072:
073:            public AutomaticTest(TestList pList, AutomaticTestWrapper pTest) {
074:                super (pList, pTest);
075:                script = null;
076:                this .testExtension = pTest.getTestExtension();
077:                if (pISQLAutomaticTest == null) {
078:                    pISQLAutomaticTest = Api.getISQLObjectFactory()
079:                            .getISQLAutomaticTest();
080:                }
081:            }
082:
083:            public void reloadFromDB(boolean base,
084:                    Hashtable<String, Parameter> paramInModel, boolean attach)
085:                    throws Exception {
086:                int transNuber = -1;
087:                try {
088:                    transNuber = Api
089:                            .beginTransaction(101, ApiConstants.LOADING);
090:
091:                    commonReloadFromDB(base, paramInModel, attach);
092:                    reloadScriptFromDB();
093:
094:                    Api.commitTrans(transNuber);
095:                } catch (Exception e) {
096:                    Api.forceRollBackTrans(transNuber);
097:                    throw e;
098:                }
099:            }
100:
101:            public void reloadScriptFromDB() throws Exception {
102:                if (!isInBase()) {
103:                    throw new Exception("AutomatedTest " + name
104:                            + " is not in BDD");
105:                }
106:                ScriptWrapper pScriptWrapper = pISQLAutomaticTest
107:                        .getTestScript(idBdd);
108:                if (pScriptWrapper != null) {
109:                    script = new Script(pScriptWrapper);
110:                } else {
111:                    script = null;
112:                }
113:            }
114:
115:            /******************************************************************************/
116:            /** 							ACCESSEURS ET MUTATEURS						***/
117:            /******************************************************************************/
118:
119:            public String getExtensionFromModel() {
120:                return testExtension;
121:            }
122:
123:            public TestDriver getDriverFromModel() {
124:                return driver;
125:            }
126:
127:            public TestDriver ActivateExtention(Extension pExtension,
128:                    URL urlSalome, JPFManager jpf) { //!!! salome.ihm.SalomeTMF.jpf.activateExtension(pExtension);
129:                Util.log("[TestDriver]-> testExtension = " + testExtension
130:                        + ", driver " + driver);
131:                if (testExtension != null && driver == null) {
132:                    // Create PluginExtention
133:                    if (pExtension != null) {
134:                        // activation du plugin
135:                        try {
136:                            driver = (TestDriver) jpf
137:                                    .activateExtension(pExtension);
138:                            driver.initTestDriver(urlSalome);
139:                            Util.log("[Automated Test] Driver ref : " + driver);
140:                        } catch (Exception e) {
141:                            driver = null;
142:                            e.printStackTrace();
143:                        }
144:                    }
145:                }
146:                return driver;
147:            }
148:
149:            /***************************** Basic Operation *********************************/
150:
151:            void addInDB(int idTestList) throws Exception {
152:                if (isInBase()) {
153:                    throw new Exception("AutomatedTest " + name
154:                            + " is already in BDD");
155:                }
156:                idBdd = pISQLAutomaticTest.insert(idTestList, name,
157:                        description, conceptorLogin, testExtension);
158:                Project.pCurrentProject.notifyChanged(ApiConstants.INSERT_TEST,
159:                        this );
160:            }
161:
162:            /*	 
163:             * used by TestList
164:             * WARNING This methode don't delete the test in campaign model
165:             * Use for that TestPlanData.deleteTestFromListFromModel()
166:             */
167:            void deleteInModel() {
168:                script = null;
169:                clearAttachInModel();
170:                parameterList.clear();
171:            }
172:
173:            void deleteInDBAndModel() throws Exception {
174:                deleteInDB();
175:                deleteInModel();
176:            }
177:
178:            /**************************** PARAMETERS ****************************************/
179:
180:            void deleteUseParameterInModel(Parameter pParm) {
181:                deleteUseParameterInModel(pParm.getNameFromModel());
182:            }
183:
184:            /**************************** Script ****************************************/
185:
186:            public void addScriptInDB(Script script, File file)
187:                    throws Exception {
188:
189:                if (!isInBase()) {
190:                    throw new Exception("AutomatedTest " + name
191:                            + " is not in BDD");
192:                }
193:                //Avant script.getLocalisation() a la pace de script.getNameFromModel()
194:                int id = pISQLAutomaticTest.addScript(idBdd,
195:                        new SalomeFileWrapper(file), script
196:                                .getDescriptionFromModel(), script
197:                                .getNameFromModel(), script
198:                                .getPlugArgFromModel(), script
199:                                .getScriptExtensionFromModel());
200:                script.setIdBdd(id);
201:            }
202:
203:            public void addScriptInModel(Script newScript) {
204:                script = newScript;
205:                if (script != null) {
206:                    script.setScriptExtensionInModel(testExtension);
207:                }
208:            }
209:
210:            public void addScriptInDBAndModel(Script script, File file)
211:                    throws Exception {
212:                addScriptInDB(script, file);
213:                addScriptInModel(script);
214:            }
215:
216:            public void deleteScriptInDB() throws Exception {
217:                if (!isInBase()) {
218:                    throw new Exception("AutomatedTest " + name
219:                            + " is not in BDD");
220:                }
221:                pISQLAutomaticTest.deleteScript(idBdd);
222:            }
223:
224:            public void deleteScriptInModel() {
225:                script = null;
226:            }
227:
228:            public void deleteScriptInDBAndModel() throws Exception {
229:                deleteScriptInDB();
230:                deleteScriptInModel();
231:            }
232:
233:            public File getTestScriptFromDB() throws Exception {
234:                if (!isInBase()) {
235:                    throw new Exception("AutomatedTest " + name
236:                            + " is not in BDD");
237:                }
238:                return pISQLAutomaticTest.getTestScriptFile(idBdd).toFile();
239:
240:            }
241:
242:            public Script getScriptFromModel() {
243:                return script;
244:            }
245:
246:            /**** COPIER/COLER ************/
247:
248:            public static AutomaticTest getCopie(AutomaticTest toCopie)
249:                    throws Exception {
250:                AutomaticTest pCopie = new AutomaticTest(toCopie
251:                        .getNameFromModel(), toCopie.getDescriptionFromModel(),
252:                        toCopie.testExtension);
253:                toCopie.reloadUSeParameterFromDB(DataLoader.getCurrentProject()
254:                        .getParameterSetFromModel());
255:                ArrayList<Parameter> paramList = toCopie
256:                        .getParameterListFromModel();
257:                for (Parameter param : paramList) {
258:                    pCopie.setUseParamInModel(param);
259:                }
260:                //pCopie.reloadUSeParameterFromDB(DataLoader.getCurrentProject().getParameterSetFromModel());
261:
262:                ScriptWrapper pScriptWrapper = pISQLAutomaticTest
263:                        .getTestScript(toCopie.getIdBdd());
264:                if (pScriptWrapper != null) {
265:                    File fScript = toCopie.getTestScriptFromDB();
266:                    Script pScritp = new Script(pScriptWrapper);
267:                    pScritp.setNameInModel(fScript.getName());
268:                    pScritp.setIdBdd(-1);
269:                    pCopie.script = pScritp;
270:                } else {
271:                    pCopie.script = null;
272:                }
273:                return pCopie;
274:            }
275:
276:            public static AutomaticTest copieIn(AutomaticTest toCopie,
277:                    TestList pTestList) throws Exception {
278:                AutomaticTest pTest = AutomaticTest
279:                        .getCopie((AutomaticTest) toCopie);
280:                String testName = toCopie.getNameFromModel();
281:                int i = 0;
282:                while (Test.isInBase(pTestList, testName)) {
283:                    testName = toCopie.getNameFromModel() + "_" + i;
284:                    i++;
285:                }
286:                pTest.updateInModel(testName, pTest.getDescriptionFromModel());
287:                pTest.setConceptorLoginInModel(DataLoader.getCurrentUser()
288:                        .getLoginFromModel());
289:                /* 1 Ajout du test */
290:                pTestList.addTestInDBAndModel(pTest);
291:
292:                /* 2 Ajout des paramtres */
293:                ArrayList<Parameter> paramList = pTest
294:                        .getParameterListFromModel();
295:                for (Parameter param : paramList) {
296:                    pTest.setUseParamInDB(param.getIdBdd());
297:                }
298:
299:                /* 3 Ajout du Script de test*/
300:                //ScriptWrapper pScriptWrapper = pISQLAutomaticTest.getTestScript(toCopie.getIdBdd());
301:                try {
302:                    File fScript = toCopie.getTestScriptFromDB();
303:                    if (fScript != null) {
304:                        pTest.addScriptInDBAndModel(pTest.getScriptFromModel(),
305:                                fScript);
306:                    }
307:                } catch (Exception e) {
308:                    //e.printStackTrace();
309:                }
310:                return pTest;
311:            }
312:
313:            /**
314:             * Creates a copy of an automatic test in the same suite, the imported test takes
315:             * the parameter "oldName" as name
316:             * @param testDB
317:             * @param testName
318:             * @return
319:             */
320:            public static Test createCopyInDBAndModel(AutomaticTest toCopy,
321:                    String oldName) throws Exception {
322:                AutomaticTest pCopy = new AutomaticTest(oldName, toCopy
323:                        .getDescriptionFromModel(), toCopy.testExtension);
324:                toCopy.reloadUSeParameterFromDB(DataLoader.getCurrentProject()
325:                        .getParameterSetFromModel());
326:                pCopy.setConceptorLoginInModel(DataLoader.getCurrentUser()
327:                        .getLoginFromModel());
328:
329:                toCopy.getTestListFromModel().addTestInDBAndModel(pCopy);
330:
331:                //add attachments
332:                HashMap<String, Attachment> attachs = toCopy
333:                        .getAttachmentMapFromModel();
334:                for (Attachment attach : attachs.values()) {
335:                    if (attach instanceof  UrlAttachment) {
336:                        pCopy.addAttachementInDBAndModel(attach);
337:                    } else {
338:                        FileAttachment fileAttach = (FileAttachment) attach;
339:                        File attachFile = fileAttach.getFileFromDB(null);
340:                        FileAttachment toAdd = new FileAttachment(attachFile,
341:                                fileAttach.getDescriptionFromModel());
342:                        pCopy.addAttachementInDBAndModel(toAdd);
343:                        attachFile.delete();
344:                    }
345:                }
346:
347:                //parameters
348:                ArrayList<Parameter> paramList = toCopy
349:                        .getParameterListFromModel();
350:                for (Parameter param : paramList) {
351:                    pCopy.setUseParamInDBAndModel(param);
352:                }
353:
354:                //script
355:                ScriptWrapper pScriptWrapper = pISQLAutomaticTest
356:                        .getTestScript(toCopy.getIdBdd());
357:                File fScript = null;
358:                if (pScriptWrapper != null) {
359:                    fScript = toCopy.getTestScriptFromDB();
360:                    Script pScript = new Script(pScriptWrapper);
361:                    pScript.setNameInModel(fScript.getName());
362:                    pScript.setIdBdd(-1);
363:                    pCopy.script = pScript;
364:                } else {
365:                    pCopy.script = null;
366:                }
367:                pCopy
368:                        .addScriptInDBAndModel(pCopy.getScriptFromModel(),
369:                                fScript);
370:
371:                return pCopy;
372:            }
373:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.