1 19 20 package gui.propertyeditors; 21 22 import gui.propertyeditors.utilities.CoreSupport; 23 24 import org.netbeans.jellytools.properties.editors.FileCustomEditorOperator; 25 import org.netbeans.jellytools.properties.editors.FilesystemCustomEditorOperator; 26 27 import org.netbeans.jemmy.EventTool; 28 29 import org.netbeans.junit.NbTestSuite; 30 31 32 37 public class PropertyType_Filesystem extends PropertyEditorsTest { 38 39 public String propertyName_L; 40 public String propertyValue_L; 41 public String propertyValueExpectation_L; 42 43 public boolean waitDialog = false; 44 45 private final String ADDDIRECTORY = "Add Directory:"; 46 private final String ADDJAR = "Add JAR:"; 47 48 private static String FS_Data_path; 49 private static String FS_Data_path_data_jar; 50 51 52 public PropertyType_Filesystem(String testName) { 53 super(testName); 54 } 55 56 57 public void setUp(){ 58 propertyName_L = "Filesystem"; 59 super.setUp(); 60 } 61 62 public static NbTestSuite suite() { 63 64 String path = ""; 67 68 FS_Data_path = path.substring(0,path.lastIndexOf(System.getProperty("file.separator"))); 69 FS_Data_path_data_jar = FS_Data_path + System.getProperty("file.separator") + "data.jar"; 70 71 NbTestSuite suite = new NbTestSuite(); 72 suite.addTest(new PropertyType_Filesystem("verifyCustomizer")); 73 suite.addTest(new PropertyType_Filesystem("testCustomizerCancel")); 74 suite.addTest(new PropertyType_Filesystem("testCustomizerAddDirectory")); 75 suite.addTest(new PropertyType_Filesystem("testCustomizerAddJar")); 76 return suite; 77 } 78 79 80 public void testCustomizerAddDirectory() { 81 propertyValue_L = ADDDIRECTORY + FS_Data_path; 82 propertyValueExpectation_L = getOSDependentFilesystem(FS_Data_path); 83 waitDialog = false; 84 setByCustomizerOk(propertyName_L, true); 85 } 86 87 public void testCustomizerAddJar() { 88 propertyValue_L = ADDJAR + FS_Data_path_data_jar; 89 propertyValueExpectation_L = FS_Data_path_data_jar; 90 waitDialog = false; 91 setByCustomizerOk(propertyName_L, true); 92 } 93 94 public void testCustomizerCancel(){ 95 propertyValue_L = ADDJAR + FS_Data_path_data_jar; 96 propertyValueExpectation_L = propertyValue_L; 97 waitDialog = false; 98 setByCustomizerCancel(propertyName_L, false); 99 } 100 101 public void verifyCustomizer() { 102 verifyCustomizer(propertyName_L); 103 } 104 105 public void setCustomizerValue() { 106 FilesystemCustomEditorOperator customizer = new FilesystemCustomEditorOperator(propertyCustomizer); 107 108 if(propertyValue_L.startsWith(ADDDIRECTORY)){ 109 err.println("== ADDING DIRECTORY ============"); 110 customizer.addLocalDirectory(); 111 customizer.btBrowse().pushNoBlock(); 112 FileCustomEditorOperator dialog = new FileCustomEditorOperator("Add Local Directory"); 113 dialog.setFileValue(getPath(propertyValue_L, ADDDIRECTORY)); 114 new EventTool().waitNoEvent(500); 115 dialog.ok(); 116 } 118 119 if(propertyValue_L.startsWith(ADDJAR)){ 120 err.println("== ADDING JAR ============"); 121 customizer.addJARFile(); 122 customizer.btBrowse2().pushNoBlock(); 123 FileCustomEditorOperator dialog = new FileCustomEditorOperator("Add JAR File"); 124 dialog.fileChooser().chooseFile(getPath(propertyValue_L, ADDJAR)); 125 } 129 130 131 } 132 133 public void verifyPropertyValue(boolean expectation) { 134 136 if(expectation){ 137 String newValue = getValue(propertyName_L); 138 String log = "Actual value is {"+newValue+"} - set value is {"+propertyValue_L+"} / expectation value is {"+propertyValueExpectation_L+"}"; 139 140 err.println("=========================== Trying to verify value ["+log+"]."); 141 142 if(newValue.indexOf(propertyValueExpectation_L)!=-1) { 143 log(log + " --> PASS"); 144 }else { 145 fail(log + " --> FAIL"); 146 } 147 }else { 148 verifyExpectationValue(propertyName_L,expectation, propertyValueExpectation_L, propertyValue_L, waitDialog); 149 } 150 151 } 152 153 154 private String getPath(String str, String delim) { 155 int index = str.indexOf(delim); 156 157 err.println("============================= Try to set path="+str); 158 159 if(index > -1) 160 return str.substring(index + delim.length()); 161 162 return str; 163 } 164 165 private String getOSDependentFilesystem(String path) { 166 String os = System.getProperty("os.name"); 167 err.println("Os name = {"+os+"}"); 168 169 if(os.indexOf("Win")!=-1) 170 return path.replace('\\','/'); 171 172 return path; 173 } 174 175 public void verifyCustomizerLayout() { 176 FilesystemCustomEditorOperator customizer = new FilesystemCustomEditorOperator(propertyCustomizer); 177 customizer.verify(); 178 customizer.btOK(); 179 customizer.btCancel(); 180 } 181 182 185 public static void main(String [] args) { 186 junit.textui.TestRunner.run(suite()); 188 } 189 190 } 191 | Popular Tags |