Source Code Cross Referenced for SQLManualTest.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » databaseSQL » 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.databaseSQL 
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.databaseSQL;
025:
026:        import java.sql.PreparedStatement;
027:        import java.sql.ResultSet;
028:        import java.util.Vector;
029:
030:        import org.objectweb.salome_tmf.api.Api;
031:        import org.objectweb.salome_tmf.api.ApiConstants;
032:        import org.objectweb.salome_tmf.api.Permission;
033:        import org.objectweb.salome_tmf.api.Util;
034:        import org.objectweb.salome_tmf.api.data.ActionWrapper;
035:        import org.objectweb.salome_tmf.api.data.DataUpToDateException;
036:        import org.objectweb.salome_tmf.api.sql.ISQLManualTest;
037:
038:        public class SQLManualTest extends SQLTest implements  ISQLManualTest {
039:
040:            /**
041:             * Insert a Manual test in table CAS_TEST
042:             * @param idTestList : the id of the testlist which contain the inserted test
043:             * @param name : the name of the test
044:             * @param description : the description of the tests
045:             * @param conceptor : the conceptor of the test
046:             * @param extension : the plug-in extension of the test
047:             * @return the id of the test in table CAS_TEST
048:             * @throws Exception
049:             * need permission canCreateTest
050:             */
051:            public int insert(int idTestList, String name, String description,
052:                    String conceptor, String extension) throws Exception {
053:                int testId = -1;
054:                int transNumber = -1;
055:                if (idTestList < 1) {
056:                    throw new Exception(
057:                            "[SQLManualTest->insert] entry data are not valid");
058:                }
059:                if (!SQLEngine.specialAllow) {
060:                    if (!Permission.canCreateTest()) {
061:                        throw new SecurityException(
062:                                "[SQLTest : insert -> canCreateTest]");
063:                    }
064:                }
065:                if (SQLObjectFactory.getInstanceOfISQLTestList().getTestList(
066:                        idTestList) == null) {
067:                    throw new DataUpToDateException();
068:                }
069:                try {
070:                    transNumber = SQLEngine.beginTransaction(100,
071:                            ApiConstants.INSERT_TEST);
072:
073:                    int order = SQLObjectFactory.getInstanceOfISQLTestList()
074:                            .getNumberOfTest(idTestList);
075:                    order--; //Because index begin at 0
076:                    PreparedStatement prep = SQLEngine
077:                            .getSQLAddQuery("addTest"); //ok
078:                    int idPers = SQLObjectFactory.getInstanceOfISQLPersonne()
079:                            .getID(conceptor);
080:                    if (idPers < 1) {
081:                        throw new Exception(
082:                                "[SQLManualTest->insert] id is not valid : "
083:                                        + idPers + ", conceptor is :"
084:                                        + conceptor);
085:                    }
086:                    prep.setInt(1, idPers);
087:                    prep.setInt(2, idTestList);
088:                    prep.setString(3, name);
089:                    prep.setDate(4, Util.getCurrentDate());
090:                    prep.setTime(5, Util.getCurrentTime());
091:                    prep.setString(6, ApiConstants.MANUAL);
092:                    prep.setString(7, description);
093:                    prep.setInt(8, order + 1);
094:                    prep.setString(9, extension);
095:                    SQLEngine.runAddQuery(prep);
096:
097:                    testId = getID(idTestList, name);
098:                    if (testId < 1) {
099:                        throw new Exception(
100:                                "[SQLManualTest->insert] id is not valid : "
101:                                        + testId + ", TestList is :"
102:                                        + idTestList + ", test : " + name);
103:                    }
104:
105:                    SQLEngine.commitTrans(transNumber);
106:                } catch (Exception e) {
107:                    Util.log("[SQLManualTest->insert]" + e);
108:                    if (Api.isDEBUG()) {
109:                        e.printStackTrace();
110:                    }
111:                    SQLEngine.rollBackTrans(transNumber);
112:                    throw e;
113:                }
114:                return testId;
115:            }
116:
117:            /**
118:             * Delete the test in the database, this include :
119:             * delete test actions, and all reference (Parameter, Campaign) and the test attachments
120:             * @param idTest : id of the test
121:             * @throws Exception
122:             * @see ISQLAction.delete(int)
123:             * need permission canDeleteTest (do a special allow)
124:             */
125:            public void delete(int idTest) throws Exception {
126:                if (idTest < 1) {
127:                    throw new Exception(
128:                            "[SQLManualTest->delete] entry data are not valid");
129:                }
130:                int transNumber = -1;
131:                boolean dospecialAllow = false;
132:                if (!SQLEngine.specialAllow) {
133:                    if (!Permission.canDeleteTest()) {
134:                        throw new SecurityException(
135:                                "[SQLTest : delete -> canDeleteTest]");
136:                    }
137:                    //Require specialAllow
138:                    dospecialAllow = true;
139:                    SQLEngine.setSpecialAllow(true);
140:                }
141:                try {
142:
143:                    transNumber = SQLEngine.beginTransaction(110,
144:                            ApiConstants.DELETE_TEST);
145:
146:                    // Begin Delete
147:                    //Delete All test actions if test is manual
148:                    ActionWrapper[] actionList = getTestActions(idTest);
149:                    for (int i = 0; i < actionList.length; i++) {
150:                        int actionId = (actionList[i]).getIdBDD();
151:                        SQLObjectFactory.getInstanceOfISQLAction().delete(
152:                                actionId, false);
153:                    }
154:
155:                    deleteRef(idTest, true);
156:
157:                    SQLEngine.commitTrans(transNumber);
158:                } catch (Exception e) {
159:                    if (dospecialAllow) {
160:                        SQLEngine.setSpecialAllow(false);
161:                    }
162:                    Util.log("[SQLManualTest->delete]" + e);
163:                    if (Api.isDEBUG()) {
164:                        e.printStackTrace();
165:                    }
166:                    SQLEngine.rollBackTrans(transNumber);
167:                    throw e;
168:                }
169:                if (dospecialAllow) {
170:                    SQLEngine.setSpecialAllow(false);
171:                }
172:            }
173:
174:            /**
175:             * Delete reference about using parameter paramId (table CAS_PARAM_TEST) for the test and his actions
176:             * @param idTest : id of the test
177:             * @param paramId : id of the parameter
178:             * @throws Exception
179:             * need permission  canUpdateTest
180:             * @see deleteUseParamRef
181:             * @see ISQLAction.deleteParamUse(int, int)
182:             */
183:            public void deleteUseParam(int idTest, int paramId)
184:                    throws Exception {
185:                if (idTest < 1 || paramId < 1) {
186:                    throw new Exception(
187:                            "[SQLManualTest->deleteUseParam] entry data are not valid");
188:                }
189:                int transNumber = -1;
190:                if (!SQLEngine.specialAllow) {
191:                    if (!Permission.canUpdateTest()) {
192:                        throw new SecurityException(
193:                                "[SQLTest : deleteUseParam -> canUpdateTest]");
194:                    }
195:                }
196:                try {
197:                    transNumber = SQLEngine.beginTransaction(100,
198:                            ApiConstants.DELETE_PARAMETER_FROM_TEST);
199:
200:                    ActionWrapper[] actionList = getTestActions(idTest);
201:                    for (int i = 0; i < actionList.length; i++) {
202:                        ActionWrapper pActionWrapper = actionList[i];
203:                        SQLObjectFactory.getInstanceOfISQLAction()
204:                                .deleteParamUse(pActionWrapper.getIdBDD(),
205:                                        paramId);
206:                    }
207:                    deleteUseParamRef(idTest, paramId);
208:
209:                    SQLEngine.commitTrans(transNumber);
210:                } catch (Exception e) {
211:                    Util.log("[SQLManualTest->deleteUseParam]" + e);
212:                    if (Api.isDEBUG()) {
213:                        e.printStackTrace();
214:                    }
215:                    SQLEngine.rollBackTrans(transNumber);
216:                    throw e;
217:                }
218:            }
219:
220:            /**
221:             * Get a Vector of ActionWrapper representing all Action of the test
222:             * @param idTest : id of the test
223:             * @return
224:             * @throws Exception
225:             */
226:            public ActionWrapper[] getTestActions(int idTest) throws Exception {
227:                if (idTest < 1) {
228:                    throw new Exception(
229:                            "[SQLManualTest->getTestActions] entry data are not valid");
230:                }
231:                Vector result = new Vector();
232:                PreparedStatement prep = SQLEngine
233:                        .getSQLSelectQuery("selectTestActions"); //ok
234:                prep.setInt(1, idTest);
235:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
236:
237:                while (stmtRes.next()) {
238:                    ActionWrapper pAction = new ActionWrapper();
239:                    pAction.setName(stmtRes.getString("nom_action"));
240:                    pAction.setDescription(stmtRes
241:                            .getString("description_action"));
242:                    pAction.setAwaitedResult(stmtRes
243:                            .getString("res_attendu_action"));
244:                    pAction.setOrderIndex(stmtRes.getInt("num_step_action"));
245:                    pAction.setIdBDD(stmtRes.getInt("id_action"));
246:                    pAction.setOrder(stmtRes.getInt("num_step_action"));
247:                    pAction.setIdTest(stmtRes.getInt("CAS_TEST_id_cas"));
248:                    result.addElement(pAction);
249:                }
250:                ActionWrapper[] awArray = new ActionWrapper[result.size()];
251:                for (int i = 0; i < result.size(); i++) {
252:                    awArray[i] = (ActionWrapper) result.get(i);
253:                }
254:                return awArray;
255:            }
256:
257:            /**
258:             * Get the number of action contening in the test identified by idTest
259:             * @param idTest
260:             * @return
261:             * @throws Exception
262:             */
263:            public int getNumberOfAction(int idTest) throws Exception {
264:                return getTestActions(idTest).length;
265:            }
266:
267:            /**
268:             * Get a ActionWrapper representing an action in position order for the test idTest
269:             * @param idTest : id of the test
270:             * @param order : order of the action
271:             * @return a ActionWrapper
272:             * @throws Exception
273:             */
274:            public ActionWrapper getActionByOrder(int idTest, int order)
275:                    throws Exception {
276:                if (idTest < 1 || order < 0) {
277:                    throw new Exception(
278:                            "[SQLManualTest->getActionByOrder] entry data are not valid");
279:                }
280:                ActionWrapper pAction = null;
281:                PreparedStatement prep = SQLEngine
282:                        .getSQLSelectQuery("selectActionByOrder"); //ok
283:                prep.setInt(1, idTest);
284:                prep.setInt(2, order);
285:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
286:
287:                while (stmtRes.next()) {
288:                    pAction = new ActionWrapper();
289:                    pAction.setName(stmtRes.getString("nom_action"));
290:                    pAction.setDescription(stmtRes
291:                            .getString("description_action"));
292:                    pAction.setIdBDD(stmtRes.getInt("id_action"));
293:                    pAction.setOrder(stmtRes.getInt("num_step_action"));
294:                }
295:                return pAction;
296:            }
297:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.