    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.commons.configuration;
    18
    19  import junit.framework.Test;
    20  import junit.framework.TestCase;
    21  import junit.framework.TestSuite;
    22
    23  /***
    24   *
    25   */
    26  public class TestDynamicCombinedConfiguration extends TestCase
    27  {
    28      private static String PATTERN ="${sys:Id}";
    29      private static String PATTERN1 = "target/test-classes/testMultiConfiguration_${sys:Id}.xml";
    30      private static String DEFAULT_FILE = "target/test-classes/testMultiConfiguration_default.xml";
    31
    32      /***
    33       * Create the test case
    34       *
    35       * @param testName name of the test case
    36       */
    37      public TestDynamicCombinedConfiguration( String testName )
    38      {
    39          super( testName );
    40      }
    41
    42      /***
    43       * @return the suite of tests being tested
    44       */
    45      public static Test suite()
    46      {
    47          return new TestSuite( TestDynamicCombinedConfiguration.class );
    48      }
    49
    50      public void testConfiguration() throws Exception
    51      {
    52          DynamicCombinedConfiguration config = new DynamicCombinedConfiguration();
    53          config.setKeyPattern(PATTERN);
    54          MultiFileHierarchicalConfiguration multi = new MultiFileHierarchicalConfiguration(PATTERN1);
    55          config.addConfiguration(multi, "Multi");
    56          XMLConfiguration xml = new XMLConfiguration(DEFAULT_FILE);
    57          config.addConfiguration(xml, "Default");
    58
    59          verify("1001", config, 15);
    60          verify("1002", config, 25);
    61          verify("1003", config, 35);
    62          verify("1004", config, 50);
    63      }
    64
    65      private void verify(String key, DynamicCombinedConfiguration config, int rows)
    66      {
    67          System.setProperty("Id", key);
    68          assertTrue(config.getInt("rowsPerPage") == rows);
    69      }
    70  }