1 18 package org.apache.batik.test; 19 20 import java.util.Iterator ; 21 import java.util.Vector ; 22 23 30 public class DefaultTestSuiteReport implements TestSuiteReport { 31 34 public static final String ERROR_CHILD_TEST_FAILED 35 = "DefaultTestSuiteReport.error.child.test.failed"; 36 37 40 public static final String ENTRY_KEY_FAILED_CHILD_TEST_REPORT 41 = "DefaultTestSuiteReport.entry.key.failed.child.test.report"; 42 43 46 public static final String ENTRY_KEY_PASSED_CHILD_TEST_REPORT 47 = "DefaultTestSuiteReport.entry.key.passed.child.test.report"; 48 49 52 protected Vector reports = new Vector (); 53 54 57 protected TestSuite testSuite; 58 59 62 protected Entry[] description = null; 63 64 67 protected TestSuiteReport parent; 68 69 72 private boolean passed = true; 73 74 public DefaultTestSuiteReport(TestSuite testSuite){ 75 if(testSuite == null){ 76 throw new IllegalArgumentException (); 77 } 78 79 this.testSuite = testSuite; 80 } 81 82 public Test getTest(){ 83 return testSuite; 84 } 85 86 public String getErrorCode(){ 87 if(hasPassed()){ 88 return null; 89 } 90 else{ 91 return ERROR_CHILD_TEST_FAILED; 92 } 93 } 94 95 public TestSuiteReport getParentReport(){ 96 return parent; 97 } 98 99 public void setParentReport(TestSuiteReport parent){ 100 this.parent = parent; 101 } 102 103 public boolean hasPassed(){ 104 Iterator iter = reports.iterator(); 105 106 boolean passed = true; 107 108 while(iter.hasNext()){ 109 TestReport childReport = (TestReport)iter.next(); 110 passed = passed && childReport.hasPassed(); 111 } 112 113 return passed; 114 } 115 116 public void addDescriptionEntry(String key, 117 Object value){ 118 addDescriptionEntry(new Entry(key, value)); 119 } 120 121 protected void addDescriptionEntry(Entry entry){ 122 if(description == null){ 123 description = new Entry[1]; 124 description[0] = entry; 125 } 126 else{ 127 Entry[] oldDescription = description; 128 description = new Entry[description.length + 1]; 129 System.arraycopy(oldDescription, 0, description, 0, 130 oldDescription.length); 131 description[oldDescription.length] = entry; 132 } 133 } 134 135 public Entry[] getDescription(){ 136 Iterator iter = reports.iterator(); 137 Vector descs = new Vector (); 138 139 while(iter.hasNext()){ 140 TestReport childReport = (TestReport)iter.next(); 141 if(!childReport.hasPassed()){ 142 TestReport.Entry entry 143 = new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_FAILED_CHILD_TEST_REPORT, null), 144 childReport); 145 descs.addElement(entry); 146 } 147 } 148 149 iter = reports.iterator(); 150 while(iter.hasNext()){ 151 TestReport childReport = (TestReport)iter.next(); 152 if(childReport.hasPassed()){ 153 TestReport.Entry entry 154 = new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_PASSED_CHILD_TEST_REPORT, null), 155 childReport); 156 descs.addElement(entry); 157 } 158 } 159 160 TestReport.Entry[] entries = null; 161 if(descs.size() > 0){ 162 entries = new TestReport.Entry[descs.size()]; 163 descs.copyInto(entries); 164 } 165 166 if(description != null){ 167 TestReport.Entry[] e = entries; 168 entries = new TestReport.Entry[e.length + description.length]; 169 System.arraycopy(e, 0, entries, 0, e.length); 170 System.arraycopy(description, 0, entries, e.length, description.length); 171 } 172 173 return entries; 174 } 175 176 public void addReport(TestReport report){ 177 if(report == null){ 178 throw new IllegalArgumentException (); 179 } 180 181 report.setParentReport(this); 182 reports.addElement(report); 183 } 184 185 186 public TestReport[] getChildrenReports(){ 187 int nReports = reports.size(); 188 TestReport[] r = new TestReport[nReports]; 189 reports.copyInto(r); 190 return r; 191 } 192 } 193 | Popular Tags |