View Javadoc

1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the Educational
3    * Community License, Version 2.0 (the "License"); you may not use this file
4    * except in compliance with the License. You may obtain a copy of the License
5    * at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12   * License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.kuali.mobility.admin.util;
16  
17  import java.util.Properties;
18  
19  import org.junit.Assert;
20  import org.junit.Test;
21  import org.kuali.mobility.admin.entity.HomeScreen;
22  
23  /**
24   * Unit test to check the functions of the <coce>LayoutUtil</code>
25   * @author Kuali Mobility Team (mobility.dev@kuali.org)
26   * @since 2.3.0
27   */
28  public class LayoutUtilTest {
29  
30  	/**
31  	 * Check that all the predefined registered as valid layouts
32  	 * actually result in valids
33  	 */
34  	@Test
35  	public void testValidLayoutPredefined(){
36  		for(String layout : HomeScreen.LAYOUTS){
37  			Assert.assertTrue("Layout " + layout + " is expected to be valid", LayoutUtil.isValidLayout(layout));
38  		}
39  	}
40  	
41  	/**
42  	 * A null layout should not be a valid layout
43  	 */
44  	@Test
45  	public void testNullInvalidLayoutPredefined(){
46  		Assert.assertFalse("null layout is not expected to be valid", LayoutUtil.isValidLayout(null));
47  	}
48  	
49  	/**
50  	 * If the user specifies a invalid layout while changing layout is not allowed,
51  	 * it should be changed to the default layout
52  	 */
53  	@Test
54  	public void testCorrectedLayout(){
55  		Properties kmeProperties = new Properties();
56  		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "false");
57  		kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
58  		
59  		String layout = "myFakeLayout";
60  		String newLayout = LayoutUtil.getValidLayout(layout, kmeProperties);
61  		
62  		Assert.assertEquals(HomeScreen.LAYOUT_LIST, newLayout);
63  	}
64  	
65  	/**
66  	 * If changing layout is not allowed, and the user specifies another valid 
67  	 * layout, it should be changed to the default layout
68  	 */
69  	@Test
70  	public void testCorrectedLayout2(){
71  		Properties kmeProperties = new Properties();
72  		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "false");
73  		kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
74  		
75  		String newLayout = LayoutUtil.getValidLayout(HomeScreen.LAYOUT_TILES, kmeProperties);
76  		
77  		Assert.assertEquals(HomeScreen.LAYOUT_LIST, newLayout);
78  	}
79  	
80  	/**
81  	 * If the user specified an invalid layout while changing layout is allowed, 
82  	 * it should be changed to the default layout
83  	 */
84  	@Test
85  	public void testCorrectedLayout3(){
86  		Properties kmeProperties = new Properties();
87  		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "true");
88  		kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
89  		
90  		String layout = "myFakeLayout";
91  		String newLayout = LayoutUtil.getValidLayout(layout, kmeProperties);
92  		
93  		Assert.assertEquals(HomeScreen.LAYOUT_LIST, newLayout);
94  	}
95  	
96  	/**
97  	 * An invalid layout should be indicated as invalid
98  	 */
99  	@Test
100 	public void testIsValidLayout(){
101 		Properties kmeProperties = new Properties();
102 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "true");
103 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
104 		
105 		String layout = "myFakeLayout";
106 		Assert.assertFalse("Layout " + layout + " is not expected to be valid", LayoutUtil.isValidLayout(layout));
107 	}
108 	
109 	
110 	/**
111 	 * A invalid layout should not be seen as an allowed layout
112 	 */
113 	@Test
114 	public void testIsLayoutAllowed(){
115 		Properties kmeProperties = new Properties();
116 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "true");
117 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
118 		
119 		String layout = "myFakeLayout";
120 		Assert.assertFalse("Layout " + layout + " is not expected to be valid", LayoutUtil.isLayoutAllowed(layout, kmeProperties));
121 	}
122 	
123 	/**
124 	 * A valid layout while changing layout is not allowed, should result in a layout not allowe
125 	 */
126 	@Test
127 	public void testIsLayoutAllowed2(){
128 		Properties kmeProperties = new Properties();
129 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "false");
130 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
131 		
132 		Assert.assertFalse("Layout " + HomeScreen.LAYOUT_TILES + " is not expected to be valid", LayoutUtil.isLayoutAllowed(HomeScreen.LAYOUT_TILES, kmeProperties));
133 	}
134 	
135 	/**
136 	 * A invalid layout should not be seen as an allowed layout
137 	 */
138 	@Test
139 	public void testIsLayoutAllowed3(){
140 		Properties kmeProperties = new Properties();
141 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "true");
142 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
143 		
144 		Assert.assertTrue("Layout " + HomeScreen.LAYOUT_TILES + " is expected to be valid", LayoutUtil.isLayoutAllowed(HomeScreen.LAYOUT_TILES, kmeProperties));
145 	}
146 	
147 	/**
148 	 * Layout change is not allowed
149 	 */
150 	@Test
151 	public void testIsLayoutChangeAllowed(){
152 		Properties kmeProperties = new Properties();
153 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "false");
154 		Assert.assertFalse(LayoutUtil.isLayoutChangeAllowed(kmeProperties));
155 	}
156 	
157 	/**
158 	 * Layout change is allowed
159 	 */
160 	@Test
161 	public void testIsLayoutChangeAllowed2(){
162 		Properties kmeProperties = new Properties();
163 		kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "true");
164 		Assert.assertTrue(LayoutUtil.isLayoutChangeAllowed(kmeProperties));
165 	}
166 }