001 /** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krad.uif; 017 018 import junit.framework.Assert; 019 import org.junit.Before; 020 import org.junit.Test; 021 import org.kuali.rice.core.api.util.ConcreteKeyValue; 022 import org.kuali.rice.core.api.util.KeyValue; 023 import org.kuali.rice.krad.uif.component.Component; 024 import org.kuali.rice.krad.uif.control.RadioGroupControl; 025 import org.kuali.rice.krad.uif.element.Link; 026 import org.kuali.rice.krad.uif.element.Message; 027 import org.kuali.rice.krad.uif.field.InputField; 028 import org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl; 029 import org.kuali.rice.krad.uif.util.ComponentFactory; 030 import org.kuali.rice.krad.uif.util.KeyMessage; 031 import org.kuali.rice.krad.uif.view.View; 032 import org.kuali.rice.krad.util.KRADConstants; 033 import org.kuali.rice.krad.web.form.UifFormBase; 034 import org.kuali.rice.krad.test.KRADTestCase; 035 036 import java.util.ArrayList; 037 import java.util.List; 038 039 /** 040 * Test rich message generation and parsing functionality 041 * 042 * @author Kuali Rice Team (rice.collab@kuali.org) 043 */ 044 public class RichMessageTest extends KRADTestCase { 045 046 /** 047 * SimpleForm for testing purposes 048 */ 049 public class SampleForm extends UifFormBase { 050 public String field1; 051 public String field2; 052 public boolean renderField; 053 } 054 055 View view = new View(); 056 Message message; 057 SampleForm model; 058 059 /** 060 * @see org.kuali.rice.test.BaselineTestCase#setUp() 061 * @throws Exception 062 */ 063 @Override 064 @Before 065 public void setUp() throws Exception { 066 super.setUp(); 067 view.setViewHelperServiceClass(ViewHelperServiceImpl.class); 068 } 069 070 /** 071 * Test html content generation in a message 072 */ 073 @Test 074 public void testHtmlContentGeneration() { 075 model = new SampleForm(); 076 List<Component> components; 077 078 //single tag 079 generateAndSetMessage("[b]Message Content[/b]"); 080 components = message.getMessageComponentStructure(); 081 Assert.assertNotNull(components); 082 Assert.assertEquals(1, components.size()); 083 Assert.assertTrue(components.get(0) instanceof Message); 084 Assert.assertFalse(((Message) components.get(0)).isGenerateSpan()); 085 Assert.assertEquals("<b>Message Content</b>", ((Message) components.get(0)).getMessageText()); 086 087 //nested tags 088 generateAndSetMessage("[span][b]Message Content[/b][/span]"); 089 components = message.getMessageComponentStructure(); 090 Assert.assertEquals(1, components.size()); 091 Assert.assertEquals("<span><b>Message Content</b></span>", ((Message) components.get(0)).getMessageText()); 092 093 //multiple tags 094 generateAndSetMessage("[div][b]Message Content[/b][/div][p]Message [i]Message[/i] Message[/p]"); 095 components = message.getMessageComponentStructure(); 096 Assert.assertEquals(1, components.size()); 097 Assert.assertEquals("<div><b>Message Content</b></div><p>Message <i>Message</i> Message</p>", 098 ((Message) components.get(0)).getMessageText()); 099 100 //multiple tags with properties 101 generateAndSetMessage( 102 "[div class='cssClass'][b]Message Content[/b][/div][p]Message [a href='http://www.kuali.org']Message[/a] Message[/p]"); 103 components = message.getMessageComponentStructure(); 104 Assert.assertEquals(1, components.size()); 105 Assert.assertEquals( 106 "<div class='cssClass'><b>Message Content</b></div><p>Message <a href='http://www.kuali.org'>Message</a> Message</p>", 107 ((Message) components.get(0)).getMessageText()); 108 } 109 110 /** 111 * Test that the escape characters are properly replaced 112 */ 113 @Test 114 public void testEscapeCharacter() { 115 model = new SampleForm(); 116 List<Component> components; 117 118 //escape character 119 generateAndSetMessage("\\[ \\] Message \\[content\\]\\[/content\\]"); 120 components = message.getMessageComponentStructure(); 121 Assert.assertNotNull(components); 122 Assert.assertEquals(1, components.size()); 123 Assert.assertTrue(components.get(0) instanceof Message); 124 String messageText = ((Message) components.get(0)).getMessageText(); 125 Assert.assertEquals(KRADConstants.MessageParsing.LEFT_BRACKET 126 + " " 127 + KRADConstants.MessageParsing.RIGHT_BRACKET 128 + " Message " 129 + KRADConstants.MessageParsing.LEFT_BRACKET 130 + "content" 131 + KRADConstants.MessageParsing.RIGHT_BRACKET 132 + "" 133 + KRADConstants.MessageParsing.LEFT_BRACKET 134 + "/content" 135 + KRADConstants.MessageParsing.RIGHT_BRACKET, messageText); 136 messageText = messageText.replace(KRADConstants.MessageParsing.LEFT_BRACKET, "["); 137 messageText = messageText.replace(KRADConstants.MessageParsing.RIGHT_BRACKET, "]"); 138 Assert.assertEquals("[ ] Message [content][/content]", messageText); 139 } 140 141 /** 142 * Test link tag generation in a message 143 */ 144 @Test 145 public void testLinkGeneration() { 146 model = new SampleForm(); 147 List<Component> components; 148 149 generateAndSetMessage("Link here [link='http://www.kuali.org']Link[/link] text"); 150 components = message.getMessageComponentStructure(); 151 Assert.assertNotNull(components); 152 Assert.assertEquals(1, components.size()); 153 Assert.assertTrue(components.get(0) instanceof Message); 154 String messageText = ((Message) components.get(0)).getMessageText(); 155 Assert.assertEquals("Link here <a href='http://www.kuali.org' target='_blank'>Link</a> text", messageText); 156 } 157 158 /** 159 * Test action link generation in a message 160 */ 161 @Test 162 public void testActionGeneration() { 163 model = new SampleForm(); 164 List<Component> components; 165 166 //methodToCall 167 generateAndSetMessage("Action here [action=methodToCall]action[/action] text"); 168 components = message.getMessageComponentStructure(); 169 Assert.assertNotNull(components); 170 Assert.assertEquals(1, components.size()); 171 Assert.assertTrue(components.get(0) instanceof Message); 172 String messageText = ((Message) components.get(0)).getMessageText(); 173 Assert.assertEquals( 174 "Action here <a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,true,true,null); return false;\">action</a> text", 175 messageText); 176 177 //Other options 178 generateAndSetMessage("Action here [action=methodToCall,false]action[/action] text"); 179 components = message.getMessageComponentStructure(); 180 Assert.assertNotNull(components); 181 Assert.assertEquals(1, components.size()); 182 Assert.assertTrue(components.get(0) instanceof Message); 183 messageText = ((Message) components.get(0)).getMessageText(); 184 Assert.assertEquals( 185 "Action here <a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,false,true,null); return false;\">action</a> text", 186 messageText); 187 188 generateAndSetMessage("Action here [action=methodToCall,false,true]action[/action] text"); 189 components = message.getMessageComponentStructure(); 190 Assert.assertNotNull(components); 191 Assert.assertEquals(1, components.size()); 192 Assert.assertTrue(components.get(0) instanceof Message); 193 messageText = ((Message) components.get(0)).getMessageText(); 194 Assert.assertEquals( 195 "Action here <a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,false,true,null); return false;\">action</a> text", 196 messageText); 197 198 //ajax submit off 199 generateAndSetMessage("Action here [action=methodToCall,true,false]action[/action] text"); 200 components = message.getMessageComponentStructure(); 201 Assert.assertNotNull(components); 202 Assert.assertEquals(1, components.size()); 203 Assert.assertTrue(components.get(0) instanceof Message); 204 messageText = ((Message) components.get(0)).getMessageText(); 205 Assert.assertEquals( 206 "Action here <a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,true,false,null); return false;\">action</a> text", 207 messageText); 208 209 //ajax callback defined 210 generateAndSetMessage( 211 "Action here [action=methodToCall,false,true,function(){console.log('success');}]action[/action] text"); 212 components = message.getMessageComponentStructure(); 213 Assert.assertNotNull(components); 214 Assert.assertEquals(1, components.size()); 215 Assert.assertTrue(components.get(0) instanceof Message); 216 messageText = ((Message) components.get(0)).getMessageText(); 217 Assert.assertEquals( 218 "Action here <a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,false,true,function(){console.log('success');}); return false;\">action</a> text", 219 messageText); 220 221 //data ajax 222 generateAndSetMessage( 223 "Action here [action=methodToCall data={something: 'value', something2: 'value2'}]action[/action] text"); 224 components = message.getMessageComponentStructure(); 225 Assert.assertNotNull(components); 226 Assert.assertEquals(1, components.size()); 227 Assert.assertTrue(components.get(0) instanceof Message); 228 messageText = ((Message) components.get(0)).getMessageText(); 229 Assert.assertEquals( 230 "Action here <a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',{something: 'value', something2: 'value2'},true,true,null); return false;\">action</a> text", 231 messageText); 232 233 //data non-ajax 234 generateAndSetMessage( 235 "Action here [action=methodToCall,true,false data={something: 'value', something2: 'value2'}]action[/action] text"); 236 components = message.getMessageComponentStructure(); 237 Assert.assertNotNull(components); 238 Assert.assertEquals(1, components.size()); 239 Assert.assertTrue(components.get(0) instanceof Message); 240 messageText = ((Message) components.get(0)).getMessageText(); 241 Assert.assertEquals( 242 "Action here <a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',{something: 'value', something2: 'value2'},true,false,null); return false;\">action</a> text", 243 messageText); 244 } 245 246 /** 247 * Test color tag generation in a message 248 */ 249 @Test 250 public void testColorGeneration() { 251 model = new SampleForm(); 252 List<Component> components; 253 254 generateAndSetMessage("color here [color='blue']Color[/color] text"); 255 components = message.getMessageComponentStructure(); 256 Assert.assertNotNull(components); 257 Assert.assertEquals(1, components.size()); 258 Assert.assertTrue(components.get(0) instanceof Message); 259 String messageText = ((Message) components.get(0)).getMessageText(); 260 Assert.assertEquals("color here <span style='color: blue;'>Color</span> text", messageText); 261 262 generateAndSetMessage("color here [color=#FFFFFF]Color[/color] text"); 263 components = message.getMessageComponentStructure(); 264 Assert.assertNotNull(components); 265 Assert.assertEquals(1, components.size()); 266 Assert.assertTrue(components.get(0) instanceof Message); 267 messageText = ((Message) components.get(0)).getMessageText(); 268 Assert.assertEquals("color here <span style='color: #FFFFFF;'>Color</span> text", messageText); 269 } 270 271 /** 272 * Test css tag generation in a message 273 */ 274 @Test 275 public void testCssClassGeneration() { 276 model = new SampleForm(); 277 List<Component> components; 278 279 generateAndSetMessage("css here [css='c1']sample[/css] text"); 280 components = message.getMessageComponentStructure(); 281 Assert.assertNotNull(components); 282 Assert.assertEquals(1, components.size()); 283 Assert.assertTrue(components.get(0) instanceof Message); 284 String messageText = ((Message) components.get(0)).getMessageText(); 285 Assert.assertEquals("css here <span class='c1'>sample</span> text", messageText); 286 287 generateAndSetMessage("css here \\[[css='c1 c2']sample[/css]\\] text"); 288 components = message.getMessageComponentStructure(); 289 Assert.assertNotNull(components); 290 Assert.assertEquals(1, components.size()); 291 Assert.assertTrue(components.get(0) instanceof Message); 292 messageText = ((Message) components.get(0)).getMessageText(); 293 Assert.assertEquals("css here " + KRADConstants.MessageParsing.LEFT_BRACKET + 294 "<span class='c1 c2'>sample</span>" + KRADConstants.MessageParsing.RIGHT_BRACKET + 295 " text", messageText); 296 } 297 298 /** 299 * Test the ability to put components defined on the message inline by index number. 300 */ 301 @Test 302 public void testInlineComponentGeneration() { 303 List<Component> components; 304 305 //One inline component 306 InputField inputField1 = ComponentFactory.getInputField(); 307 inputField1.setPropertyName("field1"); 308 List<Component> inline = new ArrayList<Component>(); 309 inline.add(inputField1); 310 generateAndSetMessage("Message text [0] Message text", inline); 311 components = message.getMessageComponentStructure(); 312 Assert.assertNotNull(components); 313 Assert.assertEquals(3, components.size()); 314 Assert.assertTrue(components.get(0) instanceof Message); 315 Assert.assertEquals("Message text ", ((Message) components.get(0)).getMessageText()); 316 Assert.assertTrue(components.get(1) instanceof InputField); 317 Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName()); 318 Assert.assertTrue(components.get(2) instanceof Message); 319 Assert.assertEquals(" Message text", ((Message) components.get(2)).getMessageText()); 320 321 //Two inline components with html content 322 inputField1 = ComponentFactory.getInputField(); 323 inputField1.setPropertyName("field1"); 324 InputField inputField2 = ComponentFactory.getInputField(); 325 inputField2.setPropertyName("field2"); 326 inline = new ArrayList<Component>(); 327 inline.add(inputField1); 328 inline.add(inputField2); 329 generateAndSetMessage("[p class='cssClass']Message text [0] Message [b]text [1] other[/b] text[/p]", inline); 330 components = message.getMessageComponentStructure(); 331 Assert.assertNotNull(components); 332 Assert.assertEquals(5, components.size()); 333 Assert.assertTrue(components.get(0) instanceof Message); 334 Assert.assertEquals("<p class='cssClass'>Message text ", ((Message) components.get(0)).getMessageText()); 335 Assert.assertTrue(components.get(1) instanceof InputField); 336 Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName()); 337 Assert.assertTrue(components.get(2) instanceof Message); 338 Assert.assertEquals(" Message <b>text ", ((Message) components.get(2)).getMessageText()); 339 Assert.assertFalse(((Message) components.get(2)).isGenerateSpan()); 340 Assert.assertTrue(components.get(3) instanceof InputField); 341 Assert.assertEquals("field2", ((InputField) components.get(3)).getPropertyName()); 342 Assert.assertTrue(components.get(4) instanceof Message); 343 Assert.assertEquals(" other</b> text</p>", ((Message) components.get(4)).getMessageText()); 344 345 //inline components with changed properties 346 inputField1 = ComponentFactory.getInputField(); 347 inputField1.setPropertyName("field1"); 348 inputField2 = ComponentFactory.getInputField(); 349 inputField2.setPropertyName("field2"); 350 inline = new ArrayList<Component>(); 351 inline.add(inputField1); 352 inline.add(inputField2); 353 generateAndSetMessage( 354 "[p class='cssClass']Message text [0 propertyName='field20'] Message [b]text [1 cssClasses='c1 c2' required=true] other[/b] text[/p]", 355 inline); 356 components = message.getMessageComponentStructure(); 357 Assert.assertNotNull(components); 358 Assert.assertEquals(5, components.size()); 359 Assert.assertTrue(components.get(0) instanceof Message); 360 Assert.assertEquals("<p class='cssClass'>Message text ", ((Message) components.get(0)).getMessageText()); 361 Assert.assertTrue(components.get(1) instanceof InputField); 362 Assert.assertEquals("field20", ((InputField) components.get(1)).getPropertyName()); 363 Assert.assertTrue(components.get(2) instanceof Message); 364 Assert.assertEquals(" Message <b>text ", ((Message) components.get(2)).getMessageText()); 365 Assert.assertTrue(components.get(3) instanceof InputField); 366 Assert.assertEquals("field2", ((InputField) components.get(3)).getPropertyName()); 367 Assert.assertTrue(((InputField) components.get(3)).getRequired()); 368 Assert.assertTrue(((InputField) components.get(3)).getCssClasses().contains("c1 c2")); 369 Assert.assertTrue(components.get(4) instanceof Message); 370 Assert.assertEquals(" other</b> text</p>", ((Message) components.get(4)).getMessageText()); 371 } 372 373 /** 374 * Test the ability to put components inline by id 375 */ 376 @Test 377 public void testIdComponentGeneration() { 378 List<Component> components; 379 380 //One inline component and id component 381 InputField inputField1 = ComponentFactory.getInputField(); 382 inputField1.setPropertyName("field1"); 383 List<Component> inline = new ArrayList<Component>(); 384 inline.add(inputField1); 385 generateAndSetMessage("Message text [0] Message text [id=Uif-Link]", inline); 386 components = message.getMessageComponentStructure(); 387 Assert.assertNotNull(components); 388 Assert.assertEquals(4, components.size()); 389 Assert.assertTrue(components.get(0) instanceof Message); 390 Assert.assertEquals("Message text ", ((Message) components.get(0)).getMessageText()); 391 Assert.assertTrue(components.get(1) instanceof InputField); 392 Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName()); 393 Assert.assertTrue(components.get(2) instanceof Message); 394 Assert.assertEquals(" Message text ", ((Message) components.get(2)).getMessageText()); 395 Assert.assertTrue(components.get(3) instanceof Link); 396 397 //One inline component and id components 398 inputField1 = ComponentFactory.getInputField(); 399 inputField1.setPropertyName("field1"); 400 inline = new ArrayList<Component>(); 401 inline.add(inputField1); 402 generateAndSetMessage( 403 "Message text [0] Message text [id=Uif-InputField propertyName=field2][id=Uif-InputField propertyName=field3]", 404 inline); 405 components = message.getMessageComponentStructure(); 406 Assert.assertNotNull(components); 407 Assert.assertEquals(5, components.size()); 408 Assert.assertTrue(components.get(0) instanceof Message); 409 Assert.assertEquals("Message text ", ((Message) components.get(0)).getMessageText()); 410 Assert.assertTrue(components.get(1) instanceof InputField); 411 Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName()); 412 Assert.assertTrue(components.get(2) instanceof Message); 413 Assert.assertEquals(" Message text ", ((Message) components.get(2)).getMessageText()); 414 Assert.assertTrue(components.get(3) instanceof InputField); 415 Assert.assertEquals("field2", ((InputField) components.get(3)).getPropertyName()); 416 Assert.assertTrue(components.get(4) instanceof InputField); 417 Assert.assertEquals("field3", ((InputField) components.get(4)).getPropertyName()); 418 419 } 420 421 /** 422 * Test a complex message which combines all the above tested functionality 423 */ 424 @Test 425 public void testComplexMessageGeneration() { 426 List<Component> components; 427 428 InputField inputField1 = ComponentFactory.getInputField(); 429 inputField1.setPropertyName("field1"); 430 List<Component> inline = new ArrayList<Component>(); 431 inline.add(inputField1); 432 generateAndSetMessage("[p][css=class]Message [link=http://www.kuali.org]link[/link][/css] [0]" 433 + " [action=methodToCall,false data={key: 'value'}]action text[/action]" 434 + " [color=green]text [id=Uif-Link href='http://www.google.com' linkText=Linky]" 435 + " [b]more text[/b][/color]\\[0\\][/p]", inline); 436 components = message.getMessageComponentStructure(); 437 Assert.assertNotNull(components); 438 Assert.assertEquals(5, components.size()); 439 Assert.assertTrue(components.get(0) instanceof Message); 440 Assert.assertEquals( 441 "<p><span class='class'>Message <a href='http://www.kuali.org' target='_blank'>link</a></span> ", 442 ((Message) components.get(0)).getMessageText()); 443 Assert.assertTrue(components.get(1) instanceof InputField); 444 Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName()); 445 Assert.assertTrue(components.get(2) instanceof Message); 446 Assert.assertEquals(" <a href=\"javascript:void(null)\" " 447 + "onclick=\"submitForm('methodToCall',{key: 'value'},false,true,null); return false;\">" 448 + "action text</a> <span style='color: green;'>text ", ((Message) components.get(2)).getMessageText()); 449 Assert.assertTrue(components.get(3) instanceof Link); 450 Assert.assertEquals("http://www.google.com", ((Link) components.get(3)).getHref()); 451 Assert.assertEquals("Linky", ((Link) components.get(3)).getLinkText()); 452 Assert.assertTrue(components.get(4) instanceof Message); 453 Assert.assertEquals(" <b>more text</b></span>" 454 + KRADConstants.MessageParsing.LEFT_BRACKET 455 + "0" 456 + KRADConstants.MessageParsing.RIGHT_BRACKET 457 + "</p>", ((Message) components.get(4)).getMessageText()); 458 459 } 460 461 /** 462 * Test rich message options available on MultiValueControls 463 */ 464 @Test 465 public void testRichMultiValueOptions() { 466 467 List<KeyValue> options = new ArrayList<KeyValue>(); 468 options.add(new ConcreteKeyValue("1", "[color=green]Option [b]1[/b][/color]")); 469 options.add(new ConcreteKeyValue("2", "Option 2 [link='http://www.kuali.org']link[/link]")); 470 options.add(new ConcreteKeyValue("3", "Other: [id=Uif-InputField propertyName=field1]")); 471 options.add(new ConcreteKeyValue("4", "Other 2: [0]")); 472 RadioGroupControl radioGroupControl = ComponentFactory.getRadioGroupControl(); 473 474 List<Component> inline = new ArrayList<Component>(); 475 InputField field2 = ComponentFactory.getInputField(); 476 field2.setPropertyName("field2"); 477 inline.add(field2); 478 radioGroupControl.setInlineComponents(inline); 479 480 radioGroupControl.setOptions(options); 481 performSimulatedLifecycle(radioGroupControl); 482 for (Component component : radioGroupControl.getComponentsForLifecycle()) { 483 performSimulatedLifecycle(component); 484 } 485 486 List<KeyMessage> richOptions = radioGroupControl.getRichOptions(); 487 Assert.assertEquals("<span style='color: green;'>Option <b>1</b></span>", ((Message) (richOptions.get(0) 488 .getMessage().getMessageComponentStructure().get(0))).getMessageText()); 489 Assert.assertEquals("Option 2 <a href='http://www.kuali.org' target='_blank'>link</a>", 490 ((Message) (richOptions.get(1).getMessage().getMessageComponentStructure().get(0))).getMessageText()); 491 Assert.assertEquals("Other: ", ((Message) (richOptions.get(2).getMessage().getMessageComponentStructure().get( 492 0))).getMessageText()); 493 Assert.assertEquals("field1", ((InputField) (richOptions.get(2).getMessage().getMessageComponentStructure().get( 494 1))).getPropertyName()); 495 Assert.assertEquals("Other 2: ", ((Message) (richOptions.get(3).getMessage().getMessageComponentStructure().get( 496 0))).getMessageText()); 497 Assert.assertEquals("field2", ((InputField) (richOptions.get(3).getMessage().getMessageComponentStructure().get( 498 1))).getPropertyName()); 499 } 500 501 /** 502 * Test SPEL richMessages 503 */ 504 @Test 505 public void testSPELRichMessages() { 506 /* TODO Cannot figure out how to simulate correctly 507 model = new SampleForm(); 508 view.setFormClass(SampleForm.class); 509 List<Component> components; 510 model.field1 = "value"; 511 model.field2 = "[link='http://www.kuali.org']value2[/link]"; 512 model.renderField = false; 513 514 //simple 515 generateAndSetMessage("Message @{field1} text"); 516 components = message.getMessageComponentStructure(); 517 Assert.assertNull(components); 518 Assert.assertTrue(message.isGenerateSpan()); 519 Assert.assertEquals("Message value text", message.getMessageText()); 520 521 //rich message wrapping 522 generateAndSetMessage("Message [b]@{field1}[/b] text"); 523 components = message.getMessageComponentStructure(); 524 Assert.assertNotNull(components); 525 Assert.assertEquals(1, components.size()); 526 Assert.assertTrue(components.get(0) instanceof Message); 527 Assert.assertFalse(((Message) components.get(0)).isGenerateSpan()); 528 Assert.assertEquals("Message <b>value</b> text", ((Message) components.get(0)).getMessageText()); 529 530 //spel value contains rich content 531 generateAndSetMessage("Message @{field2} text"); 532 components = message.getMessageComponentStructure(); 533 Assert.assertNotNull(components); 534 Assert.assertEquals(1, components.size()); 535 Assert.assertTrue(components.get(0) instanceof Message); 536 Assert.assertFalse(((Message) components.get(0)).isGenerateSpan()); 537 Assert.assertEquals("Message <a href='http://www.kuali.org' target='_blank'>value2</a> text", 538 ((Message) components.get(0)).getMessageText()); 539 540 //spel value setting richMessage component value 541 generateAndSetMessage("Message text [id=Uif-InputField render=@{renderField} propertyName=@{field1}]"); 542 components = message.getMessageComponentStructure(); 543 Assert.assertNotNull(components); 544 Assert.assertEquals(2, components.size()); 545 Assert.assertTrue(components.get(0) instanceof Message); 546 Assert.assertFalse(((Message) components.get(0)).isGenerateSpan()); 547 Assert.assertEquals("Message text ", ((Message) components.get(0)).getMessageText()); 548 Assert.assertTrue(components.get(1) instanceof InputField); 549 Assert.assertFalse(((InputField) components.get(1)).isRender()); 550 Assert.assertEquals("value", ((InputField) components.get(1)).getPropertyName());*/ 551 } 552 553 /** 554 * Test basic message with no rich functionality 555 */ 556 @Test 557 public void testBasicMessage() { 558 model = new SampleForm(); 559 List<Component> components; 560 561 //single tag 562 generateAndSetMessage("Message Content"); 563 components = message.getMessageComponentStructure(); 564 Assert.assertNull(components); 565 Assert.assertTrue(message.isGenerateSpan()); 566 Assert.assertEquals("Message Content", message.getMessageText()); 567 } 568 569 /** 570 * Peform a simulated lifecycle on the component passed in 571 * 572 * @param component 573 */ 574 private void performSimulatedLifecycle(Component component) { 575 component.performInitialization(view, model); 576 component.performApplyModel(view, model, view); 577 component.performFinalize(view, model, view); 578 } 579 580 /** 581 * Generate and setup a message to be used in testing 582 * 583 * @param messageText 584 */ 585 private void generateAndSetMessage(String messageText) { 586 message = new Message(); 587 message.setMessageText(messageText); 588 performSimulatedLifecycle(message); 589 } 590 591 /** 592 * Generate and setup a message to be used in testing which contains inline components 593 * 594 * @param messageText 595 * @param inlineComponents 596 */ 597 private void generateAndSetMessage(String messageText, List<Component> inlineComponents) { 598 message = new Message(); 599 message.setInlineComponents(inlineComponents); 600 message.setMessageText(messageText); 601 performSimulatedLifecycle(message); 602 } 603 }