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.view;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
20  import org.kuali.rice.krad.test.KRADTestCase;
21  import org.kuali.rice.krad.web.form.UifFormBase;
22  
23  import java.util.HashMap;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.assertTrue;
28  import static org.mockito.Mockito.doReturn;
29  import static org.mockito.Mockito.spy;
30  
31  /**
32   * Test cases for {@link ViewTheme}
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class ViewThemeTest extends KRADTestCase {
37  
38      /**
39       * Tests the final CSS and Script file listings are built correctly when using
40       * manual configuration
41       */
42      @Test
43      public void testManualThemeConfiguration() {
44          View view = KRADServiceLocatorWeb.getViewService().getViewById("TestViewTheme1");
45  
46          ViewTheme theme = view.getTheme();
47          assertNotNull(theme);
48  
49          assertEquals(2, theme.getMinCssSourceFiles().size());
50          assertEquals(2, theme.getMinScriptSourceFiles().size());
51  
52          // test dev mode
53          theme = spy(theme);
54          doReturn(true).when(theme).inDevMode();
55          view.setTheme(theme);
56  
57          KRADServiceLocatorWeb.getViewService().buildView(view, new UifFormBase(), new HashMap<String, String>());
58  
59          assertEquals(2, theme.getCssFiles().size());
60          assertEquals(2, theme.getScriptFiles().size());
61  
62          // test non dev mode
63          view = KRADServiceLocatorWeb.getViewService().getViewById("TestViewTheme1");
64  
65          theme = view.getTheme();
66          assertNotNull(theme);
67  
68          theme = spy(theme);
69          doReturn(false).when(theme).inDevMode();
70          view.setTheme(theme);
71  
72          KRADServiceLocatorWeb.getViewService().buildView(view, new UifFormBase(), new HashMap<String, String>());
73  
74          assertEquals(1, theme.getCssFiles().size());
75          assertEquals(1, theme.getScriptFiles().size());
76  
77          assertTrue(theme.getCssFiles().contains(theme.getMinCssFile()));
78          assertTrue(theme.getScriptFiles().contains(theme.getMinScriptFile()));
79      }
80  }