1 18 package org.apache.batik.util; 19 20 import org.apache.batik.test.AbstractTest; 21 import org.apache.batik.test.DefaultTestReport; 22 import org.apache.batik.test.TestReport; 23 24 import java.io.StringWriter ; 25 import java.io.PrintWriter ; 26 27 34 public class ParsedURLTest extends AbstractTest { 35 41 public static final String ERROR_CANNOT_PARSE_URL 42 = "ParsedURLTest.error.cannot.parse.url"; 43 44 49 public static final String ERROR_WRONG_RESULT 50 = "ParsedURLTest.error.wrong.result"; 51 52 public static final String ENTRY_KEY_ERROR_DESCRIPTION 53 = "ParsedURLTest.entry.key.error.description"; 54 55 protected String base = null; 56 protected String sub = null; 57 protected String ref = null; 58 63 public ParsedURLTest(String url, String ref ){ 64 this.base = url; 65 this.ref = ref; 66 } 67 68 74 public ParsedURLTest(String base, String sub, String ref){ 75 this.base = base; 76 this.sub = sub; 77 this.ref = ref; 78 } 79 80 83 public String getName() { 84 return ref + " -- " + super.getName(); 85 } 86 87 91 public TestReport runImpl() throws Exception { 92 DefaultTestReport report 93 = new DefaultTestReport(this); 94 95 ParsedURL url; 96 try { 97 url = new ParsedURL(base); 98 if (sub != null) { 99 url = new ParsedURL(url, sub); 100 } 101 } catch(Exception e) { 102 StringWriter trace = new StringWriter (); 103 e.printStackTrace(new PrintWriter (trace)); 104 report.setErrorCode(ERROR_CANNOT_PARSE_URL); 105 report.setDescription(new TestReport.Entry[] { 106 new TestReport.Entry 107 (TestMessages.formatMessage 108 (ENTRY_KEY_ERROR_DESCRIPTION, null), 109 TestMessages.formatMessage 110 (ERROR_CANNOT_PARSE_URL, 111 new String []{base, 112 (sub == null) ? "null" : sub, 113 trace.toString()})) 114 }); 115 report.setPassed(false); 116 return report; 117 } 118 119 if (ref.equals(url.toString())) { 120 report.setPassed(true); 121 return report; 122 } 123 124 report.setErrorCode(ERROR_WRONG_RESULT); 125 report.setDescription(new TestReport.Entry[] { 126 new TestReport.Entry 127 (TestMessages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null), 128 TestMessages.formatMessage 129 (ERROR_WRONG_RESULT, new String []{url.toString(), ref })) 130 }); 131 report.setPassed(false); 132 return report; 133 } 134 } 135 | Popular Tags |