1 31 32 package org.opencms.test; 33 34 import org.opencms.db.CmsDbPool; 35 import org.opencms.file.CmsFile; 36 import org.opencms.file.CmsGroup; 37 import org.opencms.file.CmsObject; 38 import org.opencms.file.CmsProject; 39 import org.opencms.file.CmsProperty; 40 import org.opencms.file.CmsPropertyDefinition; 41 import org.opencms.file.CmsResource; 42 import org.opencms.file.CmsResourceFilter; 43 import org.opencms.file.CmsUser; 44 import org.opencms.file.types.CmsResourceTypeBinary; 45 import org.opencms.file.types.CmsResourceTypeFolder; 46 import org.opencms.file.types.CmsResourceTypePlain; 47 import org.opencms.lock.CmsLock; 48 import org.opencms.main.CmsException; 49 import org.opencms.main.CmsShell; 50 import org.opencms.main.CmsSystemInfo; 51 import org.opencms.main.OpenCms; 52 import org.opencms.report.CmsShellReport; 53 import org.opencms.security.CmsAccessControlEntry; 54 import org.opencms.security.CmsAccessControlList; 55 import org.opencms.security.CmsPermissionSet; 56 import org.opencms.setup.CmsSetupDb; 57 import org.opencms.util.CmsDateUtil; 58 import org.opencms.util.CmsFileUtil; 59 import org.opencms.util.CmsPropertyUtils; 60 import org.opencms.util.CmsUUID; 61 62 import java.io.File ; 63 import java.io.FileInputStream ; 64 import java.io.IOException ; 65 import java.util.ArrayList ; 66 import java.util.HashMap ; 67 import java.util.Iterator ; 68 import java.util.List ; 69 import java.util.Map ; 70 import java.util.Vector ; 71 72 import junit.framework.TestCase; 73 74 import org.apache.commons.collections.ExtendedProperties; 75 76 import org.dom4j.Document; 77 import org.dom4j.Node; 78 import org.dom4j.util.NodeComparator; 79 80 96 public class OpenCmsTestCase extends TestCase { 97 98 99 protected class ConnectionData { 100 101 102 public String m_dbName; 103 104 105 public String m_jdbcDriver; 106 107 108 public String m_jdbcUrl; 109 110 111 public String m_jdbcUrlParams; 112 113 114 public String m_userName; 115 116 117 public String m_userPassword; 118 } 119 120 123 class InternalNodeComparator extends NodeComparator { 124 125 126 public Node m_node1 = null; 127 128 129 public Node m_node2 = null; 130 131 134 public int compare(Node n1, Node n2) { 135 136 int result = super.compare(n1, n2); 137 if (result != 0 && m_node1 == null) { 138 m_node1 = n1; 139 m_node2 = n2; 140 } 141 return result; 142 } 143 } 144 145 146 public static final String DB_MYSQL = "mysql"; 147 148 149 public static final String DB_ORACLE = "oracle"; 150 151 152 public static ExtendedProperties m_configuration = null; 153 154 155 public static String m_dbProduct = DB_MYSQL; 156 157 158 public static String m_defaultTablespace; 159 160 161 public static String m_indexTablespace; 162 163 164 public static HashMap m_resourceStorages; 165 166 167 public static String m_tempTablespace; 168 169 170 protected static ConnectionData m_additionalConnection; 171 172 173 protected static ConnectionData m_defaultConnection; 174 175 176 protected static ConnectionData m_setupConnection; 177 178 179 private static String m_additionalConnectionName = "additional"; 180 181 182 private static long[] m_dateConfigFiles; 183 184 185 private static String m_setupDataPath; 186 187 188 private static CmsShell m_shell; 189 190 191 private static List m_testDataPath; 192 193 194 public OpenCmsTestResourceStorage m_currentResourceStrorage; 195 196 201 public OpenCmsTestCase(String arg0) { 202 203 this(arg0, true); 204 } 205 206 211 public OpenCmsTestCase(String arg0, boolean initialize) { 212 213 super(arg0); 214 if (initialize) { 215 OpenCmsTestLogAppender.setBreakOnError(false); 216 if (m_resourceStorages == null) { 217 m_resourceStorages = new HashMap (); 218 } 219 220 initConfiguration(); 222 223 OpenCmsTestLogAppender.setBreakOnError(true); 225 } 226 } 227 228 244 public static int generateContent( 245 CmsObject cms, 246 String vfsFolder, 247 int maxWidth, 248 int maxDepth, 249 int maxProps, 250 double propertyDistribution, 251 int maxNumberOfFiles, 252 double fileTypeDistribution) throws Exception { 253 254 int fileNameLength = 10; 255 int propValueLength = 10; 256 257 if (maxDepth < 1) { 259 return 0; 260 } 261 if (!vfsFolder.endsWith("/")) { 262 vfsFolder += "/"; 263 } 264 265 int writtenFiles = 0; 266 267 int width = (int)(maxWidth * Math.random()) + 1; 268 int depth = maxDepth - (int)(2 * Math.random()); 269 for (int i = 0; i < width; i++) { 270 String vfsName = vfsFolder + generateName(fileNameLength) + i; 272 List props = generateProperties(cms, maxProps, propValueLength, propertyDistribution); 273 cms.createResource(vfsName, CmsResourceTypeFolder.getStaticTypeId(), new byte[0], props); 274 cms.unlockResource(vfsName); 275 276 int numberOfFiles = (int)(maxNumberOfFiles * Math.random()) + 1; 277 int numberOfBinaryFiles = (int)(numberOfFiles * fileTypeDistribution); 279 writtenFiles += generateResources( 280 cms, 281 "org/opencms/search/pdf-test-112.pdf", 282 vfsName, 283 numberOfBinaryFiles, 284 CmsResourceTypeBinary.getStaticTypeId(), 285 maxProps, 286 propertyDistribution); 287 288 writtenFiles += generateResources(cms, "org/opencms/search/extractors/test1.html", vfsName, numberOfFiles 290 - numberOfBinaryFiles, CmsResourceTypePlain.getStaticTypeId(), maxProps, propertyDistribution); 291 292 writtenFiles += generateContent( 294 cms, 295 vfsName, 296 maxWidth, 297 depth - 1, 298 maxProps, 299 propertyDistribution, 300 maxNumberOfFiles, 301 fileTypeDistribution); 302 303 System.out.println("" + writtenFiles + " files written in Folder " + vfsName); 304 } 305 return writtenFiles; 306 } 307 308 320 public static int generateContent(CmsObject cms, String vfsFolder, int numberOfFiles, double fileTypeDistribution) 321 throws Exception { 322 323 int maxProps = 10; 324 double propertyDistribution = 0.0; 325 int writtenFiles = 0; 326 327 int numberOfBinaryFiles = (int)(numberOfFiles * fileTypeDistribution); 328 329 writtenFiles += generateResources( 331 cms, 332 "org/opencms/search/pdf-test-112.pdf", 333 vfsFolder, 334 numberOfBinaryFiles, 335 CmsResourceTypeBinary.getStaticTypeId(), 336 maxProps, 337 propertyDistribution); 338 339 writtenFiles += generateResources(cms, "org/opencms/search/extractors/test1.html", vfsFolder, numberOfFiles 341 - numberOfBinaryFiles, CmsResourceTypePlain.getStaticTypeId(), maxProps, propertyDistribution); 342 343 System.out.println("" + writtenFiles + " files written in Folder " + vfsFolder); 344 345 return writtenFiles; 346 } 347 348 363 public static int generateResources( 364 CmsObject cms, 365 String rfsName, 366 String vfsFolder, 367 int n, 368 int type, 369 int maxProps, 370 double propertyDistribution) throws Exception { 371 372 int fileNameLength = 10; 373 int propValueLength = 10; 374 375 if (!vfsFolder.endsWith("/")) { 376 vfsFolder += "/"; 377 } 378 int writtenFiles = 0; 379 System.out.println("Importing files"); 380 for (int i = 0; i < n; i++) { 381 String vfsName = vfsFolder + generateName(fileNameLength) + i; 382 if (rfsName.lastIndexOf('.') > 0) { 383 vfsName += rfsName.substring(rfsName.lastIndexOf('.')); 384 } 385 386 List props = generateProperties(cms, maxProps, propValueLength, propertyDistribution); 387 try { 388 OpenCmsTestCase.importTestResource(cms, rfsName, vfsName, type, props); 389 writtenFiles++; 390 } catch (Exception e) { 391 System.out.println("error! " + e.getMessage()); 392 } 393 } 394 return writtenFiles; 395 } 396 397 404 public static String generateName(int maxLen) { 405 406 String name = ""; 407 int len = (int)(maxLen * Math.random()) + 1; 408 for (int j = 0; j < len; j++) { 409 name += (char)(25 * Math.random() + 97); 410 } 411 return name; 412 } 413 414 426 public static List generateProperties(CmsObject cms, int maxProps, int propValueLength, double propertyDistribution) 427 throws CmsException { 428 429 List propList = cms.readAllPropertyDefinitions(); 430 431 List props = new ArrayList (); 432 if (maxProps > propList.size()) { 433 maxProps = propList.size(); 434 } 435 int propN = (int)(Math.random() * maxProps) + 1; 436 for (int j = 0; j < propN; j++) { 437 CmsPropertyDefinition propDef = (CmsPropertyDefinition)propList.get((int)(Math.random() * propList.size())); 438 propList.remove(propDef); 439 if (Math.random() < propertyDistribution) { 440 props.add(new CmsProperty(propDef.getName(), null, generateName(propValueLength))); 442 } else { 443 props.add(new CmsProperty( 445 propDef.getName(), 446 generateName(propValueLength), 447 generateName(propValueLength))); 448 } 449 } 450 451 return props; 452 } 453 454 463 public static void generateUsers(CmsObject cms, String groupName, int n) throws CmsException { 464 465 CmsGroup group = null; 466 try { 467 group = cms.readGroup(groupName); 468 } catch (Exception e) { 469 } 471 if (group == null) { 472 group = cms.createGroup(groupName, groupName, 0, null); 473 } 474 for (int i = 0; i < n; i++) { 475 String name = generateName(10) + i; 476 cms.createUser(name, "pwd" + i, "test user " + i, null); 477 cms.addUserToGroup(name, groupName); 478 } 479 } 480 481 486 public static String getDbProduct() { 487 488 return m_dbProduct; 489 } 490 491 495 public static synchronized void initTestDataPath() { 496 497 if (m_testDataPath == null) { 498 m_testDataPath = new ArrayList (4); 499 500 try { 504 OpenCmsTestProperties.getInstance(); 505 } catch (RuntimeException rte) { 506 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 507 } 508 addTestDataPath(OpenCmsTestProperties.getInstance().getTestDataPath()); 510 } 511 } 512 513 517 public static void removeOpenCms() { 518 519 OpenCmsTestLogAppender.setBreakOnError(false); 521 522 m_shell.printPrompt(); 524 System.out.println("----- Test cases finished -----"); 525 526 m_shell.exit(); 528 529 removeDatabase(); 531 532 String configFolder = getTestDataPath("WEB-INF" + File.separator + "config." + m_dbProduct + File.separator); 534 copyConfiguration(configFolder); 535 536 String path; 538 path = getTestDataPath("WEB-INF/classes/"); 539 if (path != null) { 540 CmsFileUtil.purgeDirectory(new File(path)); 541 } 542 path = getTestDataPath("WEB-INF/lib/"); 543 if (path != null) { 544 CmsFileUtil.purgeDirectory(new File(path)); 545 } 546 path = getTestDataPath("WEB-INF/" + CmsSystemInfo.FOLDER_CONFIG + "backup/"); 547 if (path != null) { 548 CmsFileUtil.purgeDirectory(new File(path)); 549 } 550 path = getTestDataPath("WEB-INF/index/"); 551 if (path != null) { 552 CmsFileUtil.purgeDirectory(new File(path)); 553 } 554 path = getTestDataPath("export/"); 555 if (path != null) { 556 CmsFileUtil.purgeDirectory(new File(path)); 557 } 558 559 try { 560 Thread.sleep(500); 562 } catch (InterruptedException e) { 563 } 565 } 566 567 570 public static void restartOpenCms() { 571 572 OpenCmsTestLogAppender.setBreakOnError(false); 574 System.out.println("\n\n\n----- Restarting OpenCms -----"); 576 577 if (m_shell != null) { 579 try { 580 m_shell.exit(); 581 m_shell = null; 582 } catch (Throwable t) { 583 } 585 } 586 587 m_shell = new CmsShell(getTestDataPath("WEB-INF" + File.separator), null, null, "${user}@${project}>", null); 589 590 OpenCmsTestLogAppender.setBreakOnError(true); 592 } 593 594 599 public static void setConnectionName(String additionalConnectionName) { 600 601 m_additionalConnectionName = additionalConnectionName; 602 } 603 604 612 public static CmsObject setupOpenCms(String importFolder, String targetFolder) { 613 614 return setupOpenCms(importFolder, targetFolder, getTestDataPath("WEB-INF/config." + m_dbProduct + "/"), true); 615 } 616 617 626 public static CmsObject setupOpenCms(String importFolder, String targetFolder, boolean publish) { 627 628 return setupOpenCms(importFolder, targetFolder, getTestDataPath("WEB-INF/config." + m_dbProduct + "/"), publish); 629 } 630 631 642 public static CmsObject setupOpenCms(String importFolder, String targetFolder, String configFolder, boolean publish) { 643 644 m_resourceStorages = new HashMap (); 646 647 OpenCmsTestLogAppender.setBreakOnError(false); 649 System.out.println("\n\n\n----- Starting test case: Importing OpenCms VFS data -----"); 651 652 if (m_shell != null) { 654 try { 655 m_shell.exit(); 656 m_shell = null; 657 } catch (Throwable t) { 658 } 660 } 661 662 copyConfiguration(configFolder); 664 665 setupDatabase(); 667 668 m_shell = new CmsShell(getTestDataPath("WEB-INF" + File.separator), null, null, "${user}@${project}>", null); 670 671 File script; 673 FileInputStream stream = null; 674 CmsObject cms = null; 675 676 try { 677 script = new File(getTestDataPath("scripts/script_base.txt")); 679 stream = new FileInputStream (script); 680 m_shell.start(stream); 681 682 script = new File(getTestDataPath("scripts/script_default_folders.txt")); 684 stream = new FileInputStream (script); 685 m_shell.start(stream); 686 687 cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); 689 cms.loginUser("Admin", "admin"); 690 cms.getRequestContext().setCurrentProject(cms.readProject("_setupProject")); 691 692 if (importFolder != null) { 693 importResources(cms, importFolder, targetFolder); 695 } 696 697 script = new File(getTestDataPath("scripts/script_default_projects.txt")); 699 stream = new FileInputStream (script); 700 m_shell.start(stream); 701 702 if (publish) { 703 script = new File(getTestDataPath("scripts/script_publish.txt")); 705 stream = new FileInputStream (script); 706 m_shell.start(stream); 707 } else { 708 cms.unlockProject(cms.readProject("_setupProject").getId()); 709 } 710 711 cms.getRequestContext().setCurrentProject(cms.readProject("Offline")); 713 cms.getRequestContext().setSiteRoot("/sites/default/"); 714 715 System.out.println("----- Starting test cases -----"); 717 } catch (Throwable t) { 718 t.printStackTrace(System.err); 719 fail("Unable to setup OpenCms\n" + CmsException.getStackTraceAsString(t)); 720 } 721 OpenCmsTestLogAppender.setBreakOnError(true); 723 return cms; 725 } 726 727 732 protected static synchronized void addTestDataPath(String dataPath) { 733 734 File testDataFolder = new File(dataPath); 736 if (!testDataFolder.exists()) { 737 fail("DB setup data not available at " + testDataFolder.getAbsolutePath()); 738 } 739 m_testDataPath.add(CmsFileUtil.normalizePath(testDataFolder.getAbsolutePath() + File.separator)); 740 } 741 742 747 protected static void checkErrors(CmsSetupDb setupDb) { 748 749 if (!setupDb.noErrors()) { 750 Vector errors = setupDb.getErrors(); 751 for (Iterator i = errors.iterator(); i.hasNext();) { 752 String error = (String )i.next(); 753 System.out.println(error); 754 } 755 fail((String )setupDb.getErrors().get(0)); 756 } 757 } 758 759 766 protected static Map getReplacer(ConnectionData connectionData) { 767 768 Map replacer = new HashMap (); 769 replacer.put("${database}", connectionData.m_dbName); 770 replacer.put("${user}", connectionData.m_userName); 771 replacer.put("${password}", connectionData.m_userPassword); 772 replacer.put("${defaultTablespace}", m_defaultTablespace); 773 replacer.put("${indexTablespace}", m_indexTablespace); 774 replacer.put("${temporaryTablespace}", m_tempTablespace); 775 776 return replacer; 777 } 778 779 787 protected static synchronized String getSetupDataPath() { 788 789 if (m_setupDataPath == null) { 790 File setupDataFolder = new File(OpenCmsTestProperties.getInstance().getTestWebappPath()); 792 if (!setupDataFolder.exists()) { 793 fail("DB setup data not available at " + setupDataFolder.getAbsolutePath()); 794 } 795 m_setupDataPath = setupDataFolder.getAbsolutePath() + File.separator; 796 } 797 return m_setupDataPath; 799 } 800 801 808 protected static CmsSetupDb getSetupDb(ConnectionData connection) { 809 810 CmsSetupDb setupDb = new CmsSetupDb(getSetupDataPath()); 812 813 setupDb.setConnection( 815 connection.m_jdbcDriver, 816 connection.m_jdbcUrl, 817 connection.m_jdbcUrlParams, 818 connection.m_userName, 819 connection.m_userPassword); 820 821 if (!DB_ORACLE.equals(m_dbProduct)) { 823 checkErrors(setupDb); 824 } 825 826 return setupDb; 827 } 828 829 839 protected static String getTestDataPath(String filename) { 840 841 for (int i = 0; i < m_testDataPath.size(); i++) { 842 843 String path = (String )m_testDataPath.get(i); 844 File file = new File(path + filename); 845 if (file.exists()) { 846 if (file.isDirectory()) { 847 return file.getAbsolutePath() + File.separator; 848 } else { 849 return file.getAbsolutePath(); 850 } 851 } 852 } 853 854 return null; 855 } 856 857 865 protected static void importResources(CmsObject cms, String importFile, String targetPath) throws CmsException { 866 867 OpenCms.getImportExportManager().importData( 868 cms, 869 getTestDataPath(File.separator + "imports" + File.separator + importFile), 870 targetPath, 871 new CmsShellReport(cms.getRequestContext().getLocale())); 872 } 873 874 888 protected static CmsResource importTestResource( 889 CmsObject cms, 890 String rfsPath, 891 String vfsPath, 892 int type, 893 List properties) throws Exception { 894 895 byte[] content = CmsFileUtil.readFile(rfsPath); 896 CmsResource result = cms.createResource(vfsPath, type, content, properties); 897 cms.unlockResource(vfsPath); 898 return result; 899 } 900 901 904 protected static void removeDatabase() { 905 906 if (m_defaultConnection != null) { 907 removeDatabase(m_setupConnection, m_defaultConnection, false); 908 } 909 if (m_additionalConnection != null) { 910 removeDatabase(m_setupConnection, m_additionalConnection, false); 911 } 912 } 913 914 921 protected static void removeDatabase( 922 ConnectionData setupConnection, 923 ConnectionData defaultConnection, 924 boolean handleErrors) { 925 926 CmsSetupDb setupDb = null; 927 boolean noErrors = true; 928 929 try { 930 setupDb = getSetupDb(defaultConnection); 931 setupDb.dropTables(m_dbProduct, getReplacer(defaultConnection), handleErrors); 932 noErrors = setupDb.noErrors(); 933 } catch (Exception e) { 934 noErrors = false; 935 } finally { 936 if (setupDb != null) { 937 setupDb.closeConnection(); 938 } 939 } 940 941 if (!handleErrors || noErrors) { 942 try { 943 setupDb = getSetupDb(setupConnection); 944 setupDb.dropDatabase(m_dbProduct, getReplacer(defaultConnection), handleErrors); 945 setupDb.closeConnection(); 946 } catch (Exception e) { 947 noErrors = false; 948 } finally { 949 if (setupDb != null) { 950 setupDb.closeConnection(); 951 } 952 } 953 } 954 955 if (handleErrors) { 956 checkErrors(setupDb); 957 } 958 } 959 960 965 protected static void setupDatabase() { 966 967 if (m_defaultConnection != null) { 968 setupDatabase(m_setupConnection, m_defaultConnection, true); 969 } 970 if (m_additionalConnection != null) { 971 setupDatabase(m_setupConnection, m_additionalConnection, true); 972 } 973 } 974 975 982 protected static void setupDatabase( 983 ConnectionData setupConnection, 984 ConnectionData defaultConnection, 985 boolean handleErrors) { 986 987 CmsSetupDb setupDb = null; 988 boolean noErrors = true; 989 990 try { 991 setupDb = getSetupDb(setupConnection); 992 setupDb.createDatabase(m_dbProduct, getReplacer(defaultConnection), handleErrors); 993 noErrors = setupDb.noErrors(); 994 setupDb.closeConnection(); 995 } catch (Exception e) { 996 noErrors = false; 997 } finally { 998 if (setupDb != null) { 999 setupDb.closeConnection(); 1000 } 1001 } 1002 1003 if (!handleErrors || noErrors) { 1004 try { 1005 setupDb = getSetupDb(defaultConnection); 1006 setupDb.createTables(m_dbProduct, getReplacer(defaultConnection), handleErrors); 1007 noErrors = setupDb.noErrors(); 1008 setupDb.closeConnection(); 1009 } catch (Exception e) { 1010 noErrors = false; 1011 } finally { 1012 if (setupDb != null) { 1013 setupDb.closeConnection(); 1014 } 1015 } 1016 } 1017 1018 if (noErrors) { 1019 return; 1020 } else if (handleErrors) { 1021 removeDatabase(setupConnection, defaultConnection, false); 1022 setupDatabase(setupConnection, defaultConnection, false); 1023 } else { 1024 checkErrors(setupDb); 1025 } 1026 } 1027 1028 1038 private static String compareProperties( 1039 CmsObject cms, 1040 String resourceName, 1041 OpenCmsTestResourceStorageEntry storedResource, 1042 List excludeList) throws CmsException { 1043 1044 String noMatches = ""; 1045 List storedProperties = storedResource.getProperties(); 1046 List properties = cms.readPropertyObjects(resourceName, false); 1047 List unmatchedProperties; 1048 unmatchedProperties = OpenCmsTestResourceFilter.compareProperties(storedProperties, properties, excludeList); 1049 if (unmatchedProperties.size() > 0) { 1050 noMatches += "[Properies missing " + unmatchedProperties.toString() + "]\n"; 1051 } 1052 unmatchedProperties = OpenCmsTestResourceFilter.compareProperties(properties, storedProperties, excludeList); 1053 if (unmatchedProperties.size() > 0) { 1054 noMatches += "[Properies additional " + unmatchedProperties.toString() + "]\n"; 1055 } 1056 return noMatches; 1057 } 1058 1059 1064 private static void copyConfiguration(String newConfig) { 1065 1066 File configDir = new File(getTestDataPath("WEB-INF" + File.separatorChar + CmsSystemInfo.FOLDER_CONFIG)); 1067 File configOriDir = new File(newConfig); 1068 1069 if (configOriDir.exists()) { 1070 File[] oriFiles = configOriDir.listFiles(); 1071 boolean initConfigDates = false; 1072 if (m_dateConfigFiles == null) { 1073 m_dateConfigFiles = new long[oriFiles.length]; 1074 initConfigDates = true; 1075 } 1076 for (int i = 0; i < oriFiles.length; i++) { 1077 File source = oriFiles[i]; 1078 if (source.isFile()) { 1079 String sourceName = source.getAbsolutePath(); 1081 File target = new File(configDir, source.getName()); 1082 if (initConfigDates) { 1083 m_dateConfigFiles[i] = target.lastModified(); 1084 } 1085 String targetName = target.getAbsolutePath(); 1086 try { 1087 CmsFileUtil.copy(sourceName, targetName); 1088 target.setLastModified(m_dateConfigFiles[i]); 1089 } catch (IOException e) { 1090 e.printStackTrace(); 1091 } 1092 } 1093 } 1094 } 1095 1096 } 1097 1098 1105 public void assertAce(CmsObject cms, String resourceName, CmsAccessControlEntry ace) { 1106 1107 try { 1108 1109 List excludeList = new ArrayList (); 1111 if (ace != null) { 1112 excludeList.add(ace); 1113 } 1114 1115 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 1117 1118 String noMatches = compareAccessEntries(cms, resourceName, storedResource, excludeList); 1119 1120 if (noMatches.length() > 0) { 1122 fail("error comparing ace of resource " + resourceName + " with stored values: " + noMatches); 1123 } 1124 1125 if (ace != null) { 1126 List resAces = cms.getAccessControlEntries(resourceName); 1127 boolean notFound = true; 1128 Iterator i = resAces.iterator(); 1129 while (i.hasNext()) { 1130 CmsAccessControlEntry resAce = (CmsAccessControlEntry)i.next(); 1131 if (resAce.getPrincipal().equals(ace.getPrincipal()) 1132 && (resAce.getResource().equals(ace.getResource()))) { 1133 notFound = false; 1134 if (!resAce.equals(ace)) { 1135 fail("[ACE " + ace + " != " + resAce + "]"); 1136 } 1137 } 1138 } 1139 if (notFound) { 1140 fail("[ACE not found" + ace + "]"); 1141 } 1142 } 1143 } catch (Exception e) { 1144 fail("cannot read resource " + resourceName + " " + e.getMessage()); 1145 } 1146 } 1147 1148 1156 public void assertAcl(CmsObject cms, String resourceName, CmsUUID principal, CmsPermissionSet permission) { 1157 1158 try { 1159 1160 List excludeList = new ArrayList (); 1162 if (permission != null) { 1163 excludeList.add(principal); 1164 } 1165 1166 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 1168 1169 String noMatches = compareAccessLists(cms, resourceName, storedResource, excludeList); 1170 1171 if (noMatches.length() > 0) { 1173 fail("error comparing permission sets of resource " 1174 + resourceName 1175 + " with stored values: " 1176 + noMatches); 1177 } 1178 1179 if (permission != null) { 1180 CmsAccessControlList resAcls = cms.getAccessControlList(resourceName); 1181 1182 Map permissionMap = resAcls.getPermissionMap(); 1183 CmsPermissionSet resPermission = (CmsPermissionSet)permissionMap.get(principal); 1184 if (resPermission != null) { 1185 if (!resPermission.equals(permission)) { 1186 fail("[Permission set not equal " + principal + ":" + permission + " != " + resPermission + "]"); 1187 } 1188 } else { 1189 fail("[Permission set not found " + principal + ":" + permission + "]"); 1190 } 1191 } 1192 } catch (Exception e) { 1193 fail("cannot read resource " + resourceName + " " + e.getMessage()); 1194 } 1195 } 1196 1197 1206 public void assertAcl( 1207 CmsObject cms, 1208 String modifiedResource, 1209 String resourceName, 1210 CmsUUID principal, 1211 CmsPermissionSet permission) { 1212 1213 1215 try { 1216 List excludeList = new ArrayList (); 1218 if (permission != null) { 1219 excludeList.add(principal); 1220 } 1221 1222 1224 Map parents = getParents(cms, resourceName); 1225 List aceList = cms.getAccessControlEntries(resourceName); 1226 Iterator i = aceList.iterator(); 1227 while (i.hasNext()) { 1228 CmsAccessControlEntry ace = (CmsAccessControlEntry)i.next(); 1229 if (ace.getPrincipal().equals(principal)) { 1230 String parent = (String )parents.get(ace.getResource()); 1231 if ((!parent.equals(modifiedResource)) && (parent.length() > modifiedResource.length())) { 1232 permission = new CmsPermissionSet(ace.getAllowedPermissions(), ace.getDeniedPermissions()); 1233 } 1234 } 1235 } 1236 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 1238 1239 String noMatches = compareAccessLists(cms, resourceName, storedResource, excludeList); 1240 1241 if (noMatches.length() > 0) { 1243 fail("error comparing permission sets of resource " 1244 + resourceName 1245 + " with stored values: " 1246 + noMatches); 1247 } 1248 1249 if (permission != null) { 1250 CmsAccessControlList resAcls = cms.getAccessControlList(resourceName); 1251 1252 Map permissionMap = resAcls.getPermissionMap(); 1253 CmsPermissionSet resPermission = (CmsPermissionSet)permissionMap.get(principal); 1254 if (resPermission != null) { 1255 if (!resPermission.equals(permission)) { 1256 fail("[Permission set not equal " + principal + ":" + permission + " != " + resPermission + "]"); 1257 } 1258 } else { 1259 fail("[Permission set not found " + principal + ":" + permission + "]"); 1260 } 1261 } 1262 } catch (Exception e) { 1263 fail("cannot read resource " + resourceName + " " + e.getMessage()); 1264 } 1265 } 1266 1267 1274 public void assertContains(String content, String pattern) { 1275 1276 if (content.toLowerCase().indexOf(pattern.toLowerCase()) == -1) { 1277 fail("pattern '" + pattern + "' not found in content"); 1278 } 1279 } 1280 1281 1288 public void assertContainsNot(String content, String pattern) { 1289 1290 if (content.toLowerCase().indexOf(pattern.toLowerCase()) != -1) { 1291 fail("pattern '" + pattern + "' found in content"); 1292 } 1293 } 1294 1295 1302 public void assertContent(CmsObject cms, String resourceName, byte[] content) { 1303 1304 try { 1305 CmsFile file = cms.readFile(resourceName, CmsResourceFilter.ALL); 1307 1308 byte[] fileContent = file.getContents(); 1309 if (fileContent.length != file.getLength()) { 1310 fail("[Content length stored " + file.getContents().length + " != " + file.getLength() + "]"); 1311 } 1312 if (fileContent.length != content.length) { 1313 fail("[Content length compared " + file.getContents().length + " != " + content.length + "]"); 1314 } 1315 for (int i = 0; i < content.length; i++) { 1316 if (fileContent[i] != content[i]) { 1317 fail("[Content compare failed at index " + i + "]"); 1318 } 1319 } 1320 } catch (CmsException e) { 1321 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1322 } 1323 } 1324 1325 1332 public void assertDateCreated(CmsObject cms, String resourceName, long dateCreated) { 1333 1334 try { 1335 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1337 1338 if (res.getDateCreated() != dateCreated) { 1339 fail("[DateCreated " 1340 + dateCreated 1341 + " i.e. " 1342 + CmsDateUtil.getHeaderDate(dateCreated) 1343 + " != " 1344 + res.getDateCreated() 1345 + " i.e. " 1346 + CmsDateUtil.getHeaderDate(res.getDateCreated()) 1347 + "]"); 1348 1349 } 1350 1351 } catch (CmsException e) { 1352 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1353 } 1354 } 1355 1356 1363 public void assertDateCreatedAfter(CmsObject cms, String resourceName, long dateCreated) { 1364 1365 try { 1366 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1368 1369 if (res.getDateCreated() < dateCreated) { 1370 fail("[DateCreated " 1371 + dateCreated 1372 + " i.e. " 1373 + CmsDateUtil.getHeaderDate(dateCreated) 1374 + " > " 1375 + res.getDateCreated() 1376 + " i.e. " 1377 + CmsDateUtil.getHeaderDate(res.getDateCreated()) 1378 + "]"); 1379 } 1380 1381 } catch (CmsException e) { 1382 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1383 } 1384 } 1385 1386 1393 public void assertDateLastModified(CmsObject cms, String resourceName, long dateLastModified) { 1394 1395 try { 1396 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1398 1399 if (res.getDateLastModified() != dateLastModified) { 1400 fail("[DateLastModified " 1401 + dateLastModified 1402 + " i.e. " 1403 + CmsDateUtil.getHeaderDate(dateLastModified) 1404 + " != " 1405 + res.getDateLastModified() 1406 + " i.e. " 1407 + CmsDateUtil.getHeaderDate(res.getDateLastModified()) 1408 + "]"); 1409 } 1410 1411 } catch (CmsException e) { 1412 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1413 } 1414 } 1415 1416 1423 public void assertDateLastModifiedAfter(CmsObject cms, String resourceName, long dateLastModified) { 1424 1425 try { 1426 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1428 1429 if (res.getDateLastModified() < dateLastModified) { 1430 fail("[DateLastModified " 1431 + dateLastModified 1432 + " i.e. " 1433 + CmsDateUtil.getHeaderDate(dateLastModified) 1434 + " > " 1435 + res.getDateLastModified() 1436 + " i.e. " 1437 + CmsDateUtil.getHeaderDate(res.getDateLastModified()) 1438 + "]"); 1439 } 1440 1441 } catch (CmsException e) { 1442 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1443 } 1444 } 1445 1446 1452 public void assertEquals(CmsException e1, CmsException e2) { 1453 1454 if (e1 == null && e2 == null) { 1455 return; 1456 } 1457 1458 if ((e1 == null && e2 != null) || (e1 != null && e2 == null)) { 1459 fail("Exceptions not equal (not both null)"); 1460 } 1461 1462 if (!(e1.getClass().equals(e2.getClass()))) { 1463 fail("Exception " + e1.toString() + " does not equal " + e2.toString()); 1464 } 1465 1466 if (!(e1.getMessageContainer().getKey().equals(e2.getMessageContainer().getKey()))) { 1467 fail("Exception " + e1.toString() + " does not equal " + e2.toString()); 1468 } 1469 } 1470 1471 1477 public void assertEquals(Document d1, Document d2) { 1478 1479 if (d1 == null && d2 == null) { 1480 return; 1481 } 1482 1483 if ((d1 == null && d2 != null) || (d1 != null && d2 == null)) { 1484 fail("Documents not equal (not both null)"); 1485 } 1486 1487 InternalNodeComparator comparator = new InternalNodeComparator(); 1488 if (comparator.compare((Node)d1, (Node)d2) != 0) { 1489 fail("Comparison of documents failed: " 1490 + "name = " 1491 + d1.getName() 1492 + ", " 1493 + "path = " 1494 + comparator.m_node1.getUniquePath()); 1495 } 1496 } 1497 1498 1506 public void assertFilter(CmsObject cms, CmsResource resource, OpenCmsTestResourceFilter filter) { 1507 1508 try { 1509 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resource.getRootPath()); 1511 1512 assertFilter(cms, storedResource, resource, filter); 1514 } catch (Exception e) { 1515 fail("cannot read resource " + resource.getRootPath() + " " + e.getMessage()); 1516 } 1517 } 1518 1519 1527 public void assertFilter( 1528 CmsObject cms, 1529 OpenCmsTestResourceStorageEntry storedResource, 1530 CmsResource res, 1531 OpenCmsTestResourceFilter filter) { 1532 1533 String noMatches = null; 1534 String resourceName = null; 1535 1536 try { 1537 noMatches = ""; 1538 resourceName = cms.getRequestContext().removeSiteRoot(res.getRootPath()); 1539 1540 if (filter.testContents()) { 1542 byte[] contents; 1543 if (res.isFile()) { 1545 contents = cms.readFile(resourceName, CmsResourceFilter.ALL).getContents(); 1546 if (!new String (storedResource.getContents()).equals(new String (contents))) { 1547 noMatches += "[Content does not match]\n"; 1548 } 1549 contents = null; 1550 } 1551 } 1552 if (filter.testDateCreated()) { 1554 if (storedResource.getDateCreated() != res.getDateCreated()) { 1555 noMatches += "[DateCreated " 1556 + storedResource.getDateCreated() 1557 + " i.e. " 1558 + CmsDateUtil.getHeaderDate(storedResource.getDateCreated()) 1559 + " != " 1560 + res.getDateCreated() 1561 + " i.e. " 1562 + CmsDateUtil.getHeaderDate(res.getDateCreated()) 1563 + "]\n"; 1564 } 1565 } 1566 if (filter.testDateExpired()) { 1568 if (storedResource.getDateExpired() != res.getDateExpired()) { 1569 noMatches += "[DateExpired " 1570 + storedResource.getDateExpired() 1571 + " i.e. " 1572 + CmsDateUtil.getHeaderDate(storedResource.getDateExpired()) 1573 + " != " 1574 + res.getDateExpired() 1575 + " i.e. " 1576 + CmsDateUtil.getHeaderDate(res.getDateExpired()) 1577 + "]\n"; 1578 } 1579 } 1580 if (filter.testDateLastModified()) { 1582 if (storedResource.getDateLastModified() != res.getDateLastModified()) { 1583 noMatches += "[DateLastModified " 1584 + storedResource.getDateLastModified() 1585 + " i.e. " 1586 + CmsDateUtil.getHeaderDate(storedResource.getDateLastModified()) 1587 + " != " 1588 + res.getDateLastModified() 1589 + " i.e. " 1590 + CmsDateUtil.getHeaderDate(res.getDateLastModified()) 1591 + "]\n"; 1592 } 1593 } 1594 if (filter.testDateReleased()) { 1596 if (storedResource.getDateReleased() != res.getDateReleased()) { 1597 noMatches += "[DateReleased " 1598 + storedResource.getDateReleased() 1599 + " i.e. " 1600 + CmsDateUtil.getHeaderDate(storedResource.getDateReleased()) 1601 + " != " 1602 + res.getDateReleased() 1603 + " i.e. " 1604 + CmsDateUtil.getHeaderDate(res.getDateReleased()) 1605 + "]\n"; 1606 } 1607 } 1608 if (filter.testFlags()) { 1610 if (storedResource.getFlags() != res.getFlags()) { 1611 noMatches += "[Flags " + storedResource.getFlags() + " != " + res.getFlags() + "]\n"; 1612 } 1613 } 1614 if (filter.testLength()) { 1616 if (storedResource.getLength() != res.getLength()) { 1617 noMatches += "[Length " + storedResource.getLength() + " != " + res.getLength() + "]\n"; 1618 } 1619 } 1620 if (filter.testSiblingCount()) { 1622 if (storedResource.getSiblingCount() != res.getSiblingCount()) { 1623 noMatches += "[SiblingCount " 1624 + storedResource.getSiblingCount() 1625 + " != " 1626 + res.getSiblingCount() 1627 + "]\n"; 1628 } 1629 } 1630 if (filter.testLock()) { 1632 CmsLock resLock = cms.getLock(res); 1633 if (!storedResource.getLock().equals(resLock)) { 1634 noMatches += "[Lockstate " + storedResource.getLock() + " != " + resLock + "]\n"; 1635 } 1636 } 1637 if (filter.testName()) { 1639 if (!storedResource.getName().equals(res.getName())) { 1640 noMatches += "[Name " + storedResource.getName() + " != " + res.getName() + "]\n"; 1641 } 1642 } 1643 if (filter.testProjectLastModified()) { 1645 if (storedResource.getProjectLastModified() != res.getProjectLastModified()) { 1646 noMatches += "[ProjectLastModified " 1647 + storedResource.getProjectLastModified() 1648 + " != " 1649 + res.getProjectLastModified() 1650 + "]\n"; 1651 } 1652 } 1653 if (filter.testProperties()) { 1655 noMatches += compareProperties(cms, resourceName, storedResource, null); 1656 } 1657 if (filter.testAcl()) { 1659 noMatches += compareAccessLists(cms, resourceName, storedResource, null); 1661 } 1662 if (filter.testAce()) { 1664 noMatches += compareAccessEntries(cms, resourceName, storedResource, null); 1666 } 1667 if (filter.testResourceId()) { 1669 if (!storedResource.getResourceId().equals(res.getResourceId())) { 1670 noMatches += "[ResourceId " + storedResource.getResourceId() + " != " + res.getResourceId() + "]\n"; 1671 } 1672 } 1673 if (filter.testState()) { 1675 if (storedResource.getState() != res.getState()) { 1676 noMatches += "[State " + storedResource.getState() + " != " + res.getState() + "]\n"; 1677 } 1678 } 1679 if (filter.testStructureId()) { 1681 if (!storedResource.getStructureId().equals(res.getStructureId())) { 1682 noMatches += "[StructureId " 1683 + storedResource.getStructureId() 1684 + " != " 1685 + res.getStructureId() 1686 + "]\n"; 1687 } 1688 } 1689 if (filter.testTouched()) { 1691 if (storedResource.isTouched() != res.isTouched()) { 1692 noMatches += "[Touched " + storedResource.isTouched() + " != " + res.isTouched() + "]\n"; 1693 } 1694 } 1695 if (filter.testType()) { 1697 if (storedResource.getType() != res.getTypeId()) { 1698 noMatches += "[Type " + storedResource.getType() + " != " + res.getTypeId() + "]\n"; 1699 } 1700 } 1701 if (filter.testUserCreated()) { 1703 if (!storedResource.getUserCreated().equals(res.getUserCreated())) { 1704 noMatches += createUserFailMessage( 1705 cms, 1706 "UserCreated", 1707 storedResource.getUserLastModified(), 1708 res.getUserLastModified()); 1709 noMatches += "\n"; 1710 } 1711 } 1712 if (filter.testUserLastModified()) { 1714 if (!storedResource.getUserLastModified().equals(res.getUserLastModified())) { 1715 noMatches += createUserFailMessage( 1716 cms, 1717 "UserLastModified", 1718 storedResource.getUserLastModified(), 1719 res.getUserLastModified()); 1720 noMatches += "\n"; 1721 } 1722 } 1723 1724 if (noMatches.length() > 0) { 1726 fail("error comparing resource " + resourceName + " with stored values:\n" + noMatches); 1727 } 1728 } catch (CmsException e) { 1729 fail("cannot assert filter " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1730 } 1731 } 1732 1733 1741 public void assertFilter(CmsObject cms, String resourceName, OpenCmsTestResourceFilter filter) { 1742 1743 try { 1744 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 1746 1747 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1749 1750 assertFilter(cms, storedResource, res, filter); 1752 } catch (Exception e) { 1753 fail("cannot read resource " + resourceName + " " + e.getMessage()); 1754 } 1755 } 1756 1757 1765 public void assertFilter(CmsObject cms, String resourceName1, String resourceName2, OpenCmsTestResourceFilter filter) { 1766 1767 try { 1768 CmsResource res1 = cms.readResource(resourceName1, CmsResourceFilter.ALL); 1769 CmsResource res2 = cms.readResource(resourceName2, CmsResourceFilter.ALL); 1770 1771 OpenCmsTestResourceStorageEntry dummy = new OpenCmsTestResourceStorageEntry(cms, resourceName2, res2); 1773 1774 assertFilter(cms, dummy, res1, filter); 1775 } catch (CmsException e) { 1776 fail("cannot read either resource " 1777 + resourceName1 1778 + " or resource " 1779 + resourceName2 1780 + " " 1781 + CmsException.getStackTraceAsString(e)); 1782 } 1783 } 1784 1785 1792 public void assertFlags(CmsObject cms, String resourceName, int flag) { 1793 1794 try { 1795 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1797 1798 if (!((res.getFlags() & flag) > 0)) { 1800 fail("[Flags (" + res.getFlags() + ") do not contain flag (" + flag + ")"); 1801 } 1802 } catch (CmsException e) { 1803 fail("Error reading resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1804 } 1805 } 1806 1807 1813 public void assertIsFolder(CmsObject cms, String resourceName) { 1814 1815 try { 1816 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1818 1819 if (!res.isFolder()) { 1820 fail("[Not a folder: " + resourceName + "]"); 1821 } 1822 if (res.getLength() != -1) { 1823 fail("[Folder length not -1: " + resourceName + "]"); 1824 } 1825 } catch (CmsException e) { 1826 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1827 } 1828 } 1829 1830 1836 public void assertIsIdentical(Object o1, Object o2) { 1837 1838 if (o1 != o2) { 1839 fail("Object " + o1.toString() + " is not identical to " + o2.toString()); 1840 } 1841 } 1842 1843 1849 public void assertIsNotIdentical(Object o1, Object o2) { 1850 1851 if (o1 == o2) { 1852 fail("Object " + o1.toString() + " is identical to " + o2.toString()); 1853 } 1854 } 1855 1856 1862 public void assertLock(CmsObject cms, String resourceName) { 1863 1864 try { 1865 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1867 CmsLock lock = cms.getLock(res); 1868 1869 if (lock.isNullLock() || !lock.getUserId().equals(cms.getRequestContext().currentUser().getId())) { 1870 fail("[Lock " 1871 + resourceName 1872 + " requires must be locked to user " 1873 + cms.getRequestContext().currentUser().getId() 1874 + "]"); 1875 } 1876 } catch (CmsException e) { 1877 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1878 } 1879 } 1880 1881 1893 public void assertLock(CmsObject cms, String resourceName, int lockType) { 1894 1895 try { 1896 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1898 CmsLock lock = cms.getLock(res); 1899 1900 if (lockType == CmsLock.TYPE_UNLOCKED) { 1901 if (!lock.isNullLock()) { 1902 fail("[Lock " + resourceName + " must be unlocked]"); 1903 } 1904 } else if (lock.isNullLock() 1905 || lock.getType() != lockType 1906 || !lock.getUserId().equals(cms.getRequestContext().currentUser().getId())) { 1907 fail("[Lock " 1908 + resourceName 1909 + " requires a lock of type " 1910 + lockType 1911 + " for user " 1912 + cms.getRequestContext().currentUser().getId() 1913 + " but has a lock of type " 1914 + lock.getType() 1915 + " for user " 1916 + lock.getUserId() 1917 + "]"); 1918 } 1919 } catch (CmsException e) { 1920 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1921 } 1922 } 1923 1924 1932 public void assertModifiedInCurrentProject(CmsObject cms, String resourceName, boolean shouldHaveRedFlag) { 1933 1934 boolean hasRedFlag = false; 1935 1936 try { 1937 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1939 1940 hasRedFlag = (res.getState() != CmsResource.STATE_UNCHANGED); 1942 hasRedFlag &= (res.getProjectLastModified() == cms.getRequestContext().currentProject().getId()); 1944 hasRedFlag &= (res.getUserLastModified().equals(cms.getRequestContext().currentUser().getId())); 1946 1947 if (shouldHaveRedFlag && !hasRedFlag) { 1948 fail("[HasRedFlag " + resourceName + " must have a red flag]"); 1950 } else if (hasRedFlag && !shouldHaveRedFlag) { 1951 fail("[HasRedFlag " + resourceName + " must not have a red flag]"); 1953 } 1954 } catch (CmsException e) { 1955 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1956 } 1957 } 1958 1959 1966 public void assertProject(CmsObject cms, String resourceName, CmsProject project) { 1967 1968 try { 1969 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 1971 1972 if (res.getProjectLastModified() != project.getId()) { 1973 fail("[ProjectLastModified " + project.getId() + " != " + res.getProjectLastModified() + "]"); 1974 } 1975 1976 } catch (CmsException e) { 1977 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 1978 } 1979 } 1980 1981 1988 public void assertPropertyChanged(CmsObject cms, String resourceName, CmsProperty property) { 1989 1990 try { 1991 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 1993 1994 List excludeList = new ArrayList (); 1996 excludeList.add(property); 1997 1998 String noMatches = compareProperties(cms, resourceName, storedResource, excludeList); 1999 2000 if (noMatches.length() > 0) { 2002 fail("error comparing resource " + resourceName + " with stored values: " + noMatches); 2003 } 2004 2005 List storedProperties = storedResource.getProperties(); 2007 if (!storedProperties.contains(property)) { 2008 fail("property not found in stored value: " + property); 2009 } 2010 2011 CmsProperty resourceProperty = cms.readPropertyObject(resourceName, property.getName(), false); 2013 if (!resourceProperty.isIdentical(property)) { 2014 fail("property is not identical :" + property + " != " + resourceProperty); 2015 } 2016 } catch (Exception e) { 2017 fail("cannot read resource " + resourceName + " " + e.getMessage()); 2018 } 2019 } 2020 2021 2028 public void assertPropertyChanged(CmsObject cms, String resourceName, List excludeList) { 2029 2030 try { 2031 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 2033 2034 String noMatches = compareProperties(cms, resourceName, storedResource, excludeList); 2035 2036 if (noMatches.length() > 0) { 2038 fail("error comparing resource " + resourceName + " with stored values: " + noMatches); 2039 } 2040 2041 2044 String propertyNoMatches = ""; 2045 String storedNotFound = ""; 2046 Iterator i = excludeList.iterator(); 2047 List storedProperties = storedResource.getProperties(); 2048 while (i.hasNext()) { 2049 CmsProperty property = (CmsProperty)i.next(); 2050 CmsProperty resourceProperty = cms.readPropertyObject(resourceName, property.getName(), false); 2051 if (!resourceProperty.isIdentical(property)) { 2053 propertyNoMatches += "[" + property + " != " + resourceProperty + "]"; 2054 } 2055 if (!storedProperties.contains(property)) { 2057 storedNotFound += "[" + property + "]"; 2058 } 2059 } 2060 if (propertyNoMatches.length() > 0) { 2062 fail("error comparing properties for resource " + resourceName + ": " + propertyNoMatches); 2063 } 2064 if (storedNotFound.length() > 0) { 2066 fail("properties not found in stored value: " + storedNotFound); 2067 } 2068 } catch (Exception e) { 2069 fail("cannot read resource " + resourceName + " " + e.getMessage()); 2070 } 2071 } 2072 2073 2079 public void assertPropertydefinitionExist(CmsObject cms, CmsPropertyDefinition propertyDefinition) { 2080 2081 try { 2082 CmsPropertyDefinition prop = cms.readPropertyDefinition(propertyDefinition.getName()); 2083 if (prop != null) { 2084 if (!prop.getName().equals(propertyDefinition.getName())) { 2085 fail("propertsdefinitions do not match: " + prop + " != " + propertyDefinition); 2086 } 2087 } else { 2088 fail("cannot read propertydefitnion" + propertyDefinition); 2089 } 2090 } catch (CmsException e) { 2091 fail("cannot read propertydefitnion" + propertyDefinition + " " + CmsException.getStackTraceAsString(e)); 2092 } 2093 } 2094 2095 2102 public void assertPropertydefinitions(CmsObject cms, List propertyDefintions, CmsPropertyDefinition exclude) { 2103 2104 try { 2105 String noMatches = ""; 2106 List allPropertydefintions = cms.readAllPropertyDefinitions(); 2107 noMatches += comparePropertydefintions(propertyDefintions, allPropertydefintions, exclude); 2108 noMatches += comparePropertydefintions(allPropertydefintions, propertyDefintions, exclude); 2109 if (noMatches.length() > 0) { 2110 fail("missig propertydefintions: " + noMatches); 2111 } 2112 } catch (CmsException e) { 2113 fail("cannot read propertydefitnions " + CmsException.getStackTraceAsString(e)); 2114 } 2115 } 2116 2117 2123 public void assertPropertyEqual(CmsObject cms, String resourceName) { 2124 2125 try { 2126 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 2128 String noMatches = compareProperties(cms, resourceName, storedResource, null); 2129 2130 if (noMatches.length() > 0) { 2132 fail("error comparing resource " + resourceName + " with stored values: " + noMatches); 2133 } 2134 2135 } catch (Exception e) { 2136 fail("cannot read resource " + resourceName + " " + e.getMessage()); 2137 } 2138 } 2139 2140 2147 public void assertPropertyNew(CmsObject cms, String resourceName, CmsProperty property) { 2148 2149 try { 2150 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 2152 2153 List excludeList = new ArrayList (); 2155 excludeList.add(property); 2156 2157 String noMatches = compareProperties(cms, resourceName, storedResource, excludeList); 2158 2159 if (noMatches.length() > 0) { 2161 fail("error comparing resource " + resourceName + " with stored values: " + noMatches); 2162 } 2163 2164 List storedProperties = storedResource.getProperties(); 2166 if (storedProperties.contains(property)) { 2167 fail("property already found in stored value: " + property); 2168 } 2169 2170 CmsProperty resourceProperty = cms.readPropertyObject(resourceName, property.getName(), false); 2172 if (!resourceProperty.isIdentical(property)) { 2173 fail("property is not identical :" + property + " != " + resourceProperty); 2174 } 2175 } catch (Exception e) { 2176 fail("cannot read resource " + resourceName + " " + e.getMessage()); 2177 } 2178 } 2179 2180 2187 public void assertPropertyNew(CmsObject cms, String resourceName, List excludeList) { 2188 2189 try { 2190 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 2192 2193 String noMatches = compareProperties(cms, resourceName, storedResource, excludeList); 2194 2195 if (noMatches.length() > 0) { 2197 fail("error comparing resource " + resourceName + " with stored values: " + noMatches); 2198 } 2199 2200 2203 String propertyNoMatches = ""; 2204 String storedFound = ""; 2205 Iterator i = excludeList.iterator(); 2206 List storedProperties = storedResource.getProperties(); 2207 while (i.hasNext()) { 2208 CmsProperty property = (CmsProperty)i.next(); 2209 CmsProperty resourceProperty = cms.readPropertyObject(resourceName, property.getName(), false); 2210 if (!resourceProperty.isIdentical(property)) { 2212 propertyNoMatches += "[" + property + " != " + resourceProperty + "]"; 2213 } 2214 if (storedProperties.contains(property)) { 2216 storedFound += "[" + property + "]"; 2217 } 2218 } 2219 if (propertyNoMatches.length() > 0) { 2221 fail("error comparing properties for resource " + resourceName + ": " + propertyNoMatches); 2222 } 2223 if (storedFound.length() > 0) { 2225 fail("properties already found in stored value: " + storedFound); 2226 } 2227 } catch (Exception e) { 2228 fail("cannot read resource " + resourceName + " " + e.getMessage()); 2229 } 2230 } 2231 2232 2239 public void assertPropertyRemoved(CmsObject cms, String resourceName, CmsProperty property) { 2240 2241 try { 2242 2243 List excludeList = new ArrayList (); 2245 excludeList.add(property); 2246 2247 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 2249 2250 String noMatches = compareProperties(cms, resourceName, storedResource, excludeList); 2251 2252 if (noMatches.length() > 0) { 2254 fail("error comparing resource " + resourceName + " with stored values: " + noMatches); 2255 } 2256 2257 List storedProperties = storedResource.getProperties(); 2259 if (!storedProperties.contains(property)) { 2260 fail("property not found in stored value: " + property); 2261 } 2262 2263 CmsProperty resourceProperty = cms.readPropertyObject(resourceName, property.getName(), false); 2265 if (resourceProperty != CmsProperty.getNullProperty()) { 2266 fail("property is not removed :" + property + " != " + resourceProperty); 2267 } 2268 } catch (Exception e) { 2269 fail("cannot read resource " + resourceName + " " + e.getMessage()); 2270 } 2271 } 2272 2273 2280 public void assertPropertyRemoved(CmsObject cms, String resourceName, List excludeList) { 2281 2282 try { 2283 OpenCmsTestResourceStorageEntry storedResource = m_currentResourceStrorage.get(resourceName); 2285 2286 String noMatches = compareProperties(cms, resourceName, storedResource, excludeList); 2287 2288 if (noMatches.length() > 0) { 2290 fail("error comparing resource " + resourceName + " with stored values: " + noMatches); 2291 } 2292 2293 2296 String propertyNotDeleted = ""; 2297 String storedNotFound = ""; 2298 Iterator i = excludeList.iterator(); 2299 List storedProperties = storedResource.getProperties(); 2300 List resourceProperties = cms.readPropertyObjects(resourceName, false); 2301 2302 while (i.hasNext()) { 2303 CmsProperty property = (CmsProperty)i.next(); 2304 if (resourceProperties.contains(property)) { 2306 CmsProperty resourceProperty = cms.readPropertyObject(resourceName, property.getName(), false); 2307 propertyNotDeleted += "[" + property + " != " + resourceProperty + "]"; 2308 } 2309 if (!storedProperties.contains(property)) { 2311 storedNotFound += "[" + property + "]"; 2312 } 2313 } 2314 if (propertyNotDeleted.length() > 0) { 2316 fail("properties not deleted for " + resourceName + ": " + propertyNotDeleted); 2317 } 2318 if (storedNotFound.length() > 0) { 2320 fail("properties not found in stored value: " + storedNotFound); 2321 } 2322 } catch (Exception e) { 2323 fail("cannot read resource " + resourceName + " " + e.getMessage()); 2324 } 2325 } 2326 2327 2334 public void assertResourceType(CmsObject cms, String resourceName, int resourceType) { 2335 2336 try { 2337 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 2339 2340 if (res.getTypeId() != resourceType) { 2341 fail("[ResourceType " + res.getTypeId() + " != " + resourceType + "]"); 2342 } 2343 } catch (CmsException e) { 2344 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 2345 } 2346 } 2347 2348 2355 public void assertSiblingCount(CmsObject cms, String resourceName, int count) { 2356 2357 try { 2358 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 2360 if (res.getSiblingCount() != count) { 2361 fail("[SiblingCount " + res.getSiblingCount() + " != " + count + "]"); 2362 } 2363 2364 } catch (CmsException e) { 2365 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 2366 } 2367 } 2368 2369 2377 public void assertSiblingCountIncremented(CmsObject cms, String resourceName, int increment) { 2378 2379 try { 2380 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 2382 2383 OpenCmsTestResourceStorageEntry entry = m_currentResourceStrorage.get(resourceName); 2385 2386 if (res.getSiblingCount() != (entry.getSiblingCount() + increment)) { 2387 fail("[SiblingCount " 2388 + res.getSiblingCount() 2389 + " != " 2390 + entry.getSiblingCount() 2391 + "+" 2392 + increment 2393 + "]"); 2394 } 2395 2396 } catch (Exception e) { 2397 fail("cannot read resource " + resourceName + " " + e.getMessage()); 2398 } 2399 } 2400 2401 2408 public void assertState(CmsObject cms, String resourceName, int state) { 2409 2410 try { 2411 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 2413 2414 if (res.getState() != state) { 2415 fail("[State " + state + " != " + res.getState() + "]"); 2416 } 2417 2418 } catch (CmsException e) { 2419 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 2420 } 2421 } 2422 2423 2430 public void assertType(CmsObject cms, String resourceName, int type) { 2431 2432 try { 2433 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 2435 2436 if (res.getTypeId() != type) { 2437 fail("[State " + type + " != " + res.getTypeId() + "]"); 2438 } 2439 2440 } catch (CmsException e) { 2441 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 2442 } 2443 } 2444 2445 2452 public void assertUserCreated(CmsObject cms, String resourceName, CmsUser user) { 2453 2454 try { 2455 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 2457 2458 if (!res.getUserCreated().equals(user.getId())) { 2459 fail(createUserFailMessage(cms, "UserCreated", user.getId(), res.getUserLastModified())); 2460 } 2461 2462 } catch (CmsException e) { 2463 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 2464 } 2465 } 2466 2467 2474 public void assertUserLastModified(CmsObject cms, String resourceName, CmsUser user) { 2475 2476 try { 2477 CmsResource res = cms.readResource(resourceName, CmsResourceFilter.ALL); 2479 2480 if (!res.getUserLastModified().equals(user.getId())) { 2481 fail(createUserFailMessage(cms, "UserLastModified", user.getId(), res.getUserLastModified())); 2482 } 2483 2484 } catch (CmsException e) { 2485 fail("cannot read resource " + resourceName + " " + CmsException.getStackTraceAsString(e)); 2486 } 2487 } 2488 2489 2493 public void createStorage(String name) { 2494 2495 OpenCmsTestResourceStorage storage = new OpenCmsTestResourceStorage(name); 2496 m_resourceStorages.put(name, storage); 2497 } 2498 2499 2504 public String getDatabaseProduct() { 2505 2506 return m_dbProduct; 2507 } 2508 2509 2516 public int getPreCalculatedState(String resourceName) throws Exception { 2517 2518 return m_currentResourceStrorage.getPreCalculatedState(resourceName); 2519 } 2520 2521 2524 public void resetMapping() { 2525 2526 m_currentResourceStrorage.resetMapping(); 2527 } 2528 2529 2535 public void setMapping(String source, String target) { 2536 2537 m_currentResourceStrorage.setMapping(source, target); 2538 } 2539 2540 2549 public void storeResources(CmsObject cms, String resourceName) { 2550 2551 storeResources(cms, resourceName, true); 2552 } 2553 2554 2565 public void storeResources(CmsObject cms, String resourceName, boolean storeSubresources) { 2566 2567 String resName = ""; 2568 2569 try { 2570 CmsResource resource = cms.readResource(resourceName, CmsResourceFilter.ALL); 2571 if (resource.isFile()) { 2573 m_currentResourceStrorage.add(cms, resourceName, resource); 2574 } else { 2575 m_currentResourceStrorage.add(cms, resourceName 2577 + (resourceName.charAt(resourceName.length() - 1) != '/' ? "/" : ""), resource); 2578 2579 if (!storeSubresources) { 2580 return; 2581 } 2582 2583 List resources = cms.readResources(resourceName, CmsResourceFilter.ALL); 2585 Iterator i = resources.iterator(); 2586 while (i.hasNext()) { 2587 CmsResource res = (CmsResource)i.next(); 2588 resName = cms.getSitePath(res); 2589 m_currentResourceStrorage.add(cms, resName, res); 2590 } 2591 } 2592 } catch (CmsException e) { 2593 fail("cannot read resource " 2594 + resourceName 2595 + " or " 2596 + resName 2597 + " " 2598 + CmsException.getStackTraceAsString(e)); 2599 } 2600 } 2601 2602 2607 public void switchStorage(String name) throws CmsException { 2608 2609 OpenCmsTestResourceStorage storage = (OpenCmsTestResourceStorage)m_resourceStorages.get(name); 2610 if (storage != null) { 2611 m_currentResourceStrorage = storage; 2612 } else { 2613 throw new CmsException(Messages.get().container(Messages.ERR_RESOURCE_STORAGE_NOT_FOUND_0)); 2614 } 2615 } 2616 2617 2622 protected void echo(String message) { 2623 2624 try { 2625 System.out.println(); 2626 m_shell.printPrompt(); 2627 System.out.println(message); 2628 } catch (Throwable t) { 2629 throw new RuntimeException (t); 2630 } 2631 } 2632 2633 2640 protected CmsObject getCmsObject() throws CmsException { 2641 2642 CmsObject cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); 2644 cms.loginUser("Admin", "admin"); 2645 cms.getRequestContext().setCurrentProject(cms.readProject("Offline")); 2647 cms.getRequestContext().setSiteRoot("/sites/default/"); 2648 2649 createStorage(OpenCmsTestResourceStorage.DEFAULT_STORAGE); 2651 switchStorage(OpenCmsTestResourceStorage.DEFAULT_STORAGE); 2652 2653 return cms; 2655 } 2656 2657 2661 protected void removeStorage(String name) { 2662 2663 OpenCmsTestResourceStorage storage = (OpenCmsTestResourceStorage)m_resourceStorages.get(name); 2664 if (storage != null) { 2665 m_resourceStorages.remove(name); 2666 storage = null; 2667 } 2668 } 2669 2670 2673 protected void restart() { 2674 2675 OpenCmsTestLogAppender.setBreakOnError(false); 2676 2677 System.out.println("\n\n\n----- Restarting shell -----"); 2679 2680 m_shell.exit(); 2681 2682 m_shell = new CmsShell(getTestDataPath("WEB-INF" + File.separator), null, null, "${user}@${project}>", null); 2683 2684 OpenCmsTestLogAppender.setBreakOnError(true); 2685 } 2686 2687 2697 private String compareAccessEntries( 2698 CmsObject cms, 2699 String resourceName, 2700 OpenCmsTestResourceStorageEntry storedResource, 2701 List excludeList) throws CmsException { 2702 2703 String noMatches = ""; 2704 List resAce = cms.getAccessControlEntries(resourceName); 2705 List storedAce = storedResource.getAccessControlEntries(); 2706 List unmatchedAce; 2707 unmatchedAce = compareAce(resAce, storedAce, excludeList); 2708 if (unmatchedAce.size() > 0) { 2709 noMatches += "[ACE missing " + unmatchedAce.toString() + "]\n"; 2710 } 2711 unmatchedAce = compareAce(storedAce, resAce, excludeList); 2712 if (unmatchedAce.size() > 0) { 2713 noMatches += "[ACE missing " + unmatchedAce.toString() + "]\n"; 2714 } 2715 return noMatches; 2716 } 2717 2718 2728 private String compareAccessLists( 2729 CmsObject cms, 2730 String resourceName, 2731 OpenCmsTestResourceStorageEntry storedResource, 2732 List excludeList) throws CmsException { 2733 2734 String noMatches = ""; 2735 CmsAccessControlList resList = cms.getAccessControlList(resourceName); 2736 CmsAccessControlList storedList = storedResource.getAccessControlList(); 2737 List unmatchedList; 2738 unmatchedList = compareList(resList, storedList, excludeList); 2739 if (unmatchedList.size() > 0) { 2740 noMatches += "[ACL differences " + unmatchedList.toString() + "]\n"; 2741 } 2742 unmatchedList = compareList(storedList, resList, excludeList); 2743 if (unmatchedList.size() > 0) { 2744 noMatches += "[ACL differences " + unmatchedList.toString() + "]\n"; 2745 } 2746 return noMatches; 2747 } 2748 2749 2757 private List compareAce(List source, List target, List exclude) { 2758 2759 List result = new ArrayList (); 2760 Iterator i = source.iterator(); 2761 while (i.hasNext()) { 2762 CmsAccessControlEntry ace = (CmsAccessControlEntry)i.next(); 2763 if (!target.contains(ace)) { 2764 result.add(ace); 2765 } 2766 } 2767 if (exclude != null) { 2769 Iterator l = exclude.iterator(); 2770 while (l.hasNext()) { 2771 CmsAccessControlEntry excludeAce = (CmsAccessControlEntry)l.next(); 2772 if (result.contains(excludeAce)) { 2773 result.remove(excludeAce); 2774 } 2775 } 2776 } 2777 return result; 2778 } 2779 2780 2787 private List compareList(CmsAccessControlList source, CmsAccessControlList target, List exclude) { 2788 2789 HashMap result = new HashMap (); 2790 2791 HashMap destinationMap = target.getPermissionMap(); 2792 HashMap sourceMap = source.getPermissionMap(); 2793 2794 Iterator i = sourceMap.keySet().iterator(); 2795 while (i.hasNext()) { 2796 CmsUUID key = (CmsUUID)i.next(); 2797 CmsPermissionSet value = (CmsPermissionSet)sourceMap.get(key); 2798 if (destinationMap.containsKey(key)) { 2799 CmsPermissionSet destValue = (CmsPermissionSet)destinationMap.get(key); 2800 if (!destValue.equals(value)) { 2801 result.put(key, key + " " + value + " != " + destValue); 2802 } 2803 } else { 2804 result.put(key, "missing " + key); 2805 } 2806 } 2807 2808 if (exclude != null) { 2810 Iterator l = exclude.iterator(); 2811 while (l.hasNext()) { 2812 CmsUUID excludeUUID = (CmsUUID)l.next(); 2813 if (result.containsKey(excludeUUID)) { 2814 result.remove(excludeUUID); 2815 } 2816 } 2817 } 2818 return new ArrayList (result.values()); 2819 } 2820 2821 2828 private String comparePropertydefintions(List source, List target, CmsPropertyDefinition exclude) { 2829 2830 String noMatches = ""; 2831 Iterator i = source.iterator(); 2832 while (i.hasNext()) { 2833 CmsPropertyDefinition prop = (CmsPropertyDefinition)i.next(); 2834 if ((!target.contains(prop)) && (!prop.getName().equals(exclude.getName()))) { 2835 noMatches += "[" + prop + "]"; 2836 } 2837 } 2838 return noMatches; 2839 } 2840 2841 2852 private String createUserFailMessage(CmsObject cms, String message, CmsUUID user1, CmsUUID user2) 2853 throws CmsException { 2854 2855 StringBuffer result = new StringBuffer (); 2856 result.append("["); 2857 result.append(message); 2858 result.append(" ("); 2859 result.append(cms.readUser(user1).getName()); 2860 result.append(") "); 2861 result.append(user1); 2862 result.append(" != ("); 2863 result.append(cms.readUser(user2).getName()); 2864 result.append(") "); 2865 result.append(user1); 2866 result.append("]"); 2867 return result.toString(); 2868 } 2869 2870 2878 private Map getParents(CmsObject cms, String resourceName) { 2879 2880 HashMap parents = new HashMap (); 2881 List parentResources = new ArrayList (); 2882 try { 2883 parentResources = cms.readPath(resourceName, CmsResourceFilter.IGNORE_EXPIRATION); 2885 } catch (CmsException e) { 2886 } 2888 Iterator k = parentResources.iterator(); 2889 while (k.hasNext()) { 2890 CmsResource curRes = (CmsResource)k.next(); 2892 parents.put(curRes.getResourceId(), curRes.getRootPath()); 2893 } 2894 return parents; 2895 } 2896 2897 2901 private void initConfiguration() { 2902 2903 if (m_configuration == null) { 2904 initTestDataPath(); 2905 m_configuration = OpenCmsTestProperties.getInstance().getConfiguration(); 2906 m_dbProduct = OpenCmsTestProperties.getInstance().getDbProduct(); 2907 int index = 0; 2908 boolean cont; 2909 do { 2910 cont = false; 2911 if (m_configuration.containsKey("test.data.path." + index)) { 2912 addTestDataPath(m_configuration.getString("test.data.path." + index)); 2913 cont = true; 2914 index++; 2915 } 2916 } while (cont); 2917 2918 try { 2919 String propertyFile = getTestDataPath("WEB-INF/config." + m_dbProduct + "/opencms.properties"); 2920 m_configuration = CmsPropertyUtils.loadProperties(propertyFile); 2921 } catch (IOException e) { 2922 fail(e.toString()); 2923 return; 2924 } 2925 2926 String key = "setup"; 2927 m_setupConnection = new ConnectionData(); 2928 m_setupConnection.m_dbName = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2929 + "." 2930 + key 2931 + "." 2932 + "dbName"); 2933 m_setupConnection.m_jdbcUrl = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2934 + "." 2935 + key 2936 + "." 2937 + "jdbcUrl"); 2938 m_setupConnection.m_userName = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2939 + "." 2940 + key 2941 + "." 2942 + "user"); 2943 m_setupConnection.m_userPassword = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2944 + "." 2945 + key 2946 + "." 2947 + "password"); 2948 m_setupConnection.m_jdbcDriver = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2949 + "." 2950 + key 2951 + "." 2952 + CmsDbPool.KEY_JDBC_DRIVER); 2953 m_setupConnection.m_jdbcUrl = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2954 + "." 2955 + key 2956 + "." 2957 + CmsDbPool.KEY_JDBC_URL); 2958 m_setupConnection.m_jdbcUrlParams = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2959 + "." 2960 + key 2961 + "." 2962 + CmsDbPool.KEY_JDBC_URL_PARAMS); 2963 2964 key = "default"; 2965 m_defaultConnection = new ConnectionData(); 2966 m_defaultConnection.m_dbName = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2967 + "." 2968 + key 2969 + "." 2970 + "dbName"); 2971 m_defaultConnection.m_userName = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2972 + "." 2973 + key 2974 + "." 2975 + CmsDbPool.KEY_USERNAME); 2976 m_defaultConnection.m_userPassword = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2977 + "." 2978 + key 2979 + "." 2980 + CmsDbPool.KEY_PASSWORD); 2981 m_defaultConnection.m_jdbcDriver = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2982 + "." 2983 + key 2984 + "." 2985 + CmsDbPool.KEY_JDBC_DRIVER); 2986 m_defaultConnection.m_jdbcUrl = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2987 + "." 2988 + key 2989 + "." 2990 + CmsDbPool.KEY_JDBC_URL); 2991 m_defaultConnection.m_jdbcUrlParams = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 2992 + "." 2993 + key 2994 + "." 2995 + CmsDbPool.KEY_JDBC_URL_PARAMS); 2996 2997 key = m_additionalConnectionName; 2998 if (m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL + "." + key + "." + "dbName") != null) { 2999 m_additionalConnection = new ConnectionData(); 3000 m_additionalConnection.m_dbName = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 3001 + "." 3002 + key 3003 + "." 3004 + "dbName"); 3005 m_additionalConnection.m_userName = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 3006 + "." 3007 + key 3008 + "." 3009 + CmsDbPool.KEY_USERNAME); 3010 m_additionalConnection.m_userPassword = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 3011 + "." 3012 + key 3013 + "." 3014 + CmsDbPool.KEY_PASSWORD); 3015 m_additionalConnection.m_jdbcDriver = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 3016 + "." 3017 + key 3018 + "." 3019 + CmsDbPool.KEY_JDBC_DRIVER); 3020 m_additionalConnection.m_jdbcUrl = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 3021 + "." 3022 + key 3023 + "." 3024 + CmsDbPool.KEY_JDBC_URL); 3025 m_additionalConnection.m_jdbcUrlParams = m_configuration.getString(CmsDbPool.KEY_DATABASE_POOL 3026 + "." 3027 + key 3028 + "." 3029 + CmsDbPool.KEY_JDBC_URL_PARAMS); 3030 } 3031 3032 m_defaultTablespace = m_configuration.getString("db.oracle.defaultTablespace"); 3033 m_indexTablespace = m_configuration.getString("db.oracle.indexTablespace"); 3034 m_tempTablespace = m_configuration.getString("db.oracle.temporaryTablespace"); 3035 3036 System.out.println("----- Starting tests on database " 3037 + m_dbProduct 3038 + " (" 3039 + m_setupConnection.m_jdbcUrl 3040 + ") " 3041 + "-----"); 3042 } 3043 } 3044 3045} | Popular Tags |