Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
d0216c9a
Commit
d0216c9a
authored
Jul 03, 2020
by
Maxym Borodenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Property sources update
parent
25c54bef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
18 deletions
+165
-18
src/main/java/org/genesys2/spring/config/ApplicationConfig.java
...in/java/org/genesys2/spring/config/ApplicationConfig.java
+7
-9
src/test/java/org/genesys/test/config/ApplicationConfig.java
src/test/java/org/genesys/test/config/ApplicationConfig.java
+8
-9
src/test/java/org/genesys/test/util/ApplicationPropertiesTest.java
...java/org/genesys/test/util/ApplicationPropertiesTest.java
+150
-0
No files found.
src/main/java/org/genesys2/spring/config/ApplicationConfig.java
View file @
d0216c9a
...
...
@@ -30,12 +30,12 @@ import org.genesys2.transifex.client.TransifexService;
import
org.genesys2.transifex.client.TransifexServiceImpl
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.context.support.ResourceBundleMessageSource
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.io.ClassPathResource
;
...
...
@@ -70,12 +70,10 @@ public class ApplicationConfig {
}
@Bean
public
static
PropertyPlaceholderConfigurer
propertyPlaceholderConfigurer
()
{
final
PropertyPlaceholderConfigurer
propertyPlaceholderConfigurer
=
new
PropertyPlaceholderConfigurer
();
propertyPlaceholderConfigurer
.
setIgnoreResourceNotFound
(
false
);
propertyPlaceholderConfigurer
.
setSystemPropertiesMode
(
PropertyPlaceholderConfigurer
.
SYSTEM_PROPERTIES_MODE_OVERRIDE
);
propertyPlaceholderConfigurer
.
setFileEncoding
(
"utf-8"
);
public
static
PropertySourcesPlaceholderConfigurer
properties
()
{
PropertySourcesPlaceholderConfigurer
pspc
=
new
PropertySourcesPlaceholderConfigurer
();
pspc
.
setIgnoreResourceNotFound
(
true
);
pspc
.
setFileEncoding
(
"UTF-8"
);
final
List
<
Resource
>
locations
=
new
ArrayList
<>();
locations
.
add
(
new
ClassPathResource
(
"application.properties"
));
locations
.
add
(
new
ClassPathResource
(
"genesys.properties"
));
...
...
@@ -91,8 +89,8 @@ public class ApplicationConfig {
}
}
p
ropertyPlaceholderConfigurer
.
setLocations
(
locations
.
toArray
(
new
Resource
[]
{}));
return
p
ropertyPlaceholderConfigurer
;
p
spc
.
setLocations
(
locations
.
toArray
(
new
Resource
[]
{}));
return
p
spc
;
}
@Bean
...
...
src/test/java/org/genesys/test/config/ApplicationConfig.java
View file @
d0216c9a
...
...
@@ -33,12 +33,12 @@ import org.genesys2.spring.config.WebSecurityConfig;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.context.support.ResourceBundleMessageSource
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.io.ClassPathResource
;
...
...
@@ -85,17 +85,16 @@ public final class ApplicationConfig {
public
static
class
BaseConfig
{
@Bean
public
static
PropertyPlaceholderConfigurer
propertyPlaceholderConfigurer
()
{
final
PropertyPlaceholderConfigurer
propertyPlaceholderConfigurer
=
new
PropertyPlaceholderConfigurer
();
propertyPlaceholderConfigurer
.
setIgnoreResourceNotFound
(
false
);
propertyPlaceholderConfigurer
.
setSystemPropertiesMode
(
PropertyPlaceholderConfigurer
.
SYSTEM_PROPERTIES_MODE_OVERRIDE
);
propertyPlaceholderConfigurer
.
setFileEncoding
(
"utf-8"
);
public
static
PropertySourcesPlaceholderConfigurer
properties
()
{
PropertySourcesPlaceholderConfigurer
pspc
=
new
PropertySourcesPlaceholderConfigurer
();
pspc
.
setIgnoreResourceNotFound
(
true
);
pspc
.
setFileEncoding
(
"UTF-8"
);
final
List
<
Resource
>
locations
=
new
ArrayList
<>();
locations
.
add
(
new
ClassPathResource
(
"application.properties"
));
locations
.
add
(
new
ClassPathResource
(
"junit.properties"
));
propertyPlaceholderConfigurer
.
setLocations
(
locations
.
toArray
(
new
Resource
[]
{}));
return
propertyPlaceholderConfigurer
;
pspc
.
setLocations
(
locations
.
toArray
(
new
Resource
[]
{}));
return
pspc
;
}
@Bean
...
...
src/test/java/org/genesys/test/util/ApplicationPropertiesTest.java
0 → 100644
View file @
d0216c9a
/*
* Copyright 2020 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys.test.util
;
import
static
org
.
hamcrest
.
CoreMatchers
.*;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.genesys.blocks.util.CurrentApplicationContext
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.support.DefaultConversionService
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
/**
* Testing the PropertySourcesPlaceholderConfigurer support in Spring.
*
* Set environment variables:
*
* <pre>
* DB_URL=DB
* TEST_VAR_ONE=Yes
* TEST_INTEGER=13
* TEST_BOOLEAN=true
* TEST_STRINGS=AA,BB,CC
* </pre>
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
classes
=
{
ApplicationPropertiesTest
.
Config
.
class
})
@Ignore
public
class
ApplicationPropertiesTest
{
@Configuration
public
static
class
Config
{
@Bean
public
CurrentApplicationContext
currentApplicationContext
()
{
return
new
CurrentApplicationContext
();
}
// Adds support for lists
@Bean
public
ConversionService
conversionService
()
{
return
new
DefaultConversionService
();
}
@Bean
public
static
PropertySourcesPlaceholderConfigurer
properties
()
{
PropertySourcesPlaceholderConfigurer
pspc
=
new
PropertySourcesPlaceholderConfigurer
();
pspc
.
setIgnoreResourceNotFound
(
true
);
pspc
.
setFileEncoding
(
"UTF-8"
);
final
List
<
Resource
>
locations
=
new
ArrayList
<>();
locations
.
add
(
new
ClassPathResource
(
"application.properties"
));
locations
.
add
(
new
ClassPathResource
(
"junit.properties"
));
pspc
.
setLocations
(
locations
.
toArray
(
new
Resource
[]
{}));
return
pspc
;
}
// @Bean
// public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
// final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
// ppc.setIgnoreResourceNotFound(true);
// ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
// ppc.setFileEncoding("utf-8");
//
// final List<Resource> locations = new ArrayList<>();
// locations.add(new ClassPathResource("application.properties"));
// locations.add(new ClassPathResource("junit.properties"));
//
// ppc.setLocations(locations.toArray(new Resource[] {}));
// return ppc;
// }
@Bean
public
TestBean
testBean
()
{
return
new
TestBean
();
}
}
public
static
class
TestBean
{
@Value
(
"${db.url}"
)
public
String
dbUrl
;
@Value
(
"${test.var.one}"
)
public
String
testVarOne
;
@Value
(
"${test.boolean}"
)
public
Boolean
testBoolean
;
@Value
(
"${test.integer}"
)
public
int
testInt
;
@Value
(
"${test.integer.default:42}"
)
public
int
testDefault
;
@Value
(
"${test.strings}"
)
public
List
<
String
>
testStrings
;
}
@Autowired
private
TestBean
testBean
;
@Test
public
void
testEnvVar
()
{
assertThat
(
testBean
.
testVarOne
,
notNullValue
());
assertThat
(
testBean
.
testVarOne
,
equalTo
(
"Yes"
));
assertThat
(
testBean
.
testInt
,
notNullValue
());
assertThat
(
testBean
.
testInt
,
equalTo
(
13
));
assertThat
(
testBean
.
testBoolean
,
notNullValue
());
assertThat
(
testBean
.
testBoolean
,
equalTo
(
true
));
assertThat
(
testBean
.
testDefault
,
notNullValue
());
assertThat
(
testBean
.
testDefault
,
equalTo
(
42
));
assertThat
(
testBean
.
dbUrl
,
notNullValue
());
assertThat
(
testBean
.
dbUrl
,
equalTo
(
"DB"
));
assertThat
(
testBean
.
testStrings
,
notNullValue
());
assertThat
(
testBean
.
testStrings
,
hasItems
(
"AA"
,
"BB"
,
"CC"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment