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