0001: /*
0002: * SalomeTMF is a Test Management Framework
0003: * Copyright (C) 2005 France Telecom R&D
0004: *
0005: * This library is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU Lesser General Public
0007: * License as published by the Free Software Foundation; either
0008: * version 2 of the License, or (at your option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful,
0011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013: * Lesser General Public License for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public
0016: * License along with this library; if not, write to the Free Software
0017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * @author Marche Mikael
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023:
0024: package org.objectweb.salome_tmf.data;
0025:
0026: import java.io.File;
0027: import java.sql.Date;
0028: import java.sql.Time;
0029: import java.util.ArrayList;
0030: import java.util.Collection;
0031: import java.util.Collections;
0032: import java.util.Comparator;
0033: import java.util.GregorianCalendar;
0034: import java.util.HashMap;
0035: import java.util.Iterator;
0036: import java.util.Set;
0037: import java.util.Vector;
0038:
0039: import org.objectweb.salome_tmf.api.Api;
0040: import org.objectweb.salome_tmf.api.ApiConstants;
0041: import org.objectweb.salome_tmf.api.Util;
0042: import org.objectweb.salome_tmf.api.data.AttachementWrapper;
0043: import org.objectweb.salome_tmf.api.data.ExecutionResultTestWrapper;
0044: import org.objectweb.salome_tmf.api.data.ExecutionActionWrapper;
0045: import org.objectweb.salome_tmf.api.data.ExecutionResultWrapper;
0046: import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
0047: import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
0048: import org.objectweb.salome_tmf.api.data.TestAttachmentWrapper;
0049: import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
0050: import org.objectweb.salome_tmf.api.sql.ISQLExecutionActionResult;
0051: import org.objectweb.salome_tmf.api.sql.ISQLExecutionResult;
0052: import org.objectweb.salome_tmf.api.sql.ISQLExecutionTestResult;
0053: import org.objectweb.salome_tmf.data.TestList.ComparateurTest;
0054: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
0055:
0056: public class ExecutionResult extends WithAttachment {
0057:
0058: static ISQLExecutionResult pISQLExecutionResult = null;
0059: static ISQLExecutionTestResult pISQLExecutionTestResult = null;
0060: static ISQLExecutionActionResult pISQLExecutionActionResult = null;
0061:
0062: protected String status;
0063: protected Date executionDate;
0064: protected Time time;
0065: protected String testerLogin;
0066: protected HashMap testsResultMap;
0067: protected int[] statTab;
0068: protected Execution pExecution;
0069:
0070: private boolean resultLoaded = false;
0071:
0072: public ExecutionResult(String name, String description,
0073: Execution pExecution) {
0074: super (name, description);
0075: Util
0076: .log("[ExecutionResult] -------------> NEW ExecutionResult : "
0077: + name);
0078: testsResultMap = new HashMap();
0079: statTab = new int[3];
0080: statTab[0] = 0;
0081: statTab[1] = 0;
0082: statTab[2] = 0;
0083: this .pExecution = pExecution;
0084: if (pISQLExecutionResult == null) {
0085: pISQLExecutionResult = Api.getISQLObjectFactory()
0086: .getISQLExecutionResult();
0087: }
0088: if (pISQLExecutionTestResult == null) {
0089: pISQLExecutionTestResult = Api.getISQLObjectFactory()
0090: .getISQLExecutionTestResult();
0091: }
0092: if (pISQLExecutionActionResult == null) {
0093: pISQLExecutionActionResult = Api.getISQLObjectFactory()
0094: .getISQLExecutionActionResult();
0095: }
0096: //actionsMap = new HashMap();
0097: //effectivResultMap = new HashMap();
0098: //descriptionResultMap = new HashMap();
0099: //awaitedResultMap = new HashMap();
0100: resultLoaded = true; // true because new ExcetionResult not in DB
0101: }
0102:
0103: public ExecutionResult(ExecutionResultWrapper pExecRes,
0104: Execution pExecution) {
0105: super (pExecRes.getName(), pExecRes.getDescription());
0106: Util
0107: .log("[ExecutionResult] -------------> NEW ExecutionResult : "
0108: + pExecRes.getName());
0109: idBdd = pExecRes.getIdBDD();
0110: statTab = new int[3];
0111: statTab[0] = pExecRes.getNumberOfSuccess();
0112: statTab[1] = pExecRes.getNumberOfFail();
0113: statTab[2] = pExecRes.getNumberOfUnknow();
0114: testerLogin = pExecRes.getTester();
0115: time = new Time(pExecRes.getTime());
0116: executionDate = pExecRes.getExecutionDate();
0117: status = pExecRes.getExecutionStatus();
0118: testsResultMap = new HashMap();
0119: this .pExecution = pExecution;
0120:
0121: if (pISQLExecutionResult == null) {
0122: pISQLExecutionResult = Api.getISQLObjectFactory()
0123: .getISQLExecutionResult();
0124: }
0125: if (pISQLExecutionTestResult == null) {
0126: pISQLExecutionTestResult = Api.getISQLObjectFactory()
0127: .getISQLExecutionTestResult();
0128: }
0129: if (pISQLExecutionActionResult == null) {
0130: pISQLExecutionActionResult = Api.getISQLObjectFactory()
0131: .getISQLExecutionActionResult();
0132: }
0133:
0134: //actionsMap = new HashMap();
0135: //effectivResultMap = new HashMap();
0136: //descriptionResultMap = new HashMap();
0137: //awaitedResultMap = new HashMap();
0138: }
0139:
0140: public ExecutionResult cloneInDB(boolean onlySucces, User pUser)
0141: throws Exception {
0142: int transNuber = -1;
0143: ExecutionResult pExecutionResult = new ExecutionResult("re-"
0144: + name, "", pExecution);
0145: pExecutionResult.setExecutionDateInModel(new Date(
0146: GregorianCalendar.getInstance().getTimeInMillis()));
0147: pExecutionResult.setTesterInModel(pUser.getLastNameFromModel()
0148: + " " + pUser.getFirstNameFromModel());
0149:
0150: try {
0151: transNuber = Api.beginTransaction(10,
0152: ApiConstants.INSERT_EXECUTION_RESULT);
0153:
0154: pExecutionResult.addInDB(pExecution, pUser);
0155: if (onlySucces) {
0156: pExecutionResult
0157: .setExecutionStatusInModel(ApiConstants.INCOMPLETED);
0158: } else {
0159: pExecutionResult.setExecutionStatusInModel(status);
0160: }
0161:
0162: int nbNotSucces = 0;
0163: int nbInconclusif = 0;
0164: int nbSucces = 0;
0165: int nbFail = 0;
0166:
0167: loadTestReult();
0168: ArrayList testInCampaign = pExecution
0169: .getCampagneFromModel().getTestListFromModel();
0170: ExecutionResultTestWrapper[] listOfResExecTest = pISQLExecutionResult
0171: .getExecutionResultTestWrapper(idBdd);
0172: for (int i = 0; i < listOfResExecTest.length; i++) {
0173: ExecutionResultTestWrapper pResTest = listOfResExecTest[i];
0174: int orderInCamp = getTestInModel(pResTest
0175: .getExcutedTest().getIdBDD(), testInCampaign);
0176: if (orderInCamp == -1) {
0177: // AIE QUE FAIRE
0178: throw new Exception(
0179: "[ExecutionResult->cloneInDB] No test in the campaign model are given for "
0180: + pResTest.getExcutedTest()
0181: .getIdBDD()
0182: + ", name ="
0183: + pResTest.getExcutedTest()
0184: .getName());
0185: } else {
0186: Test pTest = (Test) testInCampaign.get(orderInCamp);
0187: String status = pResTest.getStatus();
0188: ExecutionTestResult pExecutionTestResult = null;
0189: if (!status.equals(ApiConstants.SUCCESS)) {
0190: nbNotSucces++;
0191: if (onlySucces) {
0192: status = "";
0193: } else if (status.equals(ApiConstants.FAIL)) {
0194: nbFail++;
0195: } else if (status.equals(ApiConstants.UNKNOWN)) {
0196: nbInconclusif++;
0197: }
0198: } else {
0199: nbSucces++;
0200: }
0201: pExecutionTestResult = pExecutionResult
0202: .initTestResultStatusInModel(pTest, status,
0203: orderInCamp, null);
0204: pExecutionResult.addExecTestResultInDB(pTest);
0205:
0206: if (pExecutionTestResult instanceof ManualExecutionResult) {
0207: //ExecutionActionWrapper pExecutionActionWrapper = pResTest.getActionResult();
0208: ExecutionActionWrapper[] tmpArray = pResTest
0209: .getActionResult();
0210: Vector actionsResult = new Vector();
0211: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0212: actionsResult.add(tmpArray[tmpI]);
0213: }
0214: ArrayList actionListInModel = ((ManualTest) pTest)
0215: .getActionListFromModel(false);
0216: for (int n = 0; n < actionListInModel.size(); n++) {
0217: Action pAction = (Action) actionListInModel
0218: .get(n);
0219: if (!status.equals(ApiConstants.SUCCESS)
0220: && onlySucces) {
0221: pExecutionResult
0222: .initActionStatus(
0223: pAction,
0224: (ManualExecutionResult) pExecutionTestResult,
0225: actionsResult);
0226: } else {
0227: pExecutionResult
0228: .setActionStatus(
0229: pAction,
0230: (ManualExecutionResult) pExecutionTestResult,
0231: actionsResult);
0232: }
0233: pExecutionResult.addExecActionResultInDB(
0234: pTest, pAction);
0235: }
0236: }
0237: //Attachement
0238: if ((!status.equals(ApiConstants.SUCCESS) && !onlySucces)
0239: || status.equals(ApiConstants.SUCCESS)) {
0240: Collection col = getExecutionTestResultFromModel(
0241: pTest).getAttachmentMapFromModel()
0242: .values();
0243: for (Iterator iterator = col.iterator(); iterator
0244: .hasNext();) {
0245: Attachment attachToTest = (Attachment) iterator
0246: .next();
0247: if (attachToTest instanceof UrlAttachment) {
0248: UrlAttachment pUrlAttachment = new UrlAttachment(
0249: attachToTest.name,
0250: attachToTest.description);
0251: pUrlAttachment
0252: .setUrl(((UrlAttachment) attachToTest)
0253: .getUrl());
0254: pExecutionResult
0255: .addAttachUrlForExecTestInDB(
0256: pTest.getIdBdd(),
0257: pUrlAttachment);
0258: } else {
0259: File f = ((FileAttachment) attachToTest)
0260: .getFileFromDB();
0261: FileAttachment pFileAttachment = new FileAttachment(
0262: f, attachToTest.description);
0263: pExecutionResult
0264: .addAttachFileForExecTestInDB(
0265: pTest.getIdBdd(),
0266: pFileAttachment);
0267: }
0268: }
0269: }
0270: }
0271: }
0272:
0273: //Attachement
0274: Collection col = getAttachmentMapFromModel().values();
0275: for (Iterator iterAttach = col.iterator(); iterAttach
0276: .hasNext();) {
0277: Attachment attachToExecRes = (Attachment) iterAttach
0278: .next();
0279: if (attachToExecRes instanceof UrlAttachment) {
0280: UrlAttachment pUrlAttachment = new UrlAttachment(
0281: attachToExecRes.name,
0282: attachToExecRes.description);
0283: pUrlAttachment
0284: .setUrl(((UrlAttachment) attachToExecRes)
0285: .getUrl());
0286: pExecutionResult.addAttachementInDB(pUrlAttachment);
0287: } else {
0288: File f = ((FileAttachment) attachToExecRes)
0289: .getFileFromDB();
0290: FileAttachment pFileAttachment = new FileAttachment(
0291: f, attachToExecRes.description);
0292: pExecutionResult
0293: .addAttachementInDB(pFileAttachment);
0294: }
0295: }
0296:
0297: //Si aucun test en echec et status == FAIT --> changer le status
0298: if (nbNotSucces == 0) {
0299: pExecutionResult
0300: .setExecutionStatusInModel(ApiConstants.FINISHED);
0301: }
0302: pExecutionResult.updateInDB(pExecution, pUser);
0303: pExecutionResult.setNumberOfSuccessInModel(nbSucces);
0304: if (!onlySucces) {
0305: pExecutionResult.setNumberOfFailInModel(nbFail);
0306: pExecutionResult
0307: .setNumberOfUnknowInModel(nbInconclusif);
0308: }
0309: pExecution.addExecutionResultInModel(pExecutionResult);
0310: Api.commitTrans(transNuber);
0311: } catch (Exception e) {
0312: Api.forceRollBackTrans(transNuber);
0313: }
0314: return pExecutionResult;
0315: }
0316:
0317: protected void reloadBaseFromDB() throws Exception {
0318: if (!isInBase()) {
0319: throw new Exception("ExecutionResult " + name
0320: + " is not in BDD");
0321: }
0322: ExecutionResultWrapper pExecRes = pISQLExecutionResult
0323: .getWrapper(idBdd);
0324: name = pExecRes.getName();
0325: description = pExecRes.getDescription();
0326: statTab[0] = pExecRes.getNumberOfSuccess();
0327: statTab[1] = pExecRes.getNumberOfFail();
0328: statTab[2] = pExecRes.getNumberOfUnknow();
0329: testerLogin = pExecRes.getTester();
0330: time = new Time(pExecRes.getTime());
0331: executionDate = pExecRes.getExecutionDate();
0332: status = pExecRes.getExecutionStatus();
0333: }
0334:
0335: public void reloadFromDB(boolean base) throws Exception {
0336: int transNuber = -1;
0337: try {
0338: transNuber = Api.beginTransaction(10, ApiConstants.LOADING);
0339: if (base) {
0340: reloadBaseFromDB();
0341: }
0342: if (!DataLoader.isDynamic) {
0343: reloadTestResult();
0344: }
0345: reloadAttachmentDataFromDB(false);
0346: Api.commitTrans(transNuber);
0347: } catch (Exception e) {
0348: Api.forceRollBackTrans(transNuber);
0349: e.printStackTrace();
0350: }
0351: }
0352:
0353: int getTestInModel(int id, ArrayList testInCampaign) {
0354: for (int i = 0; i < testInCampaign.size(); i++) {
0355: Test testOfCampaignForStatus = (Test) testInCampaign.get(i);
0356: if (testOfCampaignForStatus.getIdBdd() == id) {
0357: return i;
0358: }
0359: }
0360: return -1;
0361: }
0362:
0363: void setActionStatus(Action pAction,
0364: ManualExecutionResult pManualExecutionResult,
0365: Vector actionsResult) {
0366: for (int i = 0; i < actionsResult.size(); i++) {
0367: ExecutionActionWrapper pExecutionActionWrapper = (ExecutionActionWrapper) actionsResult
0368: .elementAt(i);
0369: if (pExecutionActionWrapper.getIdAction() == pAction
0370: .getIdBdd()) {
0371: pManualExecutionResult.addStatusForActionInModel(
0372: pAction, pExecutionActionWrapper.getResult());
0373: pManualExecutionResult.addEffectivResultInModel(
0374: pAction, pExecutionActionWrapper
0375: .getEffectivResult());
0376: pManualExecutionResult.addDescriptionResultInModel(
0377: pAction, pExecutionActionWrapper
0378: .getDescription());
0379: pManualExecutionResult.addAwaitedResultInModel(pAction,
0380: pExecutionActionWrapper.getAwaitedResult());
0381: }
0382: }
0383: }
0384:
0385: void initActionStatus(Action pAction,
0386: ManualExecutionResult pManualExecutionResult,
0387: Vector actionsResult) {
0388: for (int i = 0; i < actionsResult.size(); i++) {
0389: ExecutionActionWrapper pExecutionActionWrapper = (ExecutionActionWrapper) actionsResult
0390: .elementAt(i);
0391: if (pExecutionActionWrapper.getIdAction() == pAction
0392: .getIdBdd()) {
0393: pManualExecutionResult.addStatusForActionInModel(
0394: pAction, "");
0395: pManualExecutionResult.addEffectivResultInModel(
0396: pAction, "");
0397: pManualExecutionResult.addDescriptionResultInModel(
0398: pAction, pExecutionActionWrapper
0399: .getDescription());
0400: pManualExecutionResult.addAwaitedResultInModel(pAction,
0401: pExecutionActionWrapper.getAwaitedResult());
0402: }
0403: }
0404: }
0405:
0406: public void reloadTestResult() throws Exception {
0407: if (!isInBase()) {
0408: throw new Exception("ExecutionResult " + name
0409: + " is not in BDD");
0410: }
0411: if (pExecution == null) {
0412: throw new Exception(
0413: "[ExecutionResult->reloadTestResult] No test in the campaign are given");
0414: }
0415:
0416: Collection testResults = testsResultMap.values();
0417: for (Iterator iter = testResults.iterator(); iter.hasNext();) {
0418: ExecutionTestResult testRes = (ExecutionTestResult) iter
0419: .next();
0420: testRes.deleteInModel();
0421: }
0422: testsResultMap.clear();
0423: resultLoaded = true;
0424: /*
0425: statTab[0] = 0;
0426: statTab[1] = 0;
0427: statTab[2] = 0;
0428: */
0429: int nbSuc = 0;
0430: int nbFail = 0;
0431: int nbUnk = 0;
0432: ArrayList testInCampaign = pExecution.getCampagneFromModel()
0433: .getTestListFromModel();
0434: ExecutionResultTestWrapper[] listOfResExecTest = pISQLExecutionResult
0435: .getExecutionResultTestWrapper(idBdd);
0436: for (int i = 0; i < listOfResExecTest.length; i++) {
0437: ExecutionResultTestWrapper pResTest = listOfResExecTest[i];
0438: int orderInCamp = getTestInModel(pResTest.getExcutedTest()
0439: .getIdBDD(), testInCampaign);
0440: if (orderInCamp == -1) {
0441: // AIE QUE FAIRE
0442: throw new Exception(
0443: "[ExecutionResult->reloadTestResult] No test in the campaign model are given for "
0444: + pResTest.getExcutedTest().getIdBDD()
0445: + ", name ="
0446: + pResTest.getExcutedTest().getName());
0447: } else {
0448: Test pTest = (Test) testInCampaign.get(orderInCamp);
0449: String status = pResTest.getStatus();
0450: if (status.equals(ApiConstants.SUCCESS)) {
0451: //addSuccessInModel(1);
0452: nbSuc++;
0453: } else if (status.equals(ApiConstants.FAIL)) {
0454: //addFailInModel(1);
0455: nbFail++;
0456: } else if (status.equals(ApiConstants.UNKNOWN)) {
0457: //addUnknowInModel(1);
0458: nbUnk++;
0459: }
0460: ExecutionTestResult pExecutionTestResult = initTestResultStatusInModel(
0461: pTest, status, orderInCamp, null);
0462: pExecutionTestResult.setIdBdd(pResTest.getIdBDD());
0463: if (pExecutionTestResult instanceof ManualExecutionResult) {
0464: //ExecutionActionWrapper pExecutionActionWrapper = pResTest.getActionResult();
0465: ExecutionActionWrapper[] tmpArray = pResTest
0466: .getActionResult();
0467: Vector actionsResult = new Vector();
0468: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
0469: actionsResult.add(tmpArray[tmpI]);
0470: }
0471: ArrayList actionListInModel = ((ManualTest) pTest)
0472: .getActionListFromModel(false);
0473: for (int n = 0; n < actionListInModel.size(); n++) {
0474: Action pAction = (Action) actionListInModel
0475: .get(n);
0476: setActionStatus(
0477: pAction,
0478: (ManualExecutionResult) pExecutionTestResult,
0479: actionsResult);
0480: }
0481: }
0482: pExecutionTestResult.reloadAttachmentDataFromDB(false);
0483: statTab[0] = 0;
0484: statTab[1] = 0;
0485: statTab[2] = 0;
0486: addSuccessInModel(nbSuc);
0487: addFailInModel(nbFail);
0488: addSuccessInModel(nbUnk);
0489: }
0490:
0491: }
0492: }
0493:
0494: /******************************************************************************/
0495: /** ACCESSEURS ET MUTATEURS ***/
0496: /******************************************************************************/
0497: protected void loadTestReult() {
0498: if (resultLoaded) {
0499: correctOrder(false);
0500: return;
0501: }
0502: int transNuber = -1;
0503: try {
0504: transNuber = Api.beginTransaction(10, ApiConstants.LOADING);
0505: if (!resultLoaded) {
0506: Util
0507: .log("[ExecutionResult->loadTestReult] for "
0508: + name);
0509: reloadTestResult();
0510: }
0511: resultLoaded = true;
0512: Api.commitTrans(transNuber);
0513: } catch (Exception e) {
0514: Api.forceRollBackTrans(transNuber);
0515: }
0516: correctOrder(true);
0517: }
0518:
0519: private void correctOrder(boolean inBase) {
0520: ArrayList<ExecutionTestResult> testResList = new ArrayList<ExecutionTestResult>();
0521: Collection pExecutionTestResultList = testsResultMap.values();
0522: for (Iterator iter = pExecutionTestResultList.iterator(); iter
0523: .hasNext();) {
0524: ExecutionTestResult pExecutionTestResult = (ExecutionTestResult) iter
0525: .next();
0526: testResList.add(pExecutionTestResult);
0527: }
0528: Collections.sort(testResList, new ComparateurTestExec());
0529: int size = testResList.size();
0530: for (int i = 0; i < size; i++) {
0531: ExecutionTestResult pExecutionTestResult = testResList
0532: .get(i);
0533: pExecutionTestResult.setOrderInModel(i);
0534: if (inBase) {
0535: /*@TODO*/
0536: }
0537: }
0538: }
0539:
0540: class ComparateurTestExec implements Comparator {
0541: public int compare(Object poTestRes1, Object poTestRes2) {
0542: ExecutionTestResult pExecutionTestResult1 = (ExecutionTestResult) poTestRes1;
0543: ExecutionTestResult pExecutionTestResult12 = (ExecutionTestResult) poTestRes2;
0544: if (pExecutionTestResult1.getOderFromModel() > pExecutionTestResult12
0545: .getOderFromModel()) {
0546: return 1;
0547: } else {
0548: return -1;
0549: }
0550: }
0551: }
0552:
0553: public Execution getExecution() {
0554: return pExecution;
0555: }
0556:
0557: public Date getExecutionDateFromModel() {
0558: return executionDate;
0559: }
0560:
0561: public HashMap getTestsResultMapFromModel() {
0562: loadTestReult();
0563: return testsResultMap;
0564: }
0565:
0566: public String getExecutionStatusFromModel() {
0567: return status;
0568: }
0569:
0570: public String getTesterFromModel() {
0571: return testerLogin;
0572: }
0573:
0574: public void setExecutionDateInModel(Date date) {
0575: executionDate = date;
0576: }
0577:
0578: public void setExecutionStatusInModel(String string) {
0579: status = string;
0580: }
0581:
0582: public void setTesterInModel(String user) {
0583: testerLogin = user;
0584: }
0585:
0586: public void setNumberOfSuccessInModel(int nb) {
0587: statTab[0] = nb;
0588: }
0589:
0590: public void addSuccessInModel(int nb) {
0591: statTab[0] = statTab[0] + nb;
0592: }
0593:
0594: public void setNumberOfFailInModel(int nb) {
0595: statTab[1] = nb;
0596: }
0597:
0598: public void addFailInModel(int nb) {
0599: statTab[1] = statTab[1] + nb;
0600: }
0601:
0602: public void setNumberOfUnknowInModel(int nb) {
0603: statTab[2] = nb;
0604: }
0605:
0606: public void addUnknowInModel(int nb) {
0607: statTab[2] = statTab[2] + nb;
0608: }
0609:
0610: public int[] getStatFromModel() {
0611: return statTab;
0612: }
0613:
0614: public int getNbOfTestWithStat() {
0615: return statTab[0] + statTab[1] + statTab[2];
0616: }
0617:
0618: public String getFormatedStatFromModel(String initialPass,
0619: String initialFail, String initilalIncon) {
0620: int nbTest = pExecution.getCampagneFromModel()
0621: .getTestListFromModel().size();
0622: //int nbTest = testsResultMap.size() ;
0623: //loadTestReult();
0624: String stat = "[" + statTab[0] + initialPass + ", "
0625: + statTab[1] + initialFail + ", " + statTab[2]
0626: + initilalIncon + "] / " + nbTest + " tests";
0627: return stat;
0628: //return "[" + statTab[0] + initialPass+ ", " + statTab[1] + initialFail +", " + statTab[2] + initilalIncon + "] / " + nbTest + " tests";
0629: }
0630:
0631: public Time getTimeFromModel() {
0632: return time;
0633: }
0634:
0635: public void setTimeInModel(Time time) {
0636: this .time = time;
0637: }
0638:
0639: ExecutionTestResult makeExecutionTestResult(Test test, String status) {
0640: ExecutionTestResult executionTestResult;
0641: if (test instanceof ManualTest) {
0642: executionTestResult = new ManualExecutionResult(
0643: (ManualTest) test, status);
0644: } else {
0645: executionTestResult = new ExecutionTestResult(test, status);
0646: }
0647: return executionTestResult;
0648: }
0649:
0650: /**
0651: * Ajoute un statut pour un test. Si le test est déja dans la table, son
0652: * statut est remplacé.
0653: * @param test un test
0654: * @param status son statut (SUCCESS, FAIL, UNKNOWN)
0655: */
0656: public ExecutionTestResult initTestResultStatusInModel(Test test,
0657: String status, int i, Campaign c) {
0658: loadTestReult();
0659:
0660: ExecutionTestResult executionTestResult = makeExecutionTestResult(
0661: test, status);
0662:
0663: int order;
0664: if (c != null) {
0665: order = c.getTestOrderInModel(test);
0666: } else {
0667: order = i;
0668: }
0669: Util.log("[ExecutionTestResult->initTestResultStatusInModel]"
0670: + executionTestResult.getTestFromModel()
0671: .getNameFromModel() + " set order " + order);
0672: executionTestResult.setOrderInModel(order);
0673: testsResultMap.put(test, executionTestResult);
0674: return executionTestResult;
0675:
0676: }
0677:
0678: /**
0679: * Ajoute un statut pour un test. Si le test est déjà dans la table, son
0680: * statut est remplacé.
0681: * @param test un test
0682: * @param status son statut (SUCCESS, FAIL, UNKNOWN)
0683: */
0684: public ExecutionTestResult addTestResultStatusInModel(Test test,
0685: String status) {
0686: loadTestReult();
0687:
0688: ExecutionTestResult pExecutionTestResult;
0689: if (testsResultMap.get(test) == null) {
0690: //ExecutionTestResult
0691: pExecutionTestResult = makeExecutionTestResult(test, status);
0692: testsResultMap.put(test, pExecutionTestResult);
0693: } else {
0694: pExecutionTestResult = (ExecutionTestResult) testsResultMap
0695: .get(test);
0696: pExecutionTestResult.setStatusInModel(status);
0697: }
0698: return pExecutionTestResult;
0699: }
0700:
0701: /**
0702: * Ajoute un statut pour un test. Si le test est déjà dans la table, son
0703: * statut est remplacé.
0704: * @param test un test
0705: * @param execTestResult un objet r?sultat d'ex?cution
0706: */
0707: public void setTestExecutionTestResultInModel(Test test,
0708: ExecutionTestResult execTestResult, int i) {
0709: loadTestReult();
0710:
0711: testsResultMap.put(test, execTestResult);
0712: execTestResult.setOrderInModel(i);
0713: //Util.log("!!-->!! " + test.getNameFromModel() + " set order " + i);
0714: }
0715:
0716: /*public ExecutionTestResult getExecutionTestResultFromModel(Test test) {
0717: if (!resultLoaded){
0718: loadTestReult();
0719: }
0720: return (ExecutionTestResult)testsResultMap.get(test);
0721: }*/
0722:
0723: public ExecutionTestResult getExecutionTestResultFromModel(Test test) {
0724: loadTestReult();
0725: return (ExecutionTestResult) testsResultMap.get(test);
0726: }
0727:
0728: /**
0729: * Retourne le statut du test
0730: * @param test
0731: * @return
0732: */
0733: public String getTestResultStatusFromModel(Test test) {
0734: loadTestReult();
0735: return ((ExecutionTestResult) testsResultMap.get(test))
0736: .getStatusFromModel();
0737: }
0738:
0739: public boolean allTestsHaveStatusInModel() {
0740: boolean resul = true;
0741: /*if (!resultLoaded){
0742: loadTestReult();
0743: }*/
0744: Set keysSet = testsResultMap.keySet();
0745: for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
0746: Test test = (Test) iter.next();
0747: if (getTestResultStatusFromModel(test) == null
0748: || getTestResultStatusFromModel(test).equals("")) {
0749: resul = false;
0750: } else if (getTestResultStatusFromModel(test).equals(
0751: ApiConstants.SUCCESS)) {
0752: addSuccessInModel(1);
0753: } else if (getTestResultStatusFromModel(test).equals(
0754: ApiConstants.FAIL)) {
0755: addFailInModel(1);
0756: } else if (getTestResultStatusFromModel(test).equals(
0757: ApiConstants.UNKNOWN)) {
0758: addUnknowInModel(1);
0759: }
0760: }
0761: return resul;
0762: }
0763:
0764: public void addTestResultAttachMapInModel(Test test,
0765: HashMap attachMap) {
0766: loadTestReult();
0767:
0768: ExecutionTestResult execTestResult = (ExecutionTestResult) testsResultMap
0769: .get(test);
0770: execTestResult.setAttachmentMapInModel(attachMap);
0771: }
0772:
0773: public Test[] getTestOrderedFromModel() {
0774: loadTestReult();
0775:
0776: Test[] ptabTest = new Test[testsResultMap.size()];
0777: Collection pExecutionTestResultList = testsResultMap.values();
0778: for (Iterator iter = pExecutionTestResultList.iterator(); iter
0779: .hasNext();) {
0780: ExecutionTestResult pExecutionTestResult = (ExecutionTestResult) iter
0781: .next();
0782: //Util.log(pExecutionTestResult.getTestFromModel().getNameFromModel() + " order " + pExecutionTestResult.getOderFromModel());
0783: ptabTest[pExecutionTestResult.getOderFromModel()] = pExecutionTestResult
0784: .getTestFromModel();
0785: }
0786: return ptabTest;
0787: }
0788:
0789: /*public void setTestsResultMap(HashMap map) {
0790: testsResultMap = map;
0791: }*/
0792:
0793: public void removeTestResult(Test test) {
0794: loadTestReult();
0795:
0796: ExecutionTestResult testExec = (ExecutionTestResult) testsResultMap
0797: .get(test);
0798: if (testExec == null) {
0799: return;
0800: }
0801: int order = testExec.getOderFromModel();
0802:
0803: Collection testResults = testsResultMap.values();
0804: for (Iterator iter = testResults.iterator(); iter.hasNext();) {
0805: ExecutionTestResult testRes = (ExecutionTestResult) iter
0806: .next();
0807: if (testRes.getOderFromModel() > order)
0808: testRes.setOrderInModel(testRes.getOderFromModel() - 1);
0809: }
0810:
0811: String status = testExec.getStatusFromModel();
0812: if (status.equals(ApiConstants.SUCCESS)) {
0813: statTab[0]--;
0814: } else if (status.equals(ApiConstants.FAIL)) {
0815: statTab[1]--;
0816: } else if (status.equals(ApiConstants.UNKNOWN)) {
0817: statTab[2]--;
0818: }
0819:
0820: testsResultMap.remove(test);
0821: }
0822:
0823: /*public Attachment getTestResultAttachment(Test test, String attachName) {
0824: ExecutionTestResult execTestResult = (ExecutionTestResult)testsResultMap.get(test);
0825: return execTestResult.getAttachmentFromModel(attachName);
0826: }*/
0827:
0828: void addInDB(Execution execCamp, User pUser) throws Exception {
0829: if (isInBase()) {
0830: throw new Exception("ExecutionResult " + name
0831: + " already in BDD");
0832: }
0833: if (execCamp.getIdBdd() == -1) {
0834: throw new Exception("Execution " + name + " is not in BDD");
0835: }
0836: if (pUser.getIdBdd() == -1) {
0837: throw new Exception("User " + name + " is not in BDD");
0838: }
0839: getUniqueName(execCamp.getIdBdd());
0840: idBdd = pISQLExecutionResult.insert(execCamp.getIdBdd(), name,
0841: description, "FAIT", status, pUser.getIdBdd());
0842: Project.pCurrentProject.notifyChanged(
0843: ApiConstants.INSERT_EXECUTION_RESULT, this );
0844: }
0845:
0846: public void updateInDB(Execution execCamp, User pUser)
0847: throws Exception {
0848: if (!isInBase()) {
0849: throw new Exception("ExecutionResult " + name
0850: + " is not in BDD");
0851: }
0852: if (pUser.getIdBdd() == -1) {
0853: throw new Exception("User " + name + " is not in BDD");
0854: }
0855: pISQLExecutionResult.update(idBdd, description, "FAIT", status,
0856: pUser.getIdBdd());
0857: Project.pCurrentProject.notifyChanged(
0858: ApiConstants.UPDATE_EXECUTION_RESULT, this );
0859: }
0860:
0861: public void addExecTestResultInDB(Test test) throws Exception {
0862: getExecutionTestResultFromModel(test).addInDB(idBdd,
0863: test.getIdBdd());
0864: }
0865:
0866: public void updateExecTestResultInDB(Test test) throws Exception {
0867: getExecutionTestResultFromModel(test).updateInDB();
0868: }
0869:
0870: public void addExecActionResultInDB(Test test, Action action)
0871: throws Exception {
0872: if (!isInBase()) {
0873: throw new Exception("ExecutionResult " + name
0874: + " is not in BDD");
0875: }
0876: ((ManualExecutionResult) getExecutionTestResultFromModel(test))
0877: .addActionResultInDB(action);
0878: }
0879:
0880: public void updateInDBAndModel(String newName, String newDesc)
0881: throws Exception {
0882: throw new Exception("NOT IMPLEMENTED");
0883: }
0884:
0885: /*public void updateEffectiveResForActionInDB(int testId, Action action, String effective) throws Exception {
0886: if (!isInBase()) {
0887: throw new Exception("ExecutionResult " + name + " is not in BDD");
0888: }
0889: pISQLExecutionActionResult.update(idBdd, testId, action.getIdBdd(), effective);
0890: }*/
0891:
0892: public void updateEffectiveResForActionInDB(Test test, Action action)
0893: throws Exception {
0894: if (!isInBase()) {
0895: throw new Exception("ExecutionResult " + name
0896: + " is not in BDD");
0897: }
0898: ((ManualExecutionResult) getExecutionTestResultFromModel(test))
0899: .updateActionEffectiveResInDB(action);
0900: }
0901:
0902: /* call from Execution */
0903: void deleteInDB() throws Exception {
0904: if (!isInBase()) {
0905: throw new Exception("ExecutionResult " + name
0906: + " is not in BDD");
0907: }
0908: pISQLExecutionResult.delete(idBdd);
0909: Project.pCurrentProject.notifyChanged(
0910: ApiConstants.DELETE_EXECUTION_RESULT, this );
0911:
0912: }
0913:
0914: /* call from Execution */
0915: void deleteInModel() {
0916: clearAttachInModel();
0917: Collection testResults = testsResultMap.values();
0918: for (Iterator iter = testResults.iterator(); iter.hasNext();) {
0919: ExecutionTestResult testRes = (ExecutionTestResult) iter
0920: .next();
0921: testRes.deleteInModel();
0922: Project.pCurrentProject.notifyChanged(
0923: ApiConstants.DELETE_EXECUTION_TEST_RESULT, testRes);
0924: }
0925: testsResultMap.clear();
0926: }
0927:
0928: /* call from Execution */
0929: void deleteInDBAndModel() throws Exception {
0930: deleteInDB();
0931: deleteInModel();
0932: }
0933:
0934: ///////////////////// Attachement ///////////////////////
0935:
0936: public void addAttachementInDB(Attachment attach) throws Exception {
0937: if (attach instanceof FileAttachment) {
0938: addAttachFileInDB((FileAttachment) attach);
0939: } else {
0940: addAttachUrlInDB((UrlAttachment) attach);
0941: }
0942: }
0943:
0944: void addAttachFileInDB(FileAttachment file) throws Exception {
0945: if (!isInBase()) {
0946: throw new Exception("ExecutionResult " + name
0947: + " is not in BDD");
0948: }
0949: File f = file.getLocalFile();
0950: int id = pISQLExecutionResult.addAttachFile(idBdd,
0951: new SalomeFileWrapper(f), file
0952: .getDescriptionFromModel());
0953: file.setIdBdd(id);
0954: }
0955:
0956: void addAttachUrlInDB(UrlAttachment url) throws Exception {
0957: if (!isInBase()) {
0958: throw new Exception("ExecutionResult " + name
0959: + " is not in BDD");
0960: }
0961: int id = pISQLExecutionResult.addAttachUrl(idBdd, url
0962: .getNameFromModel(), url.getDescriptionFromModel());
0963: url.setIdBdd(id);
0964: }
0965:
0966: public void addAttachFileForExecTestInDB(Test test,
0967: FileAttachment file) throws Exception {
0968: getExecutionTestResultFromModel(test).addAttachFileInDB(file);
0969: }
0970:
0971: public void addAttachFileForExecTestInDB(int idTest,
0972: FileAttachment file) throws Exception {
0973: if (!isInBase()) {
0974: throw new Exception("ExecutionResult " + name
0975: + " is not in BDD");
0976: }
0977: File f = file.getLocalFile();
0978: int id = pISQLExecutionTestResult.addAttachFile(idBdd, idTest,
0979: new SalomeFileWrapper(f), file
0980: .getDescriptionFromModel());
0981: file.setIdBdd(id);
0982: }
0983:
0984: public void addAttachUrlForExecTestInDB(Test test, UrlAttachment url)
0985: throws Exception {
0986: getExecutionTestResultFromModel(test).addAttachUrlInDB(url);
0987: }
0988:
0989: public void addAttachUrlForExecTestInDB(int idTest,
0990: UrlAttachment url) throws Exception {
0991: if (!isInBase()) {
0992: throw new Exception("ExecutionResult " + name
0993: + " is not in BDD");
0994: }
0995: int id = pISQLExecutionTestResult.addAttachUrl(idBdd, idTest,
0996: url.getNameFromModel(), url.getDescriptionFromModel());
0997: ;
0998: url.setIdBdd(id);
0999: }
1000:
1001: public void deleteAttachementInDB(int idAttach) throws Exception {
1002: if (!isInBase()) {
1003: throw new Exception("ExecutionResult " + name
1004: + " is not in BDD");
1005: }
1006: pISQLExecutionResult.deleteAttach(idBdd, idAttach);
1007:
1008: }
1009:
1010: public void deleteAttachementInDBAndModel(Attachment attach)
1011: throws Exception {
1012: deleteAttachementInDB(attach.getIdBdd());
1013: deleteAttachmentInModel(attach);
1014: }
1015:
1016: public void deleteAttachFromExecResultInDB(int idTest, int idAttach)
1017: throws Exception {
1018: if (!isInBase()) {
1019: throw new Exception("ExecutionResult " + name
1020: + " is not in BDD");
1021: }
1022: pISQLExecutionTestResult.deleteAttach(idBdd, idTest, idAttach);
1023: }
1024:
1025: public void deleteAttachFromExecResultInModel(Test test,
1026: Attachment attach) {
1027: getExecutionTestResultFromModel(test).deleteAttachmentInModel(
1028: attach);
1029: }
1030:
1031: public void deleteAttachFromExecResultInDBModel(Test test,
1032: Attachment attach) throws Exception {
1033: deleteAttachFromExecResultInDB(test.getIdBdd(), attach
1034: .getIdBdd());
1035: deleteAttachFromExecResultInModel(test, attach);
1036: }
1037:
1038: public Vector getAttachFilesFromDB() throws Exception {
1039: if (!isInBase()) {
1040: throw new Exception("ExecutionResult " + name
1041: + " is not in BDD");
1042: }
1043: FileAttachementWrapper[] tmpArray = pISQLExecutionResult
1044: .getAttachFiles(idBdd);
1045: Vector tmpVector = new Vector();
1046: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
1047: tmpVector.add(tmpArray[tmpI]);
1048: }
1049: return tmpVector;
1050: }
1051:
1052: public Vector getAttachUrlsFromDB() throws Exception {
1053: if (!isInBase()) {
1054: throw new Exception("ExecutionResult " + name
1055: + " is not in BDD");
1056: }
1057: UrlAttachementWrapper[] tmpArray = pISQLExecutionResult
1058: .getAttachUrls(idBdd);
1059: Vector tmpVector = new Vector();
1060: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
1061: tmpVector.add(tmpArray[tmpI]);
1062: }
1063: return tmpVector;
1064: }
1065:
1066: public Vector getAttachFilesExecResultFromDB(int testId)
1067: throws Exception {
1068: if (!isInBase()) {
1069: throw new Exception("ExecutionResult " + name
1070: + " is not in BDD");
1071: }
1072: FileAttachementWrapper[] tmpArray = pISQLExecutionTestResult
1073: .getAttachFiles(idBdd, testId);
1074: Vector tmpVector = new Vector();
1075: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
1076: tmpVector.add(tmpArray[tmpI]);
1077: }
1078: return tmpVector;
1079: }
1080:
1081: public Vector getAttachUrlsExecResultFromDB(int testId)
1082: throws Exception {
1083: if (!isInBase()) {
1084: throw new Exception("ExecutionResult " + name
1085: + " is not in BDD");
1086: }
1087: UrlAttachementWrapper[] tmpArray = pISQLExecutionTestResult
1088: .getAttachUrls(idBdd, testId);
1089: Vector tmpVector = new Vector();
1090: for (int tmpI = 0; tmpI < tmpArray.length; tmpI++) {
1091: tmpVector.add(tmpArray[tmpI]);
1092: }
1093: return tmpVector;
1094: }
1095:
1096: public Vector getAllResExecTestAttachFromDB() throws Exception {
1097: if (!isInBase()) {
1098: throw new Exception("ExecutionResult " + name
1099: + " is not in BDD");
1100: }
1101: Vector res = new Vector();
1102: TestAttachmentWrapper[] tmpRes = pISQLExecutionResult
1103: .getAllAttachTestInExecutionResult(idBdd);
1104: for (int i = 0; i < tmpRes.length; i++) {
1105: Vector data = new Vector();
1106: TestAttachmentWrapper tmpdata = tmpRes[i];
1107: data.add(new Integer(tmpdata.getIdTest()));
1108: if (tmpdata.getFileAttachment() != null) {
1109: data
1110: .add(new FileAttachment(tmpdata
1111: .getFileAttachment()));
1112: } else if (tmpdata.getUrlAttachment() != null) {
1113: data.add(new UrlAttachment(tmpdata.getUrlAttachment()));
1114: }
1115: res.add(data);
1116: }
1117: return res;
1118: }
1119:
1120: /********************************************************************************/
1121: public void getUniqueName(int idExec) {
1122: int nb = 0;
1123: try {
1124: while (pISQLExecutionResult.getID(idExec, name) > 0) {
1125: name += "_" + nb;
1126: }
1127: } catch (Exception e) {
1128: }
1129: } // Fin de la méthode isInBase/1
1130:
1131: public boolean existeInBase() throws Exception {
1132: if (!isInBase()) {
1133: return false;
1134: }
1135: return pISQLExecutionResult.getID(pExecution.getIdBdd(), name) == idBdd;
1136: }
1137:
1138: /******************* TRI ********************************************/
1139:
1140: }
|