001/**
002 * Copyright 2011-2013 The Kuali Foundation Licensed under the Educational
003 * Community License, Version 2.0 (the "License"); you may not use this file
004 * except in compliance with the License. You may obtain a copy of the License
005 * at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software
010 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
011 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
012 * License for the specific language governing permissions and limitations under
013 * the License.
014 */
015package org.kuali.mobility.admin.util;
016
017import java.util.Properties;
018
019import org.junit.Assert;
020import org.junit.Test;
021import org.kuali.mobility.admin.entity.HomeScreen;
022
023/**
024 * Unit test to check the functions of the <coce>LayoutUtil</code>
025 * @author Kuali Mobility Team (mobility.dev@kuali.org)
026 * @since 2.3.0
027 */
028public class LayoutUtilTest {
029
030        /**
031         * Check that all the predefined registered as valid layouts
032         * actually result in valids
033         */
034        @Test
035        public void testValidLayoutPredefined(){
036                for(String layout : HomeScreen.LAYOUTS){
037                        Assert.assertTrue("Layout " + layout + " is expected to be valid", LayoutUtil.isValidLayout(layout));
038                }
039        }
040        
041        /**
042         * A null layout should not be a valid layout
043         */
044        @Test
045        public void testNullInvalidLayoutPredefined(){
046                Assert.assertFalse("null layout is not expected to be valid", LayoutUtil.isValidLayout(null));
047        }
048        
049        /**
050         * If the user specifies a invalid layout while changing layout is not allowed,
051         * it should be changed to the default layout
052         */
053        @Test
054        public void testCorrectedLayout(){
055                Properties kmeProperties = new Properties();
056                kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "false");
057                kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
058                
059                String layout = "myFakeLayout";
060                String newLayout = LayoutUtil.getValidLayout(layout, kmeProperties);
061                
062                Assert.assertEquals(HomeScreen.LAYOUT_LIST, newLayout);
063        }
064        
065        /**
066         * If changing layout is not allowed, and the user specifies another valid 
067         * layout, it should be changed to the default layout
068         */
069        @Test
070        public void testCorrectedLayout2(){
071                Properties kmeProperties = new Properties();
072                kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "false");
073                kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
074                
075                String newLayout = LayoutUtil.getValidLayout(HomeScreen.LAYOUT_TILES, kmeProperties);
076                
077                Assert.assertEquals(HomeScreen.LAYOUT_LIST, newLayout);
078        }
079        
080        /**
081         * If the user specified an invalid layout while changing layout is allowed, 
082         * it should be changed to the default layout
083         */
084        @Test
085        public void testCorrectedLayout3(){
086                Properties kmeProperties = new Properties();
087                kmeProperties.put(LayoutUtil.PROP_LAYOUT_EDITABLE, "true");
088                kmeProperties.put(LayoutUtil.PROP_LAYOUT_DEFAULT, HomeScreen.LAYOUT_LIST);
089                
090                String layout = "myFakeLayout";
091                String newLayout = LayoutUtil.getValidLayout(layout, kmeProperties);
092                
093                Assert.assertEquals(HomeScreen.LAYOUT_LIST, newLayout);
094        }
095        
096        /**
097         * An invalid layout should be indicated as invalid
098         */
099        @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}