< prev index next >

## src/com/sun/javatest/cof/COFTest.java

Print this page

      99 @XmlType(name = "Test", propOrder = {
     100 "name",
     101 "appuse",
     102 "status",
     103 "testcases",
     104 "starttime",
     105 "endtime",
     106 "attributes",
     107 "description"
     108 })*/
     109 public class COFTest extends COFItem {
     110
     111     private static final Date badDate = new Date(0);
     112     private static final String[] cofStatus = new String[Status.NUM_STATES];
     113     static long count = 0;
     114     private static DateFormat[] dateFormats;
     115     protected final static Pattern idPattern = Pattern.compile(".*[^\\w\\.\\[\\]\\(\\)\\{\\},_\\-]([\\w\\.\\[\\]\\(\\)\\{\\},_\\-]+)");
     116     static boolean noTestCases = false;
     117     protected final static Pattern testCasePattern = Pattern //.compile("^(\\S+): (Passed\\.|Failed\\.|Error\\.|Not\\ run\\.)(.*)");
     118             .compile("^(.*): (Passed\\.|Failed\\.|Error\\.|Not\\ run\\.)(.*)");
     119     static LinkedHashMap xmlAttributes;
     120     static LinkedHashMap xmlElements;
     121     static String xmlTagName;
     122
     123     static {
     124         xmlElements = new LinkedHashMap();
     125         xmlAttributes = new LinkedHashMap();
     126         xmlElements.put("name", "name");
     127         xmlElements.put("appuse", "appuse");
     128         xmlElements.put("status", "status");
     129         xmlElements.put("testcases", "testcases");
     130         xmlElements.put("starttime", "starttime");
     131         xmlElements.put("endtime", "endtime");
     132         xmlElements.put("attributes", "attributes");
     133         xmlElements.put("description", "description");
     134         //              xmlAttributes.put("analysis", "analysis");
     135         xmlAttributes.put("id", "id");
     136         xmlTagName = "test";
     137
     138         initDateFormats();
     139     }
     140
     141     static {
     142         cofStatus[Status.PASSED] = "pass";
     143         cofStatus[Status.FAILED] = "fail";
     144         cofStatus[Status.ERROR] = "error";
     145         cofStatus[Status.NOT_RUN] = "did_not_run";
     146     }
     147     //    @XmlAttribute
     148     protected String analysis;
     149     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema", required = true)
     150     protected List/*<String>*/ appuse;
     151     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema")
     152     protected COFTestAttributes attributes;
     153     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema")
     154     protected String description;
     155     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema", type = String.class)
     156     //    @XmlJavaTypeAdapter(Adapter1 .class)
     157     protected Date endtime;
     158     //    @XmlAttribute(required = true)
     159     protected String id;
     160     final long idNum = count++;
     161     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema", required = true)
     162     protected String name;
     163     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema", type = String.class)
     164     //    @XmlJavaTypeAdapter(Adapter1 .class)
     165     protected Date starttime;
     166     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema")
     167     protected COFStatus status;
     168     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema")
     169     protected COFTestCases testcases;
     170     private COFData cofData;
     246                     s = reader.readLine();
     247                 }
     248             } catch (ReloadFault e) {
     249                 // TODO Auto-generated catch block
     250                 e.printStackTrace();
     251             } catch (IOException e) {
     252                 // TODO Auto-generated catch block
     253                 e.printStackTrace();
     254             }
     255         }
     256     }
     257
     258     private void checkLostTestCases(TestResult tr) {
     259         MTL mtl = cofData.getMtl();
     260
     261         if (mtl == null) {
     262             // mtl is not specified
     263             return;
     264         }
     265
     266         List  /*<COFTestCase>*/ jtrCases = testcases.getTestcase();
     267         List  /*<String>*/ mtlTestCases = mtl.getTestCases(tr.getTestName());
     268         if (mtlTestCases != null && mtlTestCases.size() > 0) {
     269             // for (COFTestCase jtrCase : jtrCases) {
     270             Iterator it = jtrCases.iterator();
     271             while (it.hasNext()) {
     272                 COFTestCase jtrCase = (COFTestCase) it.next();
     273                 mtlTestCases.remove(jtrCase.name);
     274             }
     275             if (mtlTestCases.size() > 0) {
     276                 //for (String testCaseName : mtlTestCases) {
     277                 it = mtlTestCases.iterator();
     278                 while(it.hasNext()) {
     279                     String testCaseName = (String) it.next();
     280                     COFTestCase nTc = new COFTestCase();
     281                     COFStatus nStatus = new COFStatus();
     282                     nTc.setName(testCaseName);
     283                     String strS = cofStatus[tr.getStatus().getType()];
     284                     nStatus.setValue(strS);
     285                     //System.out.println("+ " + tr.getTestName() + " " + tcName + " " + strS );
     286                     testcases.getTestcase().add(testCaseName);
     287                 }
     288             }
     289         }
     290     }
     291
     292     /**
     293      * Gets the value of the analysis property.
     294      *
     295      * @return
     296      *     possible object is
     297      *     {@link String }
     298      *
     299      */
     300     public String getAnalysis() {
     301         if (analysis == null) {
     302             return "accept";
     303         } else {
     304             return analysis;
     305         }
     306     }
     310      *
     311      * <p>
     312      * This accessor method returns a reference to the live list,
     313      * not a snapshot. Therefore any modification you make to the
     314      * returned list will be present inside the JAXB object.
     315      * This is why there is not a <CODE>set</CODE> method for the appuse property.
     316      *
     317      * <p>
     318      * For example, to add a new item, do as follows:
     319      * <pre>
     320      *    getAppuse().add(newItem);
     321      * </pre>
     322      *
     323      *
     324      * <p>
     325      * Objects of the following type(s) are allowed in the list
     326      * {@link String }
     327      *
     328      *
     329      */
     330     public List/*<String>*/ getAppuse() {
     331         if (appuse == null) {
     332             appuse = new ArrayList/*<String>*/();
     333         }
     334         return this.appuse;
     335     }
     336
     337     /**
     338      * Gets the value of the attributes property.
     339      *
     340      * @return
     341      *     possible object is
     342      *     {@link COFTestAttributes }
     343      *
     344      */
     345     public COFTestAttributes getAttributes() {
     346         return attributes;
     347     }
     348
     349     /**
     350      * Gets the value of the description property.
     351      *
     352      * @return
     377      *     possible object is
     378      *     {@link String }
     379      *
     380      */
     381     public String getId() {
     382         if (id != null) {
     383             return id;
     384         }
     385         if (name == null) {
     386             throw new IllegalStateException("Name was not set.");
     387         }
     388         Matcher m = idPattern.matcher(name);
     389         if (m.matches()) {
     390             id = m.group(1) + ":" + idNum;
     391         } else {
     392             id = "test:" + idNum;
     393         }
     394         return id;
     395     }
     396
     397     LinkedHashMap getItemAttributes() {
     398         return xmlAttributes;
     399     }
     400
     401     LinkedHashMap getItemElements() {
     402         return xmlElements;
     403     }
     404
     405     String getItemTagName() {
     406         return xmlTagName;
     407     }
     408
     409     /**
     410      * Gets the value of the name property.
     411      *
     412      * @return
     413      *     possible object is
     414      *     {@link String }
     415      *
     416      */
     417     public String getName() {
     418         return name;
     419     }
     420
     421     /**
     449      *     possible object is
     450      *     {@link COFTestCases }
     451      *
     452      */
     453     public COFTestCases getTestcases() {
     454         return testcases;
     455     }
     456
     457     /**
     458      * Sets the value of the id property.
     459      *
     460      * @param value
     461      *     allowed object is
     462      *     {@link String }
     463      *
     464      */
     465     //  public void setId(String value) {
     466     //          this.id = value;
     467     //  }
     468     private static void initDateFormats() {
     469         Vector v = new Vector();
     470
     471         // generic Java default
     472         // 10-Sep-99 3:25:11 PM
     473         v.addElement(DateFormat.getDateTimeInstance());
     474
     475         // standard IETF date syntax
     476         // Fri, 10 September 1999 03:25:12 PDT
     477         v.addElement(new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss zzz"));
     478
     479         // Unix C time
     480         // Fri Sep 10 14:41:37 PDT 1999
     481         v.addElement(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"));
     482
     483         // XML time
     484         // 1999-09-10T03:25:12.123 (ISO 8601, sect 5.4)
     485         v.addElement(new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS"));
     486
     487         // allow user-specified format
     488         String s = System.getProperty("javatest.date.format");
     489         if (s != null) {
      99 @XmlType(name = "Test", propOrder = {
     100 "name",
     101 "appuse",
     102 "status",
     103 "testcases",
     104 "starttime",
     105 "endtime",
     106 "attributes",
     107 "description"
     108 })*/
     109 public class COFTest extends COFItem {
     110
     111     private static final Date badDate = new Date(0);
     112     private static final String[] cofStatus = new String[Status.NUM_STATES];
     113     static long count = 0;
     114     private static DateFormat[] dateFormats;
     115     protected final static Pattern idPattern = Pattern.compile(".*[^\\w\\.\\[\\]\\(\\)\\{\\},_\\-]([\\w\\.\\[\\]\\(\\)\\{\\},_\\-]+)");
     116     static boolean noTestCases = false;
     117     protected final static Pattern testCasePattern = Pattern //.compile("^(\\S+): (Passed\\.|Failed\\.|Error\\.|Not\\ run\\.)(.*)");
     118             .compile("^(.*): (Passed\\.|Failed\\.|Error\\.|Not\\ run\\.)(.*)");
     119     static LinkedHashMap<String, String> xmlAttributes;
     120     static LinkedHashMap<String, String> xmlElements;
     121     static String xmlTagName;
     122
     123     static {
     124         xmlElements = new LinkedHashMap<>();
     125         xmlAttributes = new LinkedHashMap<>();
     126         xmlElements.put("name", "name");
     127         xmlElements.put("appuse", "appuse");
     128         xmlElements.put("status", "status");
     129         xmlElements.put("testcases", "testcases");
     130         xmlElements.put("starttime", "starttime");
     131         xmlElements.put("endtime", "endtime");
     132         xmlElements.put("attributes", "attributes");
     133         xmlElements.put("description", "description");
     134         //              xmlAttributes.put("analysis", "analysis");
     135         xmlAttributes.put("id", "id");
     136         xmlTagName = "test";
     137
     138         initDateFormats();
     139     }
     140
     141     static {
     142         cofStatus[Status.PASSED] = "pass";
     143         cofStatus[Status.FAILED] = "fail";
     144         cofStatus[Status.ERROR] = "error";
     145         cofStatus[Status.NOT_RUN] = "did_not_run";
     146     }
     147     //    @XmlAttribute
     148     protected String analysis;
     149     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema", required = true)
     150     protected List<String> appuse;
     151     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema")
     152     protected COFTestAttributes attributes;
     153     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema")
     154     protected String description;
     155     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema", type = String.class)
     156     //    @XmlJavaTypeAdapter(Adapter1 .class)
     157     protected Date endtime;
     158     //    @XmlAttribute(required = true)
     159     protected String id;
     160     final long idNum = count++;
     161     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema", required = true)
     162     protected String name;
     163     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema", type = String.class)
     164     //    @XmlJavaTypeAdapter(Adapter1 .class)
     165     protected Date starttime;
     166     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema")
     167     protected COFStatus status;
     168     //    @XmlElement(namespace = "http://qare.sfbay.sun.com/projects/COF/2003/2_0_2/Schema")
     169     protected COFTestCases testcases;
     170     private COFData cofData;
     246                     s = reader.readLine();
     247                 }
     248             } catch (ReloadFault e) {
     249                 // TODO Auto-generated catch block
     250                 e.printStackTrace();
     251             } catch (IOException e) {
     252                 // TODO Auto-generated catch block
     253                 e.printStackTrace();
     254             }
     255         }
     256     }
     257
     258     private void checkLostTestCases(TestResult tr) {
     259         MTL mtl = cofData.getMtl();
     260
     261         if (mtl == null) {
     262             // mtl is not specified
     263             return;
     264         }
     265
     266         List  <COFTestCase> jtrCases = testcases.getTestcase();
     267         List  <String> mtlTestCases = mtl.getTestCases(tr.getTestName());
     268         if (mtlTestCases != null && mtlTestCases.size() > 0) {
     269             // for (COFTestCase jtrCase : jtrCases) {
     270             Iterator it = jtrCases.iterator();
     271             while (it.hasNext()) {
     272                 COFTestCase jtrCase = (COFTestCase) it.next();
     273                 mtlTestCases.remove(jtrCase.name);
     274             }
     275             if (mtlTestCases.size() > 0) {
     276                 //for (String testCaseName : mtlTestCases) {
     277                 it = mtlTestCases.iterator();
     278                 while(it.hasNext()) {
     279                     String testCaseName = (String) it.next();
     280                     COFTestCase nTc = new COFTestCase();
     281                     COFStatus nStatus = new COFStatus();
     282                     nTc.setName(testCaseName);
     283                     String strS = cofStatus[tr.getStatus().getType()];
     284                     nStatus.setValue(strS);
     285                     //System.out.println("+ " + tr.getTestName() + " " + tcName + " " + strS );
     286                     testcases.getTestcase().add(nTc);
     287                 }
     288             }
     289         }
     290     }
     291
     292     /**
     293      * Gets the value of the analysis property.
     294      *
     295      * @return
     296      *     possible object is
     297      *     {@link String }
     298      *
     299      */
     300     public String getAnalysis() {
     301         if (analysis == null) {
     302             return "accept";
     303         } else {
     304             return analysis;
     305         }
     306     }
     310      *
     311      * <p>
     312      * This accessor method returns a reference to the live list,
     313      * not a snapshot. Therefore any modification you make to the
     314      * returned list will be present inside the JAXB object.
     315      * This is why there is not a <CODE>set</CODE> method for the appuse property.
     316      *
     317      * <p>
     318      * For example, to add a new item, do as follows:
     319      * <pre>
     320      *    getAppuse().add(newItem);
     321      * </pre>
     322      *
     323      *
     324      * <p>
     325      * Objects of the following type(s) are allowed in the list
     326      * {@link String }
     327      *
     328      *
     329      */
     330     public List<String> getAppuse() {
     331         if (appuse == null) {
     332             appuse = new ArrayList<>();
     333         }
     334         return this.appuse;
     335     }
     336
     337     /**
     338      * Gets the value of the attributes property.
     339      *
     340      * @return
     341      *     possible object is
     342      *     {@link COFTestAttributes }
     343      *
     344      */
     345     public COFTestAttributes getAttributes() {
     346         return attributes;
     347     }
     348
     349     /**
     350      * Gets the value of the description property.
     351      *
     352      * @return
     377      *     possible object is
     378      *     {@link String }
     379      *
     380      */
     381     public String getId() {
     382         if (id != null) {
     383             return id;
     384         }
     385         if (name == null) {
     386             throw new IllegalStateException("Name was not set.");
     387         }
     388         Matcher m = idPattern.matcher(name);
     389         if (m.matches()) {
     390             id = m.group(1) + ":" + idNum;
     391         } else {
     392             id = "test:" + idNum;
     393         }
     394         return id;
     395     }
     396
     397     LinkedHashMap<String, String> getItemAttributes() {
     398         return xmlAttributes;
     399     }
     400
     401     LinkedHashMap<String, String> getItemElements() {
     402         return xmlElements;
     403     }
     404
     405     String getItemTagName() {
     406         return xmlTagName;
     407     }
     408
     409     /**
     410      * Gets the value of the name property.
     411      *
     412      * @return
     413      *     possible object is
     414      *     {@link String }
     415      *
     416      */
     417     public String getName() {
     418         return name;
     419     }
     420
     421     /**
     449      *     possible object is
     450      *     {@link COFTestCases }
     451      *
     452      */
     453     public COFTestCases getTestcases() {
     454         return testcases;
     455     }
     456
     457     /**
     458      * Sets the value of the id property.
     459      *
     460      * @param value
     461      *     allowed object is
     462      *     {@link String }
     463      *
     464      */
     465     //  public void setId(String value) {
     466     //          this.id = value;
     467     //  }
     468     private static void initDateFormats() {
     469         Vector<DateFormat> v = new Vector<>();
     470
     471         // generic Java default
     472         // 10-Sep-99 3:25:11 PM
     473         v.addElement(DateFormat.getDateTimeInstance());
     474
     475         // standard IETF date syntax
     476         // Fri, 10 September 1999 03:25:12 PDT
     477         v.addElement(new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss zzz"));
     478
     479         // Unix C time
     480         // Fri Sep 10 14:41:37 PDT 1999
     481         v.addElement(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"));
     482
     483         // XML time
     484         // 1999-09-10T03:25:12.123 (ISO 8601, sect 5.4)
     485         v.addElement(new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS"));
     486
     487         // allow user-specified format
     488         String s = System.getProperty("javatest.date.format");
     489         if (s != null) {

< prev index next >