1 package xdoclet.modules.ojb.tests; 2 3 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 21 import xdoclet.junit.*; 22 23 28 public class OjbTestBase extends XDocletTestBase 29 { 30 protected static final String OJB_DEST_FILE = "repository_user.xml"; 31 protected static final String TORQUE_DEST_FILE = "project_schema.xml"; 32 protected static final String PROPERTY_CHECKS = "checks"; 33 protected static final String PROPERTY_DATABASENAME = "databaseName"; 34 protected static final String PROPERTY_GENERATE_FOREIGNKEYS = "generateForeignkeys"; 35 36 public OjbTestBase(String name) 37 { 38 super(name); 39 } 40 41 protected String runOjbXDoclet(String destFile) 42 { 43 return runOjbXDoclet(destFile, null, null); 44 } 45 46 protected String runOjbXDoclet(String destFile, HashMap taskProps, HashMap subTaskProps) 47 { 48 clearTaskProperties(); 49 clearSubTaskProperties(); 50 setTaskName("xdoclet.modules.ojb.OjbDocletTask"); 51 setSubTaskName("xdoclet.modules.ojb.OjbSubTask"); 52 setProperties(taskProps, subTaskProps); 53 setDestFile(destFile); 54 55 return runXDoclet(); 56 } 57 58 protected String runTorqueXDoclet(String destFile, String dbName) 59 { 60 HashMap props = new HashMap (); 61 62 props.put(PROPERTY_DATABASENAME, dbName); 63 64 return runTorqueXDoclet(destFile, null, props); 65 } 66 67 protected String runTorqueXDoclet(String destFile, HashMap taskProps, HashMap subTaskProps) 68 { 69 clearTaskProperties(); 70 clearSubTaskProperties(); 71 setTaskName("xdoclet.modules.ojb.OjbDocletTask"); 72 setSubTaskName("xdoclet.modules.ojb.TorqueSubTask"); 73 setProperties(taskProps, subTaskProps); 74 setDestFile(destFile); 75 76 return runXDoclet(); 77 } 78 79 private void setProperties(HashMap taskProps, HashMap subTaskProps) 80 { 81 String key; 82 83 if (taskProps != null) 84 { 85 for (Iterator it = taskProps.keySet().iterator(); it.hasNext();) 86 { 87 key = (String )it.next(); 88 setTaskProperty(key, taskProps.get(key)); 89 } 90 } 91 if (subTaskProps != null) 92 { 93 for (Iterator it = subTaskProps.keySet().iterator(); it.hasNext();) 94 { 95 key = (String )it.next(); 96 setSubTaskProperty(key, subTaskProps.get(key)); 97 } 98 } 99 } 100 101 108 protected String compressWhitespaces(String text) 109 { 110 if (text == null) 111 { 112 return null; 113 } 114 115 StringBuffer result = new StringBuffer (); 116 char c; 117 boolean wasWS = false; 118 119 for (int idx = 0; idx < text.length(); idx++) 120 { 121 c = text.charAt(idx); 122 if (!Character.isWhitespace(c)) 123 { 124 if (wasWS && (result.length() > 0)) 125 { 126 result.append(' '); 127 } 128 result.append(c); 129 wasWS = false; 130 } 131 else 132 { 133 wasWS = true; 134 } 135 } 136 137 return result.toString(); 138 } 139 140 protected void assertEqualsOjbDescriptorFile(String expected, String value) 141 { 142 assertEquals("<!-- file containing the repository descriptions for user-defined types --> "+ 143 "<!-- Generated by the xdoclet-ojb module --> "+ 144 compressWhitespaces(expected), 145 compressWhitespaces(value)); 146 } 147 148 protected void assertEqualsTorqueSchemaFile(String expected, String value) 149 { 150 assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\" ?> "+ 151 "<!DOCTYPE database SYSTEM \"http://jakarta.apache.org/turbine/dtd/database.dtd\"> "+ 152 "<!-- Generated by the xdoclet-ojb module --> "+ 153 compressWhitespaces(expected), 154 compressWhitespaces(value)); 155 } 156 } 157 | Popular Tags |