1 /** 2 * 3 * Copyright 2005 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.geronimo.gbuild.report; 18 19 import java.util.Collection; 20 import java.util.Collections; 21 import java.util.Iterator; 22 import java.util.Set; 23 import java.util.SortedMap; 24 import java.util.TreeMap; 25 26 /** 27 * @version $Rev: 331903 $ $Date$ 28 */ 29 public class TestSuite { 30 private final String name; 31 private final SortedMap testCases; 32 private final long errorCount; 33 private final long failureCount; 34 private final long totalTime; 35 private final boolean newResult; 36 37 public TestSuite(String name, Set testCases) { 38 this.name = name; 39 40 long errorCount = 0; 41 long failureCount = 0; 42 long totalTime = 0; 43 boolean newResult = false; 44 SortedMap testCasesByName = new TreeMap(); 45 for (Iterator iterator = testCases.iterator(); iterator.hasNext();) { 46 TestCase testCase = (TestCase) iterator.next(); 47 if (testCase.isFailed()) { 48 failureCount++; 49 } else if (testCase.isError()) { 50 errorCount++; 51 } 52 totalTime += testCase.getTime(); 53 newResult = newResult || testCase.isNewResult(); 54 testCasesByName.put(testCase.getName(), testCase); 55 } 56 this.errorCount = errorCount; 57 this.failureCount = failureCount; 58 this.totalTime = totalTime; 59 this.newResult = newResult; 60 61 this.testCases = Collections.unmodifiableSortedMap(testCasesByName); 62 } 63 64 public String getName() { 65 return name; 66 } 67 68 public TestCase getTestCase(String name) { 69 return (TestCase) testCases.get(name); 70 } 71 72 public Collection getTestCases() { 73 return testCases.values(); 74 } 75 76 public Collection getItems() { 77 return testCases.values(); 78 } 79 80 public long getTestCount() { 81 return testCases.size(); 82 } 83 84 public long getPassCount() { 85 return testCases.size() - errorCount - failureCount; 86 } 87 88 public long getErrorCount() { 89 return errorCount; 90 } 91 92 public long getFailureCount() { 93 return failureCount; 94 } 95 96 public long getTotalTime() { 97 return totalTime; 98 } 99 100 public String getTotalTimeString() { 101 return ReportUtil.formatTime(getTotalTime()); 102 } 103 104 public boolean isPassed() { 105 return getTestCount() > 0 && failureCount == 0 && errorCount == 0; 106 } 107 108 public int getPassPercentage() { 109 if (testCases.isEmpty()) { 110 return 0; 111 } 112 return (int) ((0.0 + getPassCount()) * 100 / testCases.size()); 113 } 114 115 public int getPassBarSize() { 116 return getPassPercentage() * 2; 117 } 118 119 public int getFailBarSize() { 120 return 200 - getPassBarSize(); 121 } 122 123 public boolean isNewResult() { 124 return newResult; 125 } 126 }