View Javadoc

1   /*
2    * $Id: SettingsTest.java 652734 2008-05-02 02:29:02Z mrdon $
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  
32  
33  /***
34   * Unit test for {@link SettingsTest}.
35   *
36   */
37  public class SettingsTest extends StrutsTestCase {
38  
39      public void testSettings() {
40          assertEquals("12345", Settings.get(StrutsConstants.STRUTS_MULTIPART_MAXSIZE));
41          assertEquals("\temp", Settings.get(StrutsConstants.STRUTS_MULTIPART_SAVEDIR));
42  
43          assertEquals("test,org/apache/struts2/othertest", Settings.get( StrutsConstants.STRUTS_CUSTOM_PROPERTIES));
44          assertEquals("testvalue", Settings.get("testkey"));
45          assertEquals("othertestvalue", Settings.get("othertestkey"));
46  
47          int count = getKeyCount();
48          assertEquals(11, count);
49      }
50  
51      public void testDefaultResourceBundlesLoaded() {
52          assertEquals("testmessages,testmessages2", Settings.get(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES));
53          assertEquals("This is a test message", LocalizedTextUtil.findDefaultText("default.testmessage", Locale.getDefault()));
54          assertEquals("This is another test message", LocalizedTextUtil.findDefaultText("default.testmessage2", Locale.getDefault()));
55      }
56  
57      public void testSetSettings() {
58          Settings.setInstance(new TestSettings());
59  
60          String keyName = "a.long.property.key.name";
61          assertEquals(keyName, Settings.get(keyName));
62          assertEquals(2, getKeyCount());
63      }
64  
65      private int getKeyCount() {
66          int count = 0;
67          Iterator keyNames = Settings.list();
68  
69          while (keyNames.hasNext()) {
70              keyNames.next();
71              count++;
72          }
73  
74          return count;
75      }
76  }