View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.context;
21  
22  import org.junit.Assert;
23  import org.junit.jupiter.api.Test;
24  
25  class ThemeResourcesUnitTest {
26  
27    @Test
28    public void basic() {
29      final ThemeResources resources = new ThemeResources(false);
30      // empty
31      // empty
32      Assert.assertEquals(0, resources.getScriptList().size());
33      Assert.assertEquals(0, resources.getStyleList().size());
34  
35      final ThemeScript a = new ThemeScript();
36      a.setName("a");
37      // a
38      // empty
39      resources.addIncludeScript(a);
40      Assert.assertEquals(1, resources.getScriptList().size());
41      Assert.assertEquals(0, resources.getStyleList().size());
42      Assert.assertEquals("a", resources.getScriptList().get(0).getName());
43  
44      final ThemeScript b = new ThemeScript();
45      b.setName("b");
46      resources.addIncludeScript(b);
47      // a b
48      // empty
49      Assert.assertEquals(2, resources.getScriptList().size());
50      Assert.assertEquals(0, resources.getStyleList().size());
51      Assert.assertEquals("a", resources.getScriptList().get(0).getName());
52      Assert.assertEquals("b", resources.getScriptList().get(1).getName());
53  
54      final ThemeStyle c = new ThemeStyle();
55      c.setName("c");
56      resources.addIncludeStyle(c);
57      // a b
58      // c
59      Assert.assertEquals(2, resources.getScriptList().size());
60      Assert.assertEquals(1, resources.getStyleList().size());
61      Assert.assertEquals("a", resources.getScriptList().get(0).getName());
62      Assert.assertEquals("b", resources.getScriptList().get(1).getName());
63      Assert.assertEquals("c", resources.getStyleList().get(0).getName());
64  
65      // merging exclude
66      final ThemeResources resources2 = new ThemeResources(false);
67      final ThemeScript aEx = new ThemeScript();
68      aEx.setName("a");
69      resources2.addExcludeScript(aEx);
70      final ThemeStyle d = new ThemeStyle();
71      d.setName("d");
72      resources2.addIncludeStyle(d);
73  
74      final ThemeResources merge = ThemeResources.merge(resources, resources2);
75      // a b  merge with -a       ->   b
76      // c    merge with d        ->   c d
77      Assert.assertEquals(1, merge.getScriptList().size());
78      Assert.assertEquals(2, merge.getStyleList().size());
79      Assert.assertEquals("b", merge.getScriptList().get(0).getName());
80      Assert.assertEquals("c", merge.getStyleList().get(0).getName());
81      Assert.assertEquals("d", merge.getStyleList().get(1).getName());
82    }
83  
84    @Test
85    public void prodVsDev() {
86      final ThemeResources dev = new ThemeResources(false);
87      Assert.assertFalse(dev.isProduction());
88  
89      final ThemeResources prod = new ThemeResources(true);
90      Assert.assertTrue(prod.isProduction());
91    }
92  }