View Javadoc

1   /**
2    * Copyright 2005-2013 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.component;
17  
18  /**
19   * various tests for {@link org.kuali.rice.krad.uif.component.ComponentBase}
20   *
21   @author Kuali Rice Team (rice.collab@kuali.org)
22   */
23  
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.kuali.rice.krad.uif.control.FileControl;
27  import org.kuali.rice.krad.uif.control.TextAreaControl;
28  import org.kuali.rice.krad.uif.control.TextControl;
29  import org.kuali.rice.krad.uif.control.UserControl;
30  import org.kuali.rice.krad.uif.element.Action;
31  import org.kuali.rice.krad.uif.element.Image;
32  import org.kuali.rice.krad.uif.element.Message;
33  import org.kuali.rice.krad.uif.field.LinkField;
34  
35  import java.util.TreeMap;
36  
37  import static junit.framework.Assert.assertFalse;
38  import static junit.framework.Assert.assertTrue;
39  import static org.junit.Assert.assertEquals;
40  import static org.junit.Assert.assertNotNull;
41  
42  /**
43   * @author Kuali Rice Team (rice.collab@kuali.org)
44   */
45  public class ComponentBaseTest {
46      private Component component;
47      private TreeMap<String, String> dataAttributes;
48  
49      @Before
50      public void setUp() throws Exception {
51          // use an action field, since ComponentBase is abstract
52          component = new Action();
53          component.setId("action1");
54          // used a TreeMap since it makes specific guarantees as to the order of entries
55          dataAttributes = new TreeMap<String, String>();
56          // set data attributes - for testing purposes only - they do not have any functional significance
57          dataAttributes.put("iconTemplateName", "cool-icon-%s.png");
58          dataAttributes.put("transitions", "3");
59          component.setDataAttributes(dataAttributes);
60      }
61  
62      @Test
63      /**
64       * test that simple data attributes are converted into inline attributes ok
65       */
66      public void testGetSimpleDataAttributes() throws Exception {
67          assertNotNull(component.getSimpleDataAttributes());
68          String expected = " data-iconTemplateName=\"cool-icon-%s.png\" data-transitions=\"3\"";
69          assertEquals("simple attributes did not match", expected, component.getSimpleDataAttributes());
70      }
71  
72      @Test
73      /**
74       * test that simple data attributes are converted into inline attributes ok  when data attributes are null
75       */
76      public void testGetSimpleDataAttributesWhenNull() throws Exception {
77          component.setDataAttributes(null);
78          assertEquals("simple attributes did not match", "", component.getSimpleDataAttributes());
79      }
80  }