2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.config
;
11 import java
.io
.IOException
;
12 import java
.io
.InputStream
;
13 import java
.util
.HashMap
;
15 import java
.util
.Properties
;
17 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
18 import org
.springframework
.core
.env
.Environment
;
19 import org
.springframework
.stereotype
.Component
;
21 import eu
.etaxonomy
.cdm
.common
.ConfigFileUtil
;
24 * @author a.kohlbecker
29 public class ApplicationConfiguration
{
32 * Annotate your integration test class with
33 * {@code @TestPropertySource(properties = {"testmode = true"})} to
34 * load the configuration files from the test resources.
36 * <b>NOTE:</b> This will not work with current implementation of the
37 * {@link eu.etaxonomy.cdm.test.integration.CdmIntegrationTest CdmIntegrationTests}.
38 * For these tests please use the {@link unitils.AlternativeUnitilsJUnit4TestClassRunner}.
41 public static final String TEST_MODE
= "testmode";
46 Map
<String
, Properties
> configurations
= new HashMap
<>();
48 public String
getProperty(ApplicationConfigurationFile configFile
, String key
){
49 Properties props
= loadPropertiesFile(configFile
);
50 return props
.getProperty(key
);
54 * @param currentDataSourceId
57 protected Properties
loadPropertiesFile(ApplicationConfigurationFile configFile
) {
59 String currentDataSourceId
= env
.getProperty(CdmConfigurationKeys
.CDM_DATA_SOURCE_ID
);
60 if(!configurations
.containsKey(configFile
.getFileName())){
63 if(env
.getProperty(TEST_MODE
) == null){
65 props
= new ConfigFileUtil()
66 .setDefaultContent(configFile
.getDefaultContet())
67 .getProperties(currentDataSourceId
, configFile
.getFileName());
70 InputStream is
= ApplicationConfiguration
.class.getClassLoader().getResourceAsStream(
71 configFile
.getFileName());
73 throw new RuntimeException("Can't find configuration file '" + configFile
.getFileName() + ".properties in the test resoures.");
75 props
= new Properties();
79 configurations
.put(configFile
.getFileName(), props
);
81 } catch (IOException e
) {
82 throw new RuntimeException("Error reading the configuration file '" + configFile
.getFileName() + ".properties'. File corrupted?", e
);
85 return configurations
.get(configFile
.getFileName());