KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > config > GlobalSettingsTest


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.dozer.util.mapping.config;
17
18 import net.sf.dozer.util.mapping.DozerTestBase;
19 import net.sf.dozer.util.mapping.util.MapperConstants;
20
21 /**
22  * @author tierney.matt
23  */

24 public class GlobalSettingsTest extends DozerTestBase {
25   
26   public void testLoadDefaultPropFile_Default() {
27     GlobalSettings globalSettings = GlobalSettings.createNew();
28     assertNotNull("loaded by name should not be null", globalSettings.getLoadedByFileName());
29     assertEquals("invalid loaded by file name", MapperConstants.DEFAULT_CONFIG_FILE,
30         globalSettings.getLoadedByFileName());
31   }
32   
33   public void testLoadDefaultPropFile_NotFound() {
34     String JavaDoc propFileName = String.valueOf(System.currentTimeMillis());
35     System.setProperty(MapperConstants.CONFIG_FILE_SYS_PROP, propFileName);
36     GlobalSettings globalSettings = GlobalSettings.createNew();
37
38     //assert all global settings equal the default values
39
assertNull("loaded by file name should be null", globalSettings.getLoadedByFileName());
40     assertEquals("invalid stats enabled value", MapperConstants.DEFAULT_STATISTICS_ENABLED,
41         globalSettings.getSettings().isStatisticsEnabled());
42     assertEquals("invalid converter cache max size value",
43         MapperConstants.DEFAULT_CONVERTER_BY_DEST_TYPE_CACHE_MAX_SIZE,
44         globalSettings.getSettings().getConverterByDestTypeCacheMaxSize());
45     assertEquals("invalid super type cache max size value",
46         MapperConstants.DEFAULT_SUPER_TYPE_CHECK_CACHE_MAX_SIZE,
47         globalSettings.getSettings().getSuperTypesCacheMaxSize());
48   }
49   
50   public void testLoadPropFile_SpecifiedViaSysProp() {
51     String JavaDoc propFileName = "samplecustomdozer.properties";
52     System.setProperty(MapperConstants.CONFIG_FILE_SYS_PROP, propFileName);
53     
54     GlobalSettings globalSettings = GlobalSettings.createNew();
55     
56     assertNotNull("loaded by name should not be null", globalSettings.getLoadedByFileName());
57     assertEquals("invalid load by file name", propFileName, globalSettings.getLoadedByFileName());
58     assertEquals("invalid stats enabled value", true, globalSettings.getSettings().isStatisticsEnabled());
59     assertEquals("invalid converter cache max size value", 25000, globalSettings.getSettings().getConverterByDestTypeCacheMaxSize());
60     assertEquals("invalid super type cache max size value", 10000, globalSettings.getSettings().getSuperTypesCacheMaxSize());
61   }
62 }
63
Popular Tags