1 31 32 package org.opencms.setup; 33 34 import org.opencms.main.CmsSystemInfo; 35 import org.opencms.test.OpenCmsTestCase; 36 37 import java.io.File ; 38 import java.io.IOException ; 39 import java.util.Iterator ; 40 import java.util.Vector ; 41 42 import org.apache.commons.collections.ExtendedProperties; 43 44 51 public class TestCmsSetupBean extends OpenCmsTestCase { 52 53 56 59 64 public TestCmsSetupBean(String arg0) { 65 66 super(arg0); 67 } 68 69 74 public void testSaveProperties() throws IOException { 75 76 CmsSetupBean bean = new CmsSetupBean(); 77 bean.init("", null, null); 78 79 String base = getTestDataPath(File.separator + "WEB-INF" + File.separator + CmsSystemInfo.FOLDER_CONFIG); 80 String inputFile = base + CmsSystemInfo.FILE_PROPERTIES; 81 String outputFile = base + "output.properties"; 82 83 System.out.println("Reading properties from " + inputFile); 84 ExtendedProperties oldProperties = bean.loadProperties(inputFile); 85 86 System.out.println("Writing properties to " + outputFile); 87 bean.copyFile(inputFile, outputFile); 88 bean.saveProperties(oldProperties, outputFile, false); 89 90 System.out.println("Checking properties from " + outputFile); 91 ExtendedProperties newProperties = bean.loadProperties(outputFile); 92 93 for (Iterator i = oldProperties.keySet().iterator(); i.hasNext();) { 94 String key = (String )i.next(); 95 String oldValue = "", newValue = ""; 96 Object obj = oldProperties.get(key); 97 98 if (obj instanceof Vector ) { 99 StringBuffer buf; 100 101 buf = new StringBuffer (); 102 for (Iterator j = ((Vector )obj).iterator(); j.hasNext();) { 103 buf.append("[" + (String )j.next() + "]"); 104 } 105 oldValue = buf.toString(); 106 107 buf = new StringBuffer (); 108 for (Iterator j = ((Vector )newProperties.get(key)).iterator(); j.hasNext();) { 109 buf.append("[" + (String )j.next() + "]"); 110 } 111 newValue = buf.toString(); 112 113 } else { 114 oldValue = (String )obj; 115 newValue = (String )newProperties.get(key); 116 } 117 System.out.println(key); 118 System.out.println(oldValue); 119 System.out.println(newValue); 120 System.out.println("---"); 121 assertEquals(oldValue, newValue); 122 } 123 124 File output = new File (outputFile); 126 output.delete(); 127 } 128 } 129 | Popular Tags |