1 17 package org.alfresco.web.config; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.util.Map ; 22 23 import org.alfresco.config.Config; 24 import org.alfresco.config.ConfigElement; 25 import org.alfresco.config.ConfigException; 26 import org.alfresco.config.source.FileConfigSource; 27 import org.alfresco.config.xml.XMLConfigService; 28 import org.alfresco.util.BaseTest; 29 import org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty; 30 import org.alfresco.web.config.PropertySheetConfigElement.ItemConfig; 31 32 38 public class WebClientConfigTest extends BaseTest 39 { 40 43 protected void setUp() throws Exception 44 { 45 super.setUp(); 46 } 47 48 51 public void testPropertySheetConfig() 52 { 53 String configFile = getResourcesDir() + "test-config.xml"; 55 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFile)); 56 svc.init(); 57 58 Config global = svc.getGlobalConfig(); 60 ConfigElement globalPropSheet = global.getConfigElement("property-sheet"); 61 assertNotNull("global property sheet element should not be null", globalPropSheet); 62 assertTrue("config element should be an instance of PropertySheetConfigElement", 63 (globalPropSheet instanceof PropertySheetConfigElement)); 64 65 List <String > propNames = ((PropertySheetConfigElement) globalPropSheet).getItemNamesToShow(); 68 assertTrue("There should only be one property in the list", propNames.size() == 1); 69 assertTrue("The property name should be 'name'", propNames.get(0).equals("name")); 70 71 Config spaceAspectConfig = svc.getConfig("space-aspect"); 74 assertNotNull("Space aspect config should not be null", spaceAspectConfig); 75 PropertySheetConfigElement spacePropConfig = (PropertySheetConfigElement) spaceAspectConfig 76 .getConfigElement("property-sheet"); 77 assertNotNull("Space aspect property config should not be null", spacePropConfig); 78 propNames = spacePropConfig.getItemNamesToShow(); 79 assertTrue("There should be 6 properties in the list", propNames.size() == 6); 80 81 Map <String , ItemConfig> props = spacePropConfig.getItemsMapToShow(); 83 ItemConfig descProp = props.get("description"); 84 assertNotNull("description property config should not be null", descProp); 85 assertEquals("display label for description should be 'Description'", descProp.getDisplayLabel(), 86 "Description"); 87 assertFalse("read only for description should be 'false'", descProp.isReadOnly()); 88 89 ItemConfig createdDataProp = props.get("createddate"); 90 assertNotNull("createddate property config should not be null", createdDataProp); 91 assertEquals("display label for createddate should be null", null, createdDataProp.getDisplayLabel()); 92 assertTrue("read only for createddate should be 'true'", createdDataProp.isReadOnly()); 93 94 ItemConfig iconProp = props.get("icon"); 95 assertNotNull("icon property config should not be null", iconProp); 96 assertEquals("display label for icon should be null", null, iconProp.getDisplayLabel()); 97 assertFalse("read only for icon should be 'false'", iconProp.isReadOnly()); 98 } 99 100 104 public void testGenericConfigElement() 105 { 106 String configFiles = getResourcesDir() + "test-config.xml"; 108 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 109 svc.init(); 110 111 Config configProps = svc.getConfig("space-aspect"); 113 ConfigElement propsToDisplay = configProps.getConfigElement("property-sheet"); 114 assertNotNull("property sheet config should not be null", propsToDisplay); 115 116 List <ConfigElement> kids = propsToDisplay.getChildren(); 118 List <String > propNames = new ArrayList <String >(); 119 for (ConfigElement propElement : propsToDisplay.getChildren()) 120 { 121 String value = propElement.getValue(); 122 assertNull("property value should be null", value); 123 String propName = propElement.getAttribute("name"); 124 propNames.add(propName); 125 } 126 127 assertTrue("There should be 6 properties", propNames.size() == 6); 128 assertFalse("The id attribute should not be present", propsToDisplay.hasAttribute("id")); 129 130 assertEquals("showInEditMode", "false", kids.get(5).getAttribute("showInEditMode")); 132 assertEquals("readOnly", "true", kids.get(5).getAttribute("readOnly")); 133 } 134 135 139 public void testGetProperties() 140 { 141 String configFiles = getResourcesDir() + "test-config.xml"; 143 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 144 svc.init(); 145 146 Config configProps = svc.getConfig("space-aspect"); 148 PropertySheetConfigElement propsToDisplay = (PropertySheetConfigElement)configProps. 149 getConfigElement("property-sheet"); 150 assertNotNull("property sheet config should not be null", propsToDisplay); 151 152 List <String > propNames = propsToDisplay.getItemNamesToShow(); 154 155 List <ConfigElement> kids = propsToDisplay.getChildren(); 157 assertNotNull("kids should not be null", kids); 158 assertTrue("There should be more than one child", kids.size() > 1); 159 160 assertEquals("There should be 6 properties", propNames.size() == 6, true); 161 assertFalse("The id attribute should not be present", propsToDisplay.hasAttribute("id")); 162 } 163 164 public void testPropertyEditing() 165 { 166 String configFiles = getResourcesDir() + "test-config.xml"; 168 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 169 svc.init(); 170 171 Config propEditConfig = svc.getConfig("Property Editing"); 172 assertNotNull("Property Editing section should not be null", propEditConfig); 173 174 PropertySheetConfigElement propSheet = (PropertySheetConfigElement)propEditConfig. 175 getConfigElement("property-sheet"); 176 assertNotNull("property-sheet config should not be null", propSheet); 177 178 List <String > itemNamesToEdit = propSheet.getEditableItemNamesToShow(); 180 assertNotNull("itemNamesToEdit should not be null", itemNamesToEdit); 181 assertEquals("Number of properties", 3, itemNamesToEdit.size()); 182 183 assertEquals("first property name", "name", itemNamesToEdit.get(0)); 185 assertEquals("second property name", "description", itemNamesToEdit.get(1)); 186 assertEquals("third property name", "icon", itemNamesToEdit.get(2)); 187 188 Map <String , ItemConfig> itemsToEditMap = propSheet.getEditableItemsMapToShow(); 190 assertNotNull("itemsToEditMap should not be null", itemsToEditMap); 191 assertEquals("Number of properties", 3, itemsToEditMap.size()); 192 193 ItemConfig item = itemsToEditMap.get("icon"); 195 assertNotNull("icon should not be null", item); 196 assertTrue("icon property readOnly status should be true", item.isReadOnly()); 197 198 item = itemsToEditMap.get("size"); 200 assertNull("size should be null", item); 201 202 List <ItemConfig> itemsToEdit = propSheet.getEditableItemsToShow(); 204 assertNotNull("itemsToEdit should not be null", itemsToEdit); 205 assertEquals("Number of properties", 3, itemsToEdit.size()); 206 } 207 208 211 public void testClientConfig() 212 { 213 String configFiles = getResourcesDir() + "test-config.xml"; 215 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 216 svc.init(); 217 218 ClientConfigElement clientConfig = (ClientConfigElement)svc.getGlobalConfig(). 220 getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID); 221 assertNotNull("client config", clientConfig); 222 223 assertEquals("error page", "/jsp/error.jsp", clientConfig.getErrorPage()); 224 assertEquals("login page", "/jsp/login.jsp", clientConfig.getLoginPage()); 225 assertEquals("home space permission", "Consumer", clientConfig.getHomeSpacePermission()); 226 assertEquals("help url", "http://www.alfresco.org/help/webclient", clientConfig.getHelpUrl()); 227 assertEquals("edit link type", "http", clientConfig.getEditLinkType()); 228 assertEquals("from address", "alfresco@alfresco.org", clientConfig.getFromEmailAddress()); 229 assertEquals("recent spaces", 6, clientConfig.getRecentSpacesItems()); 230 assertEquals("search minimum", 3, clientConfig.getSearchMinimum()); 231 assertTrue("shelf visible", clientConfig.isShelfVisible()); 232 } 233 234 public void testClientOverride() 235 { 236 List <String > configFiles = new ArrayList <String >(2); 238 configFiles.add(getResourcesDir() + "test-config.xml"); 239 configFiles.add(getResourcesDir() + "test-config-override.xml"); 240 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 241 svc.init(); 242 243 Config globalSection = svc.getGlobalConfig(); 245 assertNotNull("global section", globalSection); 246 247 ClientConfigElement clientConfig = (ClientConfigElement)globalSection. 249 getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID); 250 assertNotNull("client config", clientConfig); 251 252 assertEquals("error page", "/jsp/error.jsp", clientConfig.getErrorPage()); 254 assertEquals("login page", "/jsp/login-override.jsp", clientConfig.getLoginPage()); 255 assertEquals("home space permission", "Editor", clientConfig.getHomeSpacePermission()); 256 assertEquals("help url", "http://www.somewhere.com/help", clientConfig.getHelpUrl()); 257 assertEquals("edit link type", "webdav", clientConfig.getEditLinkType()); 258 assertEquals("from address", "me@somewhere.com", clientConfig.getFromEmailAddress()); 259 assertEquals("recent spaces", 1, clientConfig.getRecentSpacesItems()); 260 assertEquals("search minimum", 10, clientConfig.getSearchMinimum()); 261 assertFalse("shelf visible", clientConfig.isShelfVisible()); 262 } 263 264 267 public void testNavigation() 268 { 269 String configFiles = getResourcesDir() + "test-config.xml"; 271 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 272 svc.init(); 273 274 Config testCfg = svc.getConfig("viewid-navigation-result"); 276 assertNotNull("viewid-navigation-result config should not be null", testCfg); 277 278 NavigationConfigElement navCfg = (NavigationConfigElement)testCfg.getConfigElement("navigation"); 279 assertNotNull("navigation config should not be null", navCfg); 280 281 NavigationResult navResult = navCfg.getOverride("/jsp/browse/browse.jsp", null); 283 assertEquals("result should be '/jsp/forums/forums.jsp'", "/jsp/forums/forums.jsp", 284 navResult.getResult()); 285 assertFalse("isOutcome test should be false", navResult.isOutcome()); 286 287 navResult = navCfg.getOverride(null, "browse"); 289 assertEquals("result should be '/jsp/forums/topics.jsp'", "/jsp/forums/topics.jsp", 290 navResult.getResult()); 291 assertFalse("isOutcome test should be false", navResult.isOutcome()); 292 293 navResult = navCfg.getOverride("/jsp/browse/browse.jsp", "browse"); 296 assertEquals("result should be '/jsp/forums/topics.jsp'", "/jsp/forums/topics.jsp", 297 navResult.getResult()); 298 assertFalse("isOutcome test should be false", navResult.isOutcome()); 299 300 testCfg = svc.getConfig("outcome-navigation-result"); 302 assertNotNull("outcome-navigation-result config should not be null", testCfg); 303 304 navCfg = (NavigationConfigElement)testCfg.getConfigElement("navigation"); 305 assertNotNull("navigation config should not be null", navCfg); 306 307 navResult = navCfg.getOverride("/jsp/browse/browse.jsp", null); 309 assertEquals("result should be 'showSomethingElse'", "showSomethingElse", 310 navResult.getResult()); 311 assertTrue("isOutcome test should be true", navResult.isOutcome()); 312 313 navResult = navCfg.getOverride(null, "browse"); 315 assertEquals("result should be 'showSomethingElse'", "showSomethingElse", 316 navResult.getResult()); 317 assertTrue("isOutcome test should be true", navResult.isOutcome()); 318 319 navResult = navCfg.getOverride("/jsp/browse/browse.jsp", "browse"); 322 assertEquals("result should be 'showSomethingElse'", "showSomethingElse", 323 navResult.getResult()); 324 assertTrue("isOutcome test should be true", navResult.isOutcome()); 325 326 testCfg = svc.getConfig("duplicate-navigation-overrides"); 328 assertNotNull("duplicate-navigation-overrides config should not be null", testCfg); 329 330 navCfg = (NavigationConfigElement)testCfg.getConfigElement("navigation"); 331 assertNotNull("navigation config should not be null", navCfg); 332 333 navResult = navCfg.getOverride(null, "browse"); 335 assertEquals("result should be 'newOutcome'", "newOutcome", 336 navResult.getResult()); 337 assertTrue("isOutcome test should be true", navResult.isOutcome()); 338 339 navResult = navCfg.getOverride("/jsp/browse/browse.jsp", "nonExistentOutcome"); 342 assertNull("result should be null", navResult); 343 } 344 345 public void testNavigationGenericConfig() 346 { 347 String configFiles = getResourcesDir() + "test-config.xml"; 349 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 350 svc.init(); 351 352 Config testCfg = svc.getConfig("duplicate-navigation-overrides"); 355 assertNotNull("duplicate-navigation-overrides config should not be null", testCfg); 356 357 ConfigElement ce = testCfg.getConfigElement("navigation"); 358 assertNotNull("navigation config should not be null", ce); 359 360 List <ConfigElement> children = ce.getChildren(); 361 assertNotNull(children); 362 363 assertEquals("There should be 2 children", 2, children.size()); 365 366 ConfigElement child = children.get(0); 370 String fromViewId = child.getAttribute("from-view-id"); 371 String fromOutcome = child.getAttribute("from-outcome"); 372 String toViewId = child.getAttribute("to-view-id"); 373 String toOutcome = child.getAttribute("to-outcome"); 374 375 assertNull("fromOutcome", fromOutcome); 376 assertNull("toOutcome", toOutcome); 377 assertEquals("fromViewId", "/jsp/browse/browse.jsp", fromViewId); 378 assertEquals("toViewId", "/jsp/forums/forums.jsp", toViewId); 379 380 child = children.get(1); 383 fromViewId = child.getAttribute("from-view-id"); 384 fromOutcome = child.getAttribute("from-outcome"); 385 toViewId = child.getAttribute("to-view-id"); 386 toOutcome = child.getAttribute("to-outcome"); 387 388 assertNull("fromViewId", fromViewId); 389 assertNull("toViewId", toViewId); 390 assertEquals("fromOutcome", "browse", fromOutcome); 391 assertEquals("toOutcome", "newOutcome", toOutcome); 392 } 393 394 public void testLanguages() 395 { 396 List <String > configFiles = new ArrayList <String >(2); 398 configFiles.add(getResourcesDir() + "test-config.xml"); 399 configFiles.add(getResourcesDir() + "test-config-override.xml"); 400 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 401 svc.init(); 402 403 LanguagesConfigElement config = (LanguagesConfigElement)svc.getConfig("Languages"). 404 getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID); 405 assertNotNull("languages config", config); 406 407 assertEquals("number of languages", 4, config.getLanguages().size()); 409 410 assertEquals("first language", "en_US", config.getLanguages().get(0)); 412 assertEquals("second language", "fr_FR", config.getLanguages().get(1)); 413 assertEquals("third language", "de_DE", config.getLanguages().get(2)); 414 assertEquals("fourth language", "ja_JP", config.getLanguages().get(3)); 415 416 assertEquals("en_US", "English", config.getLabelForLanguage("en_US")); 418 assertEquals("fr_FR", "French", config.getLabelForLanguage("fr_FR")); 419 assertEquals("de_DE", "German", config.getLabelForLanguage("de_DE")); 420 assertEquals("ja_JP", "Japanese", config.getLabelForLanguage("ja_JP")); 421 422 try 424 { 425 config.getChildren(); 426 fail("getChildren() did not throw an excpetion"); 427 } 428 catch (ConfigException ce) 429 { 430 } 432 } 433 434 public void testAdvancedSearch() 435 { 436 List <String > configFiles = new ArrayList <String >(2); 438 configFiles.add(getResourcesDir() + "test-config.xml"); 439 configFiles.add(getResourcesDir() + "test-config-override.xml"); 440 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 441 svc.init(); 442 443 AdvancedSearchConfigElement config = (AdvancedSearchConfigElement)svc.getConfig("Advanced Search"). 444 getConfigElement(AdvancedSearchConfigElement.CONFIG_ELEMENT_ID); 445 assertNotNull("advanced search config", config); 446 447 assertEquals("number of content types", 2, config.getContentTypes().size()); 449 450 assertEquals("first type", "cm:dictionaryModel", config.getContentTypes().get(0)); 452 assertEquals("second type", "fm:post", config.getContentTypes().get(1)); 453 454 assertEquals("number of content properties", 3, config.getCustomProperties().size()); 456 457 CustomProperty property = config.getCustomProperties().get(0); 458 assertTrue("first property is type", property.Type != null); 459 460 property = config.getCustomProperties().get(1); 461 assertTrue("second property is aspect", property.Type == null); 462 assertTrue("second property is aspect", property.Aspect != null); 463 assertEquals("second property aspect", "app:simpleworkflow", property.Aspect); 464 assertEquals("second property name", "app:approveStep", property.Property); 465 466 property = config.getCustomProperties().get(2); 467 assertEquals("third property name", "app:rejectStep", property.Property); 468 assertEquals("third property display id", "reject_step", property.LabelId); 469 470 try 472 { 473 config.getChildren(); 474 fail("getChildren() did not throw an excpetion"); 475 } 476 catch (ConfigException ce) 477 { 478 } 480 } 481 482 public void testViews() 483 { 484 List <String > configFiles = new ArrayList <String >(2); 486 configFiles.add(getResourcesDir() + "test-config.xml"); 487 configFiles.add(getResourcesDir() + "test-config-override.xml"); 488 XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles)); 489 svc.init(); 490 491 ViewsConfigElement config = (ViewsConfigElement)svc.getConfig("Views"). 492 getConfigElement(ViewsConfigElement.CONFIG_ELEMENT_ID); 493 assertNotNull("views config", config); 494 495 List <String > views = config.getViews(); 497 assertEquals("configured views", 4, views.size()); 498 499 assertEquals("details view renderer", 501 "org.alfresco.web.ui.common.renderer.data.RichListRenderer$DetailsViewRenderer", 502 views.get(0)); 503 assertEquals("icons view renderer", 504 "org.alfresco.web.ui.common.renderer.data.RichListRenderer$IconViewRenderer", 505 views.get(1)); 506 assertEquals("list view renderer", 507 "org.alfresco.web.ui.common.renderer.data.RichListRenderer$ListViewRenderer", 508 views.get(2)); 509 assertEquals("bubble view renderer", 510 "org.alfresco.web.bean.ForumsBean$TopicBubbleViewRenderer", views.get(3)); 511 512 assertEquals("default view", "details", config.getDefaultView("not-there")); 514 assertEquals("default view for topic", "bubble", config.getDefaultView("topic")); 515 516 assertEquals("default page size", 10, config.getDefaultPageSize("not", "there")); 518 assertEquals("forums icons page size", 20, config.getDefaultPageSize("forums", "icons")); 519 assertEquals("forum details page size", 50, config.getDefaultPageSize("forum", "details")); 520 assertEquals("icons view page size", 9, config.getDefaultPageSize("not-there", "icons")); 521 522 assertEquals("default sort column", "name", config.getDefaultSortColumn("not-there")); 524 assertEquals("browse page sort column", "name", config.getDefaultSortColumn("browse")); 525 assertEquals("forum page sort column", "modified", config.getDefaultSortColumn("forum")); 526 assertEquals("topic page sort column", "created", config.getDefaultSortColumn("topic")); 527 528 assertFalse("default sort direction should be ascending", config.hasDescendingSort("not-there")); 530 assertFalse("browse screen should use an ascending sort", config.hasDescendingSort("browse")); 531 assertTrue("topic screen should use a descending sort", config.hasDescendingSort("forum")); 532 assertFalse("topic screen should use an ascending sort", config.hasDescendingSort("topic")); 533 534 try 536 { 537 config.getChildren(); 538 fail("getChildren() did not throw an excpetion"); 539 } 540 catch (ConfigException ce) 541 { 542 } 544 } 545 } 546 | Popular Tags |