1 18 package org.apache.batik.test; 19 20 47 public class TestReportValidator extends AbstractTest { 48 51 private Test test; 52 53 56 private boolean expectedStatus; 57 58 61 private String expectedErrorCode; 62 63 67 static final String ERROR_UNEXPECTED_TEST_STATUS 68 = "TestReportValidator.error.unexpected.test.status"; 69 70 74 static final String ERROR_UNEXPECTED_ERROR_CODE 75 = "TestReportValidator.error.unexpected.error.code"; 76 77 80 public static final String ENTRY_KEY_EXPECTED_ERROR_CODE 81 = "TestReportValidator.entry.key.expected.error.code"; 82 83 87 public static final String ENTRY_KEY_RECEIVED_ERROR_CODE 88 = "TestReportValidator.entry.key.received.error.code"; 89 90 94 public static final String ENTRY_KEY_EXPECTED_STATUS 95 = "TestReportValidator.entry.key.expected.status"; 96 97 101 public static final String ENTRY_KEY_RECEIVED_STATUS 102 = "TestReportValidator.entry.key.received.status"; 103 104 108 public TestReportValidator(Test test, 109 boolean expectedStatus, 110 String expectedErrorCode){ 111 setConfig(test, 112 expectedStatus, 113 expectedErrorCode); 114 } 115 116 119 protected TestReportValidator(){ 120 } 121 122 126 protected void setConfig(Test test, 127 boolean expectedStatus, 128 String expectedErrorCode){ 129 this.expectedErrorCode = expectedErrorCode; 130 this.test = test; 131 this.expectedStatus = expectedStatus; 132 } 133 134 public TestReport runImpl() throws Exception { 135 TestReport tr = test.run(); 136 137 DefaultTestReport r = new DefaultTestReport(this); 141 142 if( tr.hasPassed() != expectedStatus ){ 143 TestReport.Entry expectedStatusEntry 144 = new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_EXPECTED_STATUS, null), 145 (new Boolean (expectedStatus)).toString()); 146 TestReport.Entry receivedStatusEntry 147 = new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_RECEIVED_STATUS, null), 148 (new Boolean (tr.hasPassed())).toString()); 149 r.setDescription(new TestReport.Entry[]{ expectedStatusEntry, receivedStatusEntry }); 150 r.setErrorCode(ERROR_UNEXPECTED_TEST_STATUS); 151 r.setPassed(false); 152 } 153 else if( tr.getErrorCode() != expectedErrorCode ){ 154 TestReport.Entry expectedErrorCodeEntry 155 = new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_EXPECTED_ERROR_CODE, null), 156 expectedErrorCode); 157 TestReport.Entry receivedErrorCodeEntry 158 = new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_RECEIVED_ERROR_CODE, null), 159 tr.getErrorCode()); 160 161 r.setDescription(new TestReport.Entry[]{ expectedErrorCodeEntry, receivedErrorCodeEntry }); 162 r.setErrorCode(ERROR_UNEXPECTED_ERROR_CODE); 163 r.setPassed(false); 164 } 165 166 return r; 167 } 168 } 169 | Popular Tags |