View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif;
17  
18  import junit.framework.Assert;
19  
20  import org.junit.Before;
21  import org.junit.Test;
22  import org.kuali.rice.core.api.util.ConcreteKeyValue;
23  import org.kuali.rice.core.api.util.KeyValue;
24  import org.kuali.rice.krad.uif.component.Component;
25  import org.kuali.rice.krad.uif.control.RadioGroupControl;
26  import org.kuali.rice.krad.uif.element.Link;
27  import org.kuali.rice.krad.uif.element.Message;
28  import org.kuali.rice.krad.uif.field.InputField;
29  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
30  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleUtils;
31  import org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl;
32  import org.kuali.rice.krad.uif.util.ComponentFactory;
33  import org.kuali.rice.krad.uif.util.KeyMessage;
34  import org.kuali.rice.krad.uif.util.LifecycleElement;
35  import org.kuali.rice.krad.uif.view.View;
36  import org.kuali.rice.krad.util.KRADConstants;
37  import org.kuali.rice.krad.web.form.UifFormBase;
38  import org.kuali.rice.krad.test.KRADTestCase;
39  
40  import java.util.ArrayList;
41  import java.util.List;
42  
43  /**
44   * Test rich message generation and parsing functionality
45   *
46   * @author Kuali Rice Team (rice.collab@kuali.org)
47   */
48  public class RichMessageTest extends KRADTestCase {
49  
50      /**
51       * SimpleForm for testing purposes
52       */
53      public class SampleForm extends UifFormBase {
54          public String field1;
55          public String field2;
56          public boolean renderField;
57      }
58  
59      View view = new View();
60      Message message;
61      SampleForm model;
62  
63      /**
64       * @see org.kuali.rice.test.BaselineTestCase#setUp()
65       * @throws Exception
66       */
67      @Override
68      @Before
69      public void setUp() throws Exception {
70          super.setUp();
71          view.setViewHelperServiceClass(ViewHelperServiceImpl.class);
72      }
73  
74      /**
75       * Test html content generation in a message
76       */
77      @Test
78      public void testHtmlContentGeneration() {
79          model = new SampleForm();
80          List<Component> components;
81  
82          //single tag
83          generateAndSetMessage("[b]Message Content[/b]");
84          components = message.getMessageComponentStructure();
85          Assert.assertNotNull(components);
86          Assert.assertEquals(1, components.size());
87          Assert.assertTrue(components.get(0) instanceof Message);
88          Assert.assertFalse(((Message) components.get(0)).isRenderWrapperTag());
89          Assert.assertEquals("<b>Message Content</b>", ((Message) components.get(0)).getMessageText());
90  
91          //nested tags
92          generateAndSetMessage("[span][b]Message Content[/b][/span]");
93          components = message.getMessageComponentStructure();
94          Assert.assertEquals(1, components.size());
95          Assert.assertEquals("<span><b>Message Content</b></span>", ((Message) components.get(0)).getMessageText());
96  
97          //multiple tags
98          generateAndSetMessage("[div][b]Message Content[/b][/div][p]Message [i]Message[/i] Message[/p]");
99          components = message.getMessageComponentStructure();
100         Assert.assertEquals(1, components.size());
101         Assert.assertEquals("<div><b>Message Content</b></div><p>Message&nbsp;<i>Message</i>&nbsp;Message</p>",
102                 ((Message) components.get(0)).getMessageText());
103 
104         //multiple tags with properties
105         generateAndSetMessage(
106                 "[div class='cssClass'][b]Message Content[/b][/div][p]Message [a href='http://www.kuali.org']Message[/a] Message[/p]");
107         components = message.getMessageComponentStructure();
108         Assert.assertEquals(1, components.size());
109         Assert.assertEquals(
110                 "<div class='cssClass'><b>Message Content</b></div><p>Message&nbsp;<a href='http://www.kuali.org'>Message</a>&nbsp;Message</p>",
111                 ((Message) components.get(0)).getMessageText());
112     }
113 
114     /**
115      * Test that the escape characters are properly replaced
116      */
117     @Test
118     public void testEscapeCharacter() {
119         model = new SampleForm();
120         List<Component> components;
121 
122         //escape character
123         generateAndSetMessage("\\[ \\] Message \\[content\\]\\[/content\\]");
124         components = message.getMessageComponentStructure();
125         Assert.assertNotNull(components);
126         Assert.assertEquals(1, components.size());
127         Assert.assertTrue(components.get(0) instanceof Message);
128         String messageText = ((Message) components.get(0)).getMessageText();
129         Assert.assertEquals(KRADConstants.MessageParsing.LEFT_BRACKET
130                 + " "
131                 + KRADConstants.MessageParsing.RIGHT_BRACKET
132                 + " Message "
133                 + KRADConstants.MessageParsing.LEFT_BRACKET
134                 + "content"
135                 + KRADConstants.MessageParsing.RIGHT_BRACKET
136                 + ""
137                 + KRADConstants.MessageParsing.LEFT_BRACKET
138                 + "/content"
139                 + KRADConstants.MessageParsing.RIGHT_BRACKET, messageText);
140         messageText = messageText.replace(KRADConstants.MessageParsing.LEFT_BRACKET, "[");
141         messageText = messageText.replace(KRADConstants.MessageParsing.RIGHT_BRACKET, "]");
142         Assert.assertEquals("[ ] Message [content][/content]", messageText);
143     }
144 
145     /**
146      * Test link tag generation in a message
147      */
148     @Test
149     public void testLinkGeneration() {
150         model = new SampleForm();
151         List<Component> components;
152 
153         generateAndSetMessage("Link here [link='http://www.kuali.org']Link[/link] text");
154         components = message.getMessageComponentStructure();
155         Assert.assertNotNull(components);
156         Assert.assertEquals(1, components.size());
157         Assert.assertTrue(components.get(0) instanceof Message);
158         String messageText = ((Message) components.get(0)).getMessageText();
159         Assert.assertEquals("Link here&nbsp;<a href='http://www.kuali.org' target='_blank'>Link</a>&nbsp;text", messageText);
160     }
161 
162     /**
163      * Test action link generation in a message
164      */
165     @Test
166     public void testActionGeneration() {
167         model = new SampleForm();
168         List<Component> components;
169 
170         //methodToCall
171         generateAndSetMessage("Action here [action=methodToCall]action[/action] text");
172         components = message.getMessageComponentStructure();
173         Assert.assertNotNull(components);
174         Assert.assertEquals(1, components.size());
175         Assert.assertTrue(components.get(0) instanceof Message);
176         String messageText = ((Message) components.get(0)).getMessageText();
177         Assert.assertEquals(
178                 "Action here&nbsp;<a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,true,true,null); return false;\">action</a>&nbsp;text",
179                 messageText);
180 
181         //Other options
182         generateAndSetMessage("Action here [action=methodToCall,false]action[/action] text");
183         components = message.getMessageComponentStructure();
184         Assert.assertNotNull(components);
185         Assert.assertEquals(1, components.size());
186         Assert.assertTrue(components.get(0) instanceof Message);
187         messageText = ((Message) components.get(0)).getMessageText();
188         Assert.assertEquals(
189                 "Action here&nbsp;<a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,false,true,null); return false;\">action</a>&nbsp;text",
190                 messageText);
191 
192         generateAndSetMessage("Action here [action=methodToCall,false,true]action[/action] text");
193         components = message.getMessageComponentStructure();
194         Assert.assertNotNull(components);
195         Assert.assertEquals(1, components.size());
196         Assert.assertTrue(components.get(0) instanceof Message);
197         messageText = ((Message) components.get(0)).getMessageText();
198         Assert.assertEquals(
199                 "Action here&nbsp;<a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,false,true,null); return false;\">action</a>&nbsp;text",
200                 messageText);
201 
202         //ajax submit off
203         generateAndSetMessage("Action here [action=methodToCall,true,false]action[/action] text");
204         components = message.getMessageComponentStructure();
205         Assert.assertNotNull(components);
206         Assert.assertEquals(1, components.size());
207         Assert.assertTrue(components.get(0) instanceof Message);
208         messageText = ((Message) components.get(0)).getMessageText();
209         Assert.assertEquals(
210                 "Action here&nbsp;<a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,true,false,null); return false;\">action</a>&nbsp;text",
211                 messageText);
212 
213         //ajax callback defined
214         generateAndSetMessage(
215                 "Action here [action=methodToCall,false,true,function(){console.log('success');}]action[/action] text");
216         components = message.getMessageComponentStructure();
217         Assert.assertNotNull(components);
218         Assert.assertEquals(1, components.size());
219         Assert.assertTrue(components.get(0) instanceof Message);
220         messageText = ((Message) components.get(0)).getMessageText();
221         Assert.assertEquals(
222                 "Action here&nbsp;<a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',null,false,true,function(){console.log('success');}); return false;\">action</a>&nbsp;text",
223                 messageText);
224 
225         //data ajax
226         generateAndSetMessage(
227                 "Action here [action=methodToCall data={something: 'value', something2: 'value2'}]action[/action] text");
228         components = message.getMessageComponentStructure();
229         Assert.assertNotNull(components);
230         Assert.assertEquals(1, components.size());
231         Assert.assertTrue(components.get(0) instanceof Message);
232         messageText = ((Message) components.get(0)).getMessageText();
233         Assert.assertEquals(
234                 "Action here&nbsp;<a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',{something: 'value', something2: 'value2'},true,true,null); return false;\">action</a>&nbsp;text",
235                 messageText);
236 
237         //data non-ajax
238         generateAndSetMessage(
239                 "Action here [action=methodToCall,true,false data={something: 'value', something2: 'value2'}]action[/action] text");
240         components = message.getMessageComponentStructure();
241         Assert.assertNotNull(components);
242         Assert.assertEquals(1, components.size());
243         Assert.assertTrue(components.get(0) instanceof Message);
244         messageText = ((Message) components.get(0)).getMessageText();
245         Assert.assertEquals(
246                 "Action here&nbsp;<a href=\"javascript:void(null)\" onclick=\"submitForm('methodToCall',{something: 'value', something2: 'value2'},true,false,null); return false;\">action</a>&nbsp;text",
247                 messageText);
248     }
249 
250     /**
251      * Test color tag generation in a message
252      */
253     @Test
254     public void testColorGeneration() {
255         model = new SampleForm();
256         List<Component> components;
257 
258         generateAndSetMessage("color here [color='blue']Color[/color] text");
259         components = message.getMessageComponentStructure();
260         Assert.assertNotNull(components);
261         Assert.assertEquals(1, components.size());
262         Assert.assertTrue(components.get(0) instanceof Message);
263         String messageText = ((Message) components.get(0)).getMessageText();
264         Assert.assertEquals("color here&nbsp;<span style='color: blue;'>Color</span>&nbsp;text", messageText);
265 
266         generateAndSetMessage("color here [color=#FFFFFF]Color[/color] text");
267         components = message.getMessageComponentStructure();
268         Assert.assertNotNull(components);
269         Assert.assertEquals(1, components.size());
270         Assert.assertTrue(components.get(0) instanceof Message);
271         messageText = ((Message) components.get(0)).getMessageText();
272         Assert.assertEquals("color here&nbsp;<span style='color: #FFFFFF;'>Color</span>&nbsp;text", messageText);
273     }
274 
275     /**
276      * Test css tag generation in a message
277      */
278     @Test
279     public void testCssClassGeneration() {
280         model = new SampleForm();
281         List<Component> components;
282 
283         generateAndSetMessage("css here [css='c1']sample[/css] text");
284         components = message.getMessageComponentStructure();
285         Assert.assertNotNull(components);
286         Assert.assertEquals(1, components.size());
287         Assert.assertTrue(components.get(0) instanceof Message);
288         String messageText = ((Message) components.get(0)).getMessageText();
289         Assert.assertEquals("css here&nbsp;<span class='c1'>sample</span>&nbsp;text", messageText);
290 
291         generateAndSetMessage("css here \\[[css='c1 c2']sample[/css]\\] text");
292         components = message.getMessageComponentStructure();
293         Assert.assertNotNull(components);
294         Assert.assertEquals(1, components.size());
295         Assert.assertTrue(components.get(0) instanceof Message);
296         messageText = ((Message) components.get(0)).getMessageText();
297         Assert.assertEquals("css here " + KRADConstants.MessageParsing.LEFT_BRACKET +
298                 "<span class='c1 c2'>sample</span>" + KRADConstants.MessageParsing.RIGHT_BRACKET +
299                 " text", messageText);
300     }
301 
302     /**
303      * Test the ability to put components defined on the message inline by index number.
304      */
305     @Test
306     public void testInlineComponentGeneration() {
307         List<Component> components;
308 
309         //One inline component
310         InputField inputField1 = ComponentFactory.getInputField();
311         inputField1.setPropertyName("field1");
312         List<Component> inline = new ArrayList<Component>();
313         inline.add(inputField1);
314         generateAndSetMessage("Message text [0] Message text", inline);
315         components = message.getMessageComponentStructure();
316         Assert.assertNotNull(components);
317         Assert.assertEquals(3, components.size());
318         Assert.assertTrue(components.get(0) instanceof Message);
319         Assert.assertEquals("Message text&nbsp;", ((Message) components.get(0)).getMessageText());
320         Assert.assertTrue(components.get(1) instanceof InputField);
321         Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName());
322         Assert.assertTrue(components.get(2) instanceof Message);
323         Assert.assertEquals("&nbsp;Message text", ((Message) components.get(2)).getMessageText());
324 
325         //Two inline components with html content
326         inputField1 = ComponentFactory.getInputField();
327         inputField1.setPropertyName("field1");
328         InputField inputField2 = ComponentFactory.getInputField();
329         inputField2.setPropertyName("field2");
330         inline = new ArrayList<Component>();
331         inline.add(inputField1);
332         inline.add(inputField2);
333         generateAndSetMessage("[p class='cssClass']Message text [0] Message [b]text [1] other[/b] text[/p]", inline);
334         components = message.getMessageComponentStructure();
335         Assert.assertNotNull(components);
336         Assert.assertEquals(5, components.size());
337         Assert.assertTrue(components.get(0) instanceof Message);
338         Assert.assertEquals("<p class='cssClass'>Message text&nbsp;", ((Message) components.get(0)).getMessageText());
339         Assert.assertTrue(components.get(1) instanceof InputField);
340         Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName());
341         Assert.assertTrue(components.get(2) instanceof Message);
342         Assert.assertEquals("&nbsp;Message&nbsp;<b>text&nbsp;", ((Message) components.get(2)).getMessageText());
343         Assert.assertFalse(((Message) components.get(2)).isRenderWrapperTag());
344         Assert.assertTrue(components.get(3) instanceof InputField);
345         Assert.assertEquals("field2", ((InputField) components.get(3)).getPropertyName());
346         Assert.assertTrue(components.get(4) instanceof Message);
347         Assert.assertEquals("&nbsp;other</b>&nbsp;text</p>", ((Message) components.get(4)).getMessageText());
348 
349         //inline components with changed properties
350         inputField1 = ComponentFactory.getInputField();
351         inputField1.setPropertyName("field1");
352         inputField2 = ComponentFactory.getInputField();
353         inputField2.setPropertyName("field2");
354         inline = new ArrayList<Component>();
355         inline.add(inputField1);
356         inline.add(inputField2);
357         generateAndSetMessage(
358                 "[p class='cssClass']Message text [0 propertyName='field20'] Message [b]text [1 cssClasses='c1 c2' required=true] other[/b] text[/p]",
359                 inline);
360         components = message.getMessageComponentStructure();
361         Assert.assertNotNull(components);
362         Assert.assertEquals(5, components.size());
363         Assert.assertTrue(components.get(0) instanceof Message);
364         Assert.assertEquals("<p class='cssClass'>Message text&nbsp;", ((Message) components.get(0)).getMessageText());
365         Assert.assertTrue(components.get(1) instanceof InputField);
366         Assert.assertEquals("field20", ((InputField) components.get(1)).getPropertyName());
367         Assert.assertTrue(components.get(2) instanceof Message);
368         Assert.assertEquals("&nbsp;Message&nbsp;<b>text&nbsp;", ((Message) components.get(2)).getMessageText());
369         Assert.assertTrue(components.get(3) instanceof InputField);
370         Assert.assertEquals("field2", ((InputField) components.get(3)).getPropertyName());
371         Assert.assertTrue(((InputField) components.get(3)).getRequired());
372         Assert.assertTrue(((InputField) components.get(3)).getCssClasses().contains("c1 c2"));
373         Assert.assertTrue(components.get(4) instanceof Message);
374         Assert.assertEquals("&nbsp;other</b>&nbsp;text</p>", ((Message) components.get(4)).getMessageText());
375     }
376 
377     /**
378      * Test the ability to put components inline by id
379      */
380     @Test
381     public void testIdComponentGeneration() {
382         List<Component> components;
383 
384         //One inline component and id component
385         InputField inputField1 = ComponentFactory.getInputField();
386         inputField1.setPropertyName("field1");
387         List<Component> inline = new ArrayList<Component>();
388         inline.add(inputField1);
389         generateAndSetMessage("Message text [0] Message text [id=Uif-Link]", inline);
390         components = message.getMessageComponentStructure();
391         Assert.assertNotNull(components);
392         Assert.assertEquals(4, components.size());
393         Assert.assertTrue(components.get(0) instanceof Message);
394         Assert.assertEquals("Message text&nbsp;", ((Message) components.get(0)).getMessageText());
395         Assert.assertTrue(components.get(1) instanceof InputField);
396         Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName());
397         Assert.assertTrue(components.get(2) instanceof Message);
398         Assert.assertEquals("&nbsp;Message text&nbsp;", ((Message) components.get(2)).getMessageText());
399         Assert.assertTrue(components.get(3) instanceof Link);
400 
401         //One inline component and id components
402         inputField1 = ComponentFactory.getInputField();
403         inputField1.setPropertyName("field1");
404         inline = new ArrayList<Component>();
405         inline.add(inputField1);
406         generateAndSetMessage(
407                 "Message text [0] Message text [id=Uif-InputField propertyName=field2][id=Uif-InputField propertyName=field3]",
408                 inline);
409         components = message.getMessageComponentStructure();
410         Assert.assertNotNull(components);
411         Assert.assertEquals(5, components.size());
412         Assert.assertTrue(components.get(0) instanceof Message);
413         Assert.assertEquals("Message text&nbsp;", ((Message) components.get(0)).getMessageText());
414         Assert.assertTrue(components.get(1) instanceof InputField);
415         Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName());
416         Assert.assertTrue(components.get(2) instanceof Message);
417         Assert.assertEquals("&nbsp;Message text&nbsp;", ((Message) components.get(2)).getMessageText());
418         Assert.assertTrue(components.get(3) instanceof InputField);
419         Assert.assertEquals("field2", ((InputField) components.get(3)).getPropertyName());
420         Assert.assertTrue(components.get(4) instanceof InputField);
421         Assert.assertEquals("field3", ((InputField) components.get(4)).getPropertyName());
422 
423     }
424 
425     /**
426      * Test a complex message which combines all the above tested functionality
427      */
428     @Test
429     public void testComplexMessageGeneration() {
430         List<Component> components;
431 
432         InputField inputField1 = ComponentFactory.getInputField();
433         inputField1.setPropertyName("field1");
434         List<Component> inline = new ArrayList<Component>();
435         inline.add(inputField1);
436         generateAndSetMessage("[p][css=class]Message [link=http://www.kuali.org]link[/link][/css] [0]"
437                 + " [action=methodToCall,false data={key: 'value'}]action text[/action]"
438                 + " [color=green]text [id=Uif-Link href='http://www.google.com' linkText=Linky]"
439                 + " [b]more text[/b][/color]\\[0\\][/p]", inline);
440         components = message.getMessageComponentStructure();
441         Assert.assertNotNull(components);
442         Assert.assertEquals(5, components.size());
443         Assert.assertTrue(components.get(0) instanceof Message);
444         Assert.assertEquals(
445                 "<p><span class='class'>Message&nbsp;<a href='http://www.kuali.org' target='_blank'>link</a></span>&nbsp;",
446                 ((Message) components.get(0)).getMessageText());
447         Assert.assertTrue(components.get(1) instanceof InputField);
448         Assert.assertEquals("field1", ((InputField) components.get(1)).getPropertyName());
449         Assert.assertTrue(components.get(2) instanceof Message);
450         Assert.assertEquals("&nbsp;<a href=\"javascript:void(null)\" "
451                 + "onclick=\"submitForm('methodToCall',{key: 'value'},false,true,null); return false;\">"
452                 + "action text</a>&nbsp;<span style='color: green;'>text&nbsp;", ((Message) components.get(2)).getMessageText());
453         Assert.assertTrue(components.get(3) instanceof Link);
454         Assert.assertEquals("http://www.google.com", ((Link) components.get(3)).getHref());
455         Assert.assertEquals("Linky", ((Link) components.get(3)).getLinkText());
456         Assert.assertTrue(components.get(4) instanceof Message);
457         Assert.assertEquals("&nbsp;<b>more text</b></span>"
458                 + KRADConstants.MessageParsing.LEFT_BRACKET
459                 + "0"
460                 + KRADConstants.MessageParsing.RIGHT_BRACKET
461                 + "</p>", ((Message) components.get(4)).getMessageText());
462 
463     }
464 
465     /**
466      * Test rich message options available on MultiValueControls
467      */
468     @Test
469     public void testRichMultiValueOptions() {
470 
471         List<KeyValue> options = new ArrayList<KeyValue>();
472         options.add(new ConcreteKeyValue("1", "[color=green]Option [b]1[/b][/color]"));
473         options.add(new ConcreteKeyValue("2", "Option 2 [link='http://www.kuali.org']link[/link]"));
474         options.add(new ConcreteKeyValue("3", "Other: [id=Uif-InputField propertyName=field1]"));
475         options.add(new ConcreteKeyValue("4", "Other 2: [0]"));
476         RadioGroupControl radioGroupControl = ComponentFactory.getRadioGroupControl();
477 
478         List<Component> inline = new ArrayList<Component>();
479         InputField field2 = ComponentFactory.getInputField();
480         field2.setPropertyName("field2");
481         inline.add(field2);
482         radioGroupControl.setInlineComponents(inline);
483 
484         radioGroupControl.setOptions(options);
485         performSimulatedLifecycle(radioGroupControl);
486         for (LifecycleElement component : ViewLifecycleUtils.getElementsForLifecycle(radioGroupControl).values()) {
487             if (component instanceof Component) {
488                 performSimulatedLifecycle((Component) component);
489             }
490         }
491 
492         List<KeyMessage> richOptions = radioGroupControl.getRichOptions();
493         Assert.assertEquals("<span style='color: green;'>Option&nbsp;<b>1</b></span>", ((Message) (richOptions.get(0)
494                 .getMessage().getMessageComponentStructure().get(0))).getMessageText());
495         Assert.assertEquals("Option 2&nbsp;<a href='http://www.kuali.org' target='_blank'>link</a>",
496                 ((Message) (richOptions.get(1).getMessage().getMessageComponentStructure().get(0))).getMessageText());
497         Assert.assertEquals("Other:&nbsp;", ((Message) (richOptions.get(2).getMessage().getMessageComponentStructure().get(
498                 0))).getMessageText());
499         Assert.assertEquals("field1", ((InputField) (richOptions.get(2).getMessage().getMessageComponentStructure().get(
500                 1))).getPropertyName());
501         Assert.assertEquals("Other 2:&nbsp;", ((Message) (richOptions.get(3).getMessage().getMessageComponentStructure().get(
502                 0))).getMessageText());
503         Assert.assertEquals("field2", ((InputField) (richOptions.get(3).getMessage().getMessageComponentStructure().get(
504                 1))).getPropertyName());
505     }
506 
507     /**
508      * Test SPEL richMessages
509      */
510     @Test
511     public void testSPELRichMessages() {
512         /*  TODO Cannot figure out how to simulate correctly
513         model = new SampleForm();
514         view.setFormClass(SampleForm.class);
515         List<Component> components;
516         model.field1 = "value";
517         model.field2 = "[link='http://www.kuali.org']value2[/link]";
518         model.renderField = false;
519 
520         //simple
521         generateAndSetMessage("Message @{field1} text");
522         components = message.getMessageComponentStructure();
523         Assert.assertNull(components);
524         Assert.assertTrue(message.isRenderWrapperTag());
525         Assert.assertEquals("Message value text", message.getMessageText());
526 
527         //rich message wrapping
528         generateAndSetMessage("Message [b]@{field1}[/b] text");
529         components = message.getMessageComponentStructure();
530         Assert.assertNotNull(components);
531         Assert.assertEquals(1, components.size());
532         Assert.assertTrue(components.get(0) instanceof Message);
533         Assert.assertFalse(((Message) components.get(0)).isRenderWrapperTag());
534         Assert.assertEquals("Message <b>value</b> text", ((Message) components.get(0)).getMessageText());
535 
536         //spel value contains rich content
537         generateAndSetMessage("Message @{field2} text");
538         components = message.getMessageComponentStructure();
539         Assert.assertNotNull(components);
540         Assert.assertEquals(1, components.size());
541         Assert.assertTrue(components.get(0) instanceof Message);
542         Assert.assertFalse(((Message) components.get(0)).isRenderWrapperTag());
543         Assert.assertEquals("Message <a href='http://www.kuali.org' target='_blank'>value2</a> text",
544                 ((Message) components.get(0)).getMessageText());
545 
546         //spel value setting richMessage component value
547         generateAndSetMessage("Message text [id=Uif-InputField render=@{renderField} propertyName=@{field1}]");
548         components = message.getMessageComponentStructure();
549         Assert.assertNotNull(components);
550         Assert.assertEquals(2, components.size());
551         Assert.assertTrue(components.get(0) instanceof Message);
552         Assert.assertFalse(((Message) components.get(0)).isRenderWrapperTag());
553         Assert.assertEquals("Message text ", ((Message) components.get(0)).getMessageText());
554         Assert.assertTrue(components.get(1) instanceof InputField);
555         Assert.assertFalse(((InputField) components.get(1)).isRender());
556         Assert.assertEquals("value", ((InputField) components.get(1)).getPropertyName());*/
557     }
558 
559     /**
560      * Test basic message with no rich functionality
561      */
562     @Test
563     public void testBasicMessage() {
564         model = new SampleForm();
565         List<Component> components;
566 
567         //single tag
568         generateAndSetMessage("Message Content");
569         components = message.getMessageComponentStructure();
570         Assert.assertNull(components);
571         Assert.assertTrue(message.isRenderWrapperTag());
572         Assert.assertEquals("Message Content", message.getMessageText());
573     }
574 
575     /**
576      * Peform a simulated lifecycle on the component passed in
577      *
578      * @param component
579      */
580     private void performSimulatedLifecycle(final Component component) {
581         if (model == null) {
582             model = new SampleForm();
583         }
584 
585         ViewLifecycle.encapsulateLifecycle(view, model, null, null, new Runnable(){
586             @Override
587             public void run() {
588                 component.performInitialization(model);
589                 component.performApplyModel(model, view);
590                 component.performFinalize(model, view);
591             }});
592     }
593 
594     /**
595      * Generate and setup a message to be used in testing
596      *
597      * @param messageText
598      */
599     private void generateAndSetMessage(String messageText) {
600         message = new Message();
601         message.setMessageText(messageText);
602         performSimulatedLifecycle(message);
603     }
604 
605     /**
606      * Generate and setup a message to be used in testing which contains inline components
607      *
608      * @param messageText
609      * @param inlineComponents
610      */
611     private void generateAndSetMessage(String messageText, List<Component> inlineComponents) {
612         message = new Message();
613         message.setInlineComponents(inlineComponents);
614         message.setMessageText(messageText);
615         performSimulatedLifecycle(message);
616     }
617 }