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  package org.apache.myfaces.application;
20  
21  import org.apache.myfaces.test.base.AbstractJsfTestCase;
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  import javax.faces.application.Resource;
26  import java.net.URL;
27  import java.util.Locale;
28  
29  /**
30   * Test cases for org.apache.myfaces.application.ResourceHandlerImpl.
31   *
32   * @author Jakob Korherr
33   */
34  public class ResourceHandlerImplTest extends AbstractJsfTestCase
35  {
36  
37      private ResourceHandlerImpl resourceHandler;
38  
39      public ResourceHandlerImplTest(String name)
40      {
41          super(name);
42      }
43  
44      @Override
45      protected void setUp() throws Exception
46      {
47          super.setUp();
48  
49          resourceHandler = new ResourceHandlerImpl();
50      }
51  
52      @Override
53      protected void tearDown() throws Exception
54      {
55          resourceHandler = null;
56  
57          super.tearDown();    
58      }
59  
60      @Test
61      public void testCreateResource_ResourceNotNull() throws Exception
62      {
63          Resource resource = resourceHandler.createResource("testResource.xhtml");
64  
65          Assert.assertNotNull(resource);
66      }
67  
68      @Test
69      public void testCreateResource_cacheHonorsLocale() throws Exception
70      {
71          // setup message bundle to use
72          application.setMessageBundle("org/apache/myfaces/application/resourcehandler/messages");
73  
74          // get english resource
75          application.setDefaultLocale(Locale.ENGLISH);
76          Resource resourceEn = resourceHandler.createResource("testResource.xhtml");
77          URL urlEn = resourceEn.getURL();
78  
79          // get german resource
80          application.setDefaultLocale(Locale.GERMAN);
81          Resource resourceDe = resourceHandler.createResource("testResource.xhtml");
82          URL urlDe = resourceDe.getURL();
83  
84          // URLs MUST be different, since there is an english and a german version of the resource
85          Assert.assertFalse("Resources must be different", urlEn.equals(urlDe));
86      }
87  
88  }