View Javadoc

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