View Javadoc

1   /*
2    * $Id: SettingsTest.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.config;
23  
24  import java.util.Iterator;
25  import java.util.Locale;
26  
27  import org.apache.struts2.StrutsConstants;
28  import org.apache.struts2.StrutsTestCase;
29  
30  import com.opensymphony.xwork2.util.LocalizedTextUtil;
31  import com.opensymphony.xwork2.util.location.LocatableProperties;
32  import com.opensymphony.xwork2.inject.ContainerBuilder;
33  import com.opensymphony.xwork2.inject.Container;
34  import junit.framework.TestCase;
35  
36  
37  /***
38   * Unit test for {@link SettingsTest}.
39   *
40   */
41  public class LegacyPropertiesConfigurationProviderTest extends TestCase {
42  
43      public void testRegister_DifferentLocale() {
44  
45          ContainerBuilder builder = new ContainerBuilder();
46          builder.constant("foo", "bar");
47          builder.constant("struts.locale", "DE_de");
48  
49          LegacyPropertiesConfigurationProvider prov = new LegacyPropertiesConfigurationProvider();
50          prov.register(builder, new LocatableProperties());
51  
52          Container container = builder.create(true);
53  
54          Locale locale = container.getInstance(Locale.class);
55  
56          assertNotNull(locale);
57          assertEquals("DE", locale.getCountry());
58          assertEquals("de", locale.getLanguage());
59  
60      }
61  
62      public void testRegister_NoLocale() {
63  
64          ContainerBuilder builder = new ContainerBuilder();
65          builder.constant("foo", "bar");
66  
67          LegacyPropertiesConfigurationProvider prov = new LegacyPropertiesConfigurationProvider();
68          prov.register(builder, new LocatableProperties());
69  
70          Container container = builder.create(true);
71  
72          Locale locale = container.getInstance(Locale.class);
73  
74          assertNotNull(locale);
75          Locale vmLocale = Locale.getDefault();
76          assertEquals(locale, vmLocale);
77      }
78  
79  }