1 package org.eclipse.emf.codegen.ecore.templates.model.tests; 2 3 import java.util.*; 4 import org.eclipse.emf.codegen.ecore.genmodel.*; 5 6 public class TestCase 7 { 8 protected static String nl; 9 public static synchronized TestCase create(String lineSeparator) 10 { 11 nl = lineSeparator; 12 TestCase result = new TestCase(); 13 nl = null; 14 return result; 15 } 16 17 protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; 18 protected final String TEXT_1 = ""; 19 protected final String TEXT_2 = "/**" + NL + " * <copyright>" + NL + " * </copyright>" + NL + " *" + NL + " * "; 20 protected final String TEXT_3 = "Id"; 21 protected final String TEXT_4 = NL + " */" + NL + "package "; 22 protected final String TEXT_5 = ";" + NL; 23 protected final String TEXT_6 = NL + NL + "/**" + NL + " * <!-- begin-user-doc -->" + NL + " * A test case for the model object '<em><b>"; 24 protected final String TEXT_7 = "</b></em>'." + NL + " * <!-- end-user-doc -->"; 25 protected final String TEXT_8 = NL + " * <p>" + NL + " * The following features are tested:" + NL + " * <ul>"; 26 protected final String TEXT_9 = NL + " * <li>{@link "; 27 protected final String TEXT_10 = "#"; 28 protected final String TEXT_11 = "() <em>"; 29 protected final String TEXT_12 = "</em>}</li>"; 30 protected final String TEXT_13 = NL + " * </ul>" + NL + " * </p>"; 31 protected final String TEXT_14 = NL + " * <p>" + NL + " * The following operations are tested:" + NL + " * <ul>"; 32 protected final String TEXT_15 = NL + " * <li>{@link "; 33 protected final String TEXT_16 = "#"; 34 protected final String TEXT_17 = "("; 35 protected final String TEXT_18 = ") <em>"; 36 protected final String TEXT_19 = "</em>}</li>"; 37 protected final String TEXT_20 = NL + " * </ul>" + NL + " * </p>"; 38 protected final String TEXT_21 = NL + " * @generated" + NL + " */" + NL + "public"; 39 protected final String TEXT_22 = " abstract"; 40 protected final String TEXT_23 = " class "; 41 protected final String TEXT_24 = " extends "; 42 protected final String TEXT_25 = NL + "{"; 43 protected final String TEXT_26 = NL + NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; 44 protected final String TEXT_27 = " copyright = \""; 45 protected final String TEXT_28 = "\";"; 46 protected final String TEXT_29 = NL + NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; 47 protected final String TEXT_30 = " mofDriverNumber = \""; 48 protected final String TEXT_31 = "\";"; 49 protected final String TEXT_32 = NL + NL + "\t/**" + NL + "\t * The fixture for this "; 50 protected final String TEXT_33 = " test case." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected "; 51 protected final String TEXT_34 = " fixture = null;"; 52 protected final String TEXT_35 = NL + NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static void main(String[] args)" + NL + "\t{" + NL + "\t\t"; 53 protected final String TEXT_36 = ".run("; 54 protected final String TEXT_37 = "Test.class);" + NL + "\t}"; 55 protected final String TEXT_38 = NL + NL + "\t/**" + NL + "\t * Constructs a new "; 56 protected final String TEXT_39 = " test case with the given name." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic "; 57 protected final String TEXT_40 = "(String name)" + NL + "\t{" + NL + "\t\tsuper(name);" + NL + "\t}"; 58 protected final String TEXT_41 = NL + NL + "\t/**" + NL + "\t * Sets the fixture for this "; 59 protected final String TEXT_42 = " test case." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void setFixture("; 60 protected final String TEXT_43 = " fixture)" + NL + "\t{" + NL + "\t\tthis.fixture = fixture;" + NL + "\t}"; 61 protected final String TEXT_44 = NL + NL + "\t/**" + NL + "\t * Returns the fixture for this "; 62 protected final String TEXT_45 = " test case." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate "; 63 protected final String TEXT_46 = " getFixture()" + NL + "\t{"; 64 protected final String TEXT_47 = NL + "\t\treturn fixture;"; 65 protected final String TEXT_48 = NL + "\t\treturn ("; 66 protected final String TEXT_49 = ")fixture;"; 67 protected final String TEXT_50 = NL + "\t}"; 68 protected final String TEXT_51 = NL + NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @see junit.framework.TestCase#setUp()" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void setUp() throws Exception" + NL + "\t{" + NL + "\t\tsetFixture("; 69 protected final String TEXT_52 = ".eINSTANCE.create"; 70 protected final String TEXT_53 = "());" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @see junit.framework.TestCase#tearDown()" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void tearDown() throws Exception" + NL + "\t{" + NL + "\t\tsetFixture(null);" + NL + "\t}"; 71 protected final String TEXT_54 = NL + NL + "\t/**" + NL + "\t * Tests the '{@link "; 72 protected final String TEXT_55 = "#"; 73 protected final String TEXT_56 = "() <em>"; 74 protected final String TEXT_57 = "</em>}' feature getter." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @see "; 75 protected final String TEXT_58 = "#"; 76 protected final String TEXT_59 = "()" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void test"; 77 protected final String TEXT_60 = "()" + NL + "\t{"; 78 protected final String TEXT_61 = NL + "\t\t// TODO: implement this feature getter test method" + NL + "\t\t// Ensure that you remove @generated or mark it @generated NOT" + NL + "\t\tfail();"; 79 protected final String TEXT_62 = NL + "\t}"; 80 protected final String TEXT_63 = NL + NL + "\t/**" + NL + "\t * Tests the '{@link "; 81 protected final String TEXT_64 = "#set"; 82 protected final String TEXT_65 = "("; 83 protected final String TEXT_66 = ") <em>"; 84 protected final String TEXT_67 = "</em>}' feature setter." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @see "; 85 protected final String TEXT_68 = "#set"; 86 protected final String TEXT_69 = "("; 87 protected final String TEXT_70 = ")" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void testSet"; 88 protected final String TEXT_71 = "()" + NL + "\t{"; 89 protected final String TEXT_72 = NL + "\t\t// TODO: implement this feature setter test method" + NL + "\t\t// Ensure that you remove @generated or mark it @generated NOT" + NL + "\t\tfail();"; 90 protected final String TEXT_73 = NL + "\t}"; 91 protected final String TEXT_74 = NL + NL + "\t/**" + NL + "\t * Tests the '{@link "; 92 protected final String TEXT_75 = "#unset"; 93 protected final String TEXT_76 = "() <em>unset"; 94 protected final String TEXT_77 = "()</em>}' method." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @see "; 95 protected final String TEXT_78 = "#unset"; 96 protected final String TEXT_79 = "()" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void testUnset"; 97 protected final String TEXT_80 = "()" + NL + "\t{"; 98 protected final String TEXT_81 = NL + "\t\t// TODO: implement this test method" + NL + "\t\t// Ensure that you remove @generated or mark it @generated NOT" + NL + "\t\tfail();"; 99 protected final String TEXT_82 = NL + "\t}"; 100 protected final String TEXT_83 = NL + NL + "\t/**" + NL + "\t * Tests the '{@link "; 101 protected final String TEXT_84 = "#isSet"; 102 protected final String TEXT_85 = "() <em>isSet"; 103 protected final String TEXT_86 = "()</em>}' method." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @see "; 104 protected final String TEXT_87 = "#isSet"; 105 protected final String TEXT_88 = "()" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void testIsSet"; 106 protected final String TEXT_89 = "()" + NL + "\t{"; 107 protected final String TEXT_90 = NL + "\t\t// TODO: implement this test method" + NL + "\t\t// Ensure that you remove @generated or mark it @generated NOT" + NL + "\t\tfail();"; 108 protected final String TEXT_91 = NL + "\t}"; 109 protected final String TEXT_92 = NL + NL + "\t/**" + NL + "\t * Tests the '{@link "; 110 protected final String TEXT_93 = "#"; 111 protected final String TEXT_94 = "("; 112 protected final String TEXT_95 = ") <em>"; 113 protected final String TEXT_96 = "</em>}' operation." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @see "; 114 protected final String TEXT_97 = "#"; 115 protected final String TEXT_98 = "("; 116 protected final String TEXT_99 = ")" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void test"; 117 protected final String TEXT_100 = "()" + NL + "\t{"; 118 protected final String TEXT_101 = NL + "\t\t// TODO: implement this operation test method" + NL + "\t\t// Ensure that you remove @generated or mark it @generated NOT" + NL + "\t\tfail();"; 119 protected final String TEXT_102 = NL + "\t}"; 120 protected final String TEXT_103 = NL; 121 protected final String TEXT_104 = NL + "} //"; 122 protected final String TEXT_105 = NL; 123 124 public String generate(Object argument) 125 { 126 StringBuffer stringBuffer = new StringBuffer (); 127 128 142 143 GenClass genClass = (GenClass)argument; GenPackage genPackage = genClass.getGenPackage(); GenModel genModel=genPackage.getGenModel(); 144 stringBuffer.append(TEXT_1); 145 stringBuffer.append(TEXT_2); 146 stringBuffer.append("$"); 147 stringBuffer.append(TEXT_3); 148 stringBuffer.append("$"); 149 stringBuffer.append(TEXT_4); 150 stringBuffer.append(genPackage.getTestsPackageName()); 151 stringBuffer.append(TEXT_5); 152 genModel.markImportLocation(stringBuffer); 153 stringBuffer.append(TEXT_6); 154 stringBuffer.append(genClass.getFormattedName()); 155 stringBuffer.append(TEXT_7); 156 if (!genClass.getImplementedGenFeatures().isEmpty()) { boolean first = true; 157 for (Iterator genFeatures = genClass.getImplementedGenFeatures().iterator(); genFeatures.hasNext();) { GenFeature genFeature = (GenFeature)genFeatures.next(); 158 if ((genFeature.isVolatile() || genFeature.isDerived()) && !genFeature.isSuppressedGetVisibility()) { 159 if (first) { first = false; 160 stringBuffer.append(TEXT_8); 161 } 162 stringBuffer.append(TEXT_9); 163 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 164 stringBuffer.append(TEXT_10); 165 stringBuffer.append(genFeature.getGetAccessor()); 166 stringBuffer.append(TEXT_11); 167 stringBuffer.append(genFeature.getFormattedName()); 168 stringBuffer.append(TEXT_12); 169 } 170 } 171 if (!first) { 172 stringBuffer.append(TEXT_13); 173 } 174 } 175 if (!genClass.getImplementedGenOperations().isEmpty()) { boolean first = true; 176 for (Iterator genOperations = genClass.getImplementedGenOperations().iterator(); genOperations.hasNext();) { GenOperation genOperation = (GenOperation)genOperations.next(); 177 if (first) { first = false; 178 stringBuffer.append(TEXT_14); 179 } 180 stringBuffer.append(TEXT_15); 181 stringBuffer.append(genOperation.getGenClass().getQualifiedInterfaceName()); 182 stringBuffer.append(TEXT_16); 183 stringBuffer.append(genOperation.getName()); 184 stringBuffer.append(TEXT_17); 185 stringBuffer.append(genOperation.getParameterTypes(", ")); 186 stringBuffer.append(TEXT_18); 187 stringBuffer.append(genOperation.getFormattedName()); 188 stringBuffer.append(TEXT_19); 189 } 190 if (!first) { 191 stringBuffer.append(TEXT_20); 192 } 193 } 194 stringBuffer.append(TEXT_21); 195 if (genClass.isAbstract()) { 196 stringBuffer.append(TEXT_22); 197 } 198 stringBuffer.append(TEXT_23); 199 stringBuffer.append(genClass.getTestCaseClassName()); 200 stringBuffer.append(TEXT_24); 201 stringBuffer.append(genClass.isModelRoot() ? genModel.getImportedName("junit.framework.TestCase") : genClass.getClassExtendsGenClass().getImportedTestCaseClassName()); 202 stringBuffer.append(TEXT_25); 203 if (genModel.getCopyrightText() != null) { 204 stringBuffer.append(TEXT_26); 205 stringBuffer.append(genModel.getImportedName("java.lang.String")); 206 stringBuffer.append(TEXT_27); 207 stringBuffer.append(genModel.getCopyrightText()); 208 stringBuffer.append(TEXT_28); 209 stringBuffer.append(genModel.getNonNLS()); 210 } 211 if (genModel.getDriverNumber() != null) { 212 stringBuffer.append(TEXT_29); 213 stringBuffer.append(genModel.getImportedName("java.lang.String")); 214 stringBuffer.append(TEXT_30); 215 stringBuffer.append(genModel.getDriverNumber()); 216 stringBuffer.append(TEXT_31); 217 stringBuffer.append(genModel.getNonNLS()); 218 } 219 if (genClass.isModelRoot()) { 220 stringBuffer.append(TEXT_32); 221 stringBuffer.append(genClass.getFormattedName()); 222 stringBuffer.append(TEXT_33); 223 stringBuffer.append(genClass.getImportedInterfaceName()); 224 stringBuffer.append(TEXT_34); 225 } 226 if (!genClass.isAbstract()) { 227 stringBuffer.append(TEXT_35); 228 stringBuffer.append(genModel.getImportedName("junit.textui.TestRunner")); 229 stringBuffer.append(TEXT_36); 230 stringBuffer.append(genClass.getInterfaceName()); 231 stringBuffer.append(TEXT_37); 232 } 233 stringBuffer.append(TEXT_38); 234 stringBuffer.append(genClass.getFormattedName()); 235 stringBuffer.append(TEXT_39); 236 stringBuffer.append(genClass.getTestCaseClassName()); 237 stringBuffer.append(TEXT_40); 238 if (genClass.isModelRoot()) { 239 stringBuffer.append(TEXT_41); 240 stringBuffer.append(genClass.getFormattedName()); 241 stringBuffer.append(TEXT_42); 242 stringBuffer.append(genClass.getImportedInterfaceName()); 243 stringBuffer.append(TEXT_43); 244 } 245 stringBuffer.append(TEXT_44); 246 stringBuffer.append(genClass.getFormattedName()); 247 stringBuffer.append(TEXT_45); 248 stringBuffer.append(genClass.getImportedInterfaceName()); 249 stringBuffer.append(TEXT_46); 250 if (genClass.isModelRoot()) { 251 stringBuffer.append(TEXT_47); 252 } else { 253 stringBuffer.append(TEXT_48); 254 stringBuffer.append(genClass.getImportedInterfaceName()); 255 stringBuffer.append(TEXT_49); 256 } 257 stringBuffer.append(TEXT_50); 258 if (!genClass.isAbstract()) { 259 stringBuffer.append(TEXT_51); 260 stringBuffer.append(genPackage.getImportedFactoryInterfaceName()); 261 stringBuffer.append(TEXT_52); 262 stringBuffer.append(genClass.getName()); 263 stringBuffer.append(TEXT_53); 264 } 265 for (Iterator genFeatures=genClass.getImplementedGenFeatures().iterator(); genFeatures.hasNext();) { GenFeature genFeature = (GenFeature)genFeatures.next(); 266 if (genFeature.isVolatile() || genFeature.isDerived()) { 267 if (genFeature.isGet() && !genFeature.isSuppressedGetVisibility()) { 268 stringBuffer.append(TEXT_54); 269 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 270 stringBuffer.append(TEXT_55); 271 stringBuffer.append(genFeature.getGetAccessor()); 272 stringBuffer.append(TEXT_56); 273 stringBuffer.append(genFeature.getFormattedName()); 274 stringBuffer.append(TEXT_57); 275 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 276 stringBuffer.append(TEXT_58); 277 stringBuffer.append(genFeature.getGetAccessor()); 278 stringBuffer.append(TEXT_59); 279 stringBuffer.append(genModel.capName(genFeature.getGetAccessor())); 280 stringBuffer.append(TEXT_60); 281 stringBuffer.append(TEXT_61); 282 stringBuffer.append(TEXT_62); 284 } 286 if (genFeature.isSet() && !genFeature.isSuppressedSetVisibility()) { 287 stringBuffer.append(TEXT_63); 288 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 289 stringBuffer.append(TEXT_64); 290 stringBuffer.append(genFeature.getAccessorName()); 291 stringBuffer.append(TEXT_65); 292 stringBuffer.append(genFeature.getType()); 293 stringBuffer.append(TEXT_66); 294 stringBuffer.append(genFeature.getFormattedName()); 295 stringBuffer.append(TEXT_67); 296 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 297 stringBuffer.append(TEXT_68); 298 stringBuffer.append(genFeature.getAccessorName()); 299 stringBuffer.append(TEXT_69); 300 stringBuffer.append(genFeature.getType()); 301 stringBuffer.append(TEXT_70); 302 stringBuffer.append(genFeature.getAccessorName()); 303 stringBuffer.append(TEXT_71); 304 stringBuffer.append(TEXT_72); 305 stringBuffer.append(TEXT_73); 307 } 309 if (genFeature.isUnset() && !genFeature.isSuppressedUnsetVisibility()) { 310 stringBuffer.append(TEXT_74); 311 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 312 stringBuffer.append(TEXT_75); 313 stringBuffer.append(genFeature.getAccessorName()); 314 stringBuffer.append(TEXT_76); 315 stringBuffer.append(genFeature.getAccessorName()); 316 stringBuffer.append(TEXT_77); 317 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 318 stringBuffer.append(TEXT_78); 319 stringBuffer.append(genFeature.getAccessorName()); 320 stringBuffer.append(TEXT_79); 321 stringBuffer.append(genFeature.getAccessorName()); 322 stringBuffer.append(TEXT_80); 323 stringBuffer.append(TEXT_81); 324 stringBuffer.append(TEXT_82); 326 } 328 if (genFeature.isIsSet() && !genFeature.isSuppressedIsSetVisibility()) { 329 stringBuffer.append(TEXT_83); 330 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 331 stringBuffer.append(TEXT_84); 332 stringBuffer.append(genFeature.getAccessorName()); 333 stringBuffer.append(TEXT_85); 334 stringBuffer.append(genFeature.getAccessorName()); 335 stringBuffer.append(TEXT_86); 336 stringBuffer.append(genFeature.getGenClass().getQualifiedInterfaceName()); 337 stringBuffer.append(TEXT_87); 338 stringBuffer.append(genFeature.getAccessorName()); 339 stringBuffer.append(TEXT_88); 340 stringBuffer.append(genFeature.getAccessorName()); 341 stringBuffer.append(TEXT_89); 342 stringBuffer.append(TEXT_90); 343 stringBuffer.append(TEXT_91); 345 } 347 } 348 } 350 for (Iterator genOperations = genClass.getImplementedGenOperations().iterator(); genOperations.hasNext();) { GenOperation genOperation = (GenOperation)genOperations.next(); 351 stringBuffer.append(TEXT_92); 352 stringBuffer.append(genOperation.getGenClass().getQualifiedInterfaceName()); 353 stringBuffer.append(TEXT_93); 354 stringBuffer.append(genOperation.getName()); 355 stringBuffer.append(TEXT_94); 356 stringBuffer.append(genOperation.getParameterTypes(", ")); 357 stringBuffer.append(TEXT_95); 358 stringBuffer.append(genOperation.getFormattedName()); 359 stringBuffer.append(TEXT_96); 360 stringBuffer.append(genOperation.getGenClass().getQualifiedInterfaceName()); 361 stringBuffer.append(TEXT_97); 362 stringBuffer.append(genOperation.getName()); 363 stringBuffer.append(TEXT_98); 364 stringBuffer.append(genOperation.getParameterTypes(", ")); 365 stringBuffer.append(TEXT_99); 366 stringBuffer.append(genModel.capName(genOperation.getName())); 367 stringBuffer.append(genOperation.getGenParameters().size() == 0 ? "" : "__" + genOperation.getParameterTypes("_", false)); 368 stringBuffer.append(TEXT_100); 369 stringBuffer.append(TEXT_101); 370 stringBuffer.append(TEXT_102); 372 } 374 stringBuffer.append(TEXT_103); 375 stringBuffer.append(TEXT_104); 376 stringBuffer.append(genClass.getTestCaseClassName()); 377 genModel.emitSortedImports(); 378 stringBuffer.append(TEXT_105); 379 return stringBuffer.toString(); 380 } 381 } 382 | Popular Tags |