Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
6a6ae64a
Commit
6a6ae64a
authored
Mar 24, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.1.x' into 1.2.x
parents
6322ea14
4d8cf714
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
12 deletions
+57
-12
VcapApplicationListener.java
...gframework/boot/cloudfoundry/VcapApplicationListener.java
+4
-1
VcapApplicationListenerTests.java
...ework/boot/cloudfoundry/VcapApplicationListenerTests.java
+53
-11
No files found.
spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java
View file @
6a6ae64a
/*
/*
* Copyright 2010-201
4
the original author or authors.
* Copyright 2010-201
5
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -208,6 +208,9 @@ public class VcapApplicationListener implements
...
@@ -208,6 +208,9 @@ public class VcapApplicationListener implements
if
(
value
instanceof
String
)
{
if
(
value
instanceof
String
)
{
properties
.
put
(
key
,
value
);
properties
.
put
(
key
,
value
);
}
}
else
if
(
value
instanceof
Number
)
{
properties
.
put
(
key
,
value
.
toString
());
}
else
if
(
value
instanceof
Map
)
{
else
if
(
value
instanceof
Map
)
{
// Need a compound key
// Need a compound key
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
...
spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java
View file @
6a6ae64a
/*
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
5
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -34,7 +34,9 @@ import static org.junit.Assert.assertNull;
...
@@ -34,7 +34,9 @@ import static org.junit.Assert.assertNull;
public
class
VcapApplicationListenerTests
{
public
class
VcapApplicationListenerTests
{
private
final
VcapApplicationListener
initializer
=
new
VcapApplicationListener
();
private
final
VcapApplicationListener
initializer
=
new
VcapApplicationListener
();
private
final
ConfigurableApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
private
final
ConfigurableApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
private
final
ApplicationEnvironmentPreparedEvent
event
=
new
ApplicationEnvironmentPreparedEvent
(
private
final
ApplicationEnvironmentPreparedEvent
event
=
new
ApplicationEnvironmentPreparedEvent
(
new
SpringApplication
(),
new
String
[
0
],
this
.
context
.
getEnvironment
());
new
SpringApplication
(),
new
String
[
0
],
this
.
context
.
getEnvironment
());
...
@@ -43,7 +45,18 @@ public class VcapApplicationListenerTests {
...
@@ -43,7 +45,18 @@ public class VcapApplicationListenerTests {
EnvironmentTestUtils
EnvironmentTestUtils
.
addEnvironment
(
.
addEnvironment
(
this
.
context
,
this
.
context
,
"VCAP_APPLICATION:{\"application_users\":[],\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\",\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],\"started_at\":\"2013-05-29 02:37:59 +0000\",\"started_at_timestamp\":1369795079,\"host\":\"0.0.0.0\",\"port\":61034,\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\",\"state_timestamp\":1369795079}"
);
"VCAP_APPLICATION:{\"application_users\":[],"
+
"\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\","
+
"\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\","
+
"\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],"
+
"\"started_at\":\"2013-05-29 02:37:59 +0000\","
+
"\"started_at_timestamp\":1369795079,"
+
"\"host\":\"0.0.0.0\",\"port\":61034,"
+
"\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},"
+
"\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\","
+
"\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],"
+
"\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\","
+
"\"state_timestamp\":1369795079}"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertEquals
(
"bb7935245adf3e650dfb7c58a06e9ece"
,
this
.
context
.
getEnvironment
()
assertEquals
(
"bb7935245adf3e650dfb7c58a06e9ece"
,
this
.
context
.
getEnvironment
()
.
getProperty
(
"vcap.application.instance_id"
));
.
getProperty
(
"vcap.application.instance_id"
));
...
@@ -64,7 +77,7 @@ public class VcapApplicationListenerTests {
...
@@ -64,7 +77,7 @@ public class VcapApplicationListenerTests {
public
void
testUnparseableApplicationProperties
()
{
public
void
testUnparseableApplicationProperties
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"VCAP_APPLICATION:"
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"VCAP_APPLICATION:"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertNull
(
this
.
context
.
getEnvironment
().
getProperty
(
"vcap"
));
assertNull
(
getProperty
(
"vcap"
));
}
}
@Test
@Test
...
@@ -72,9 +85,20 @@ public class VcapApplicationListenerTests {
...
@@ -72,9 +85,20 @@ public class VcapApplicationListenerTests {
EnvironmentTestUtils
EnvironmentTestUtils
.
addEnvironment
(
.
addEnvironment
(
this
.
context
,
this
.
context
,
"VCAP_APPLICATION:{\"application_users\":null,\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\",\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],\"started_at\":\"2013-05-29 02:37:59 +0000\",\"started_at_timestamp\":1369795079,\"host\":\"0.0.0.0\",\"port\":61034,\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\",\"state_timestamp\":1369795079}"
);
"VCAP_APPLICATION:{\"application_users\":null,"
+
"\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\","
+
"\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\","
+
"\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],"
+
"\"started_at\":\"2013-05-29 02:37:59 +0000\","
+
"\"started_at_timestamp\":1369795079,"
+
"\"host\":\"0.0.0.0\",\"port\":61034,"
+
"\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},"
+
"\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\","
+
"\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],"
+
"\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\","
+
"\"state_timestamp\":1369795079}"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertNull
(
this
.
context
.
getEnvironment
().
getProperty
(
"vcap"
));
assertNull
(
getProperty
(
"vcap"
));
}
}
@Test
@Test
...
@@ -82,10 +106,17 @@ public class VcapApplicationListenerTests {
...
@@ -82,10 +106,17 @@ public class VcapApplicationListenerTests {
EnvironmentTestUtils
EnvironmentTestUtils
.
addEnvironment
(
.
addEnvironment
(
this
.
context
,
this
.
context
,
"VCAP_SERVICES:{\"rds-mysql-n/a\":[{\"name\":\"mysql\",\"label\":\"rds-mysql-n/a\",\"plan\":\"10mb\",\"credentials\":{\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\",\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\",\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\",\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}"
);
"VCAP_SERVICES:{\"rds-mysql-n/a\":[{"
+
"\"name\":\"mysql\",\"label\":\"rds-mysql-n/a\","
+
"\"plan\":\"10mb\",\"credentials\":{"
+
"\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\","
+
"\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
+
"\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
+
"\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":"
+
"\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertEquals
(
"mysql"
,
assertEquals
(
"mysql"
,
getProperty
(
"vcap.services.mysql.name"
));
this
.
context
.
getEnvironment
().
getProperty
(
"vcap.services.mysql.name
"
));
assertEquals
(
"3306"
,
getProperty
(
"vcap.services.mysql.credentials.port
"
));
}
}
@Test
@Test
...
@@ -93,9 +124,20 @@ public class VcapApplicationListenerTests {
...
@@ -93,9 +124,20 @@ public class VcapApplicationListenerTests {
EnvironmentTestUtils
EnvironmentTestUtils
.
addEnvironment
(
.
addEnvironment
(
this
.
context
,
this
.
context
,
"VCAP_SERVICES:{\"rds-mysql\":[{\"name\":\"mysql\",\"label\":\"rds-mysql\",\"plan\":\"10mb\",\"credentials\":{\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\",\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\",\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\",\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}"
);
"VCAP_SERVICES:{\"rds-mysql\":[{"
+
"\"name\":\"mysql\",\"label\":\"rds-mysql\",\"plan\":\"10mb\","
+
"\"credentials\":{\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\","
+
"\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
+
"\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
+
"\"port\":3306,\"user\":\"urpRuqTf8Cpe6\","
+
"\"username\":\"urpRuqTf8Cpe6\","
+
"\"password\":\"pxLsGVpsC9A5S\"}}]}"
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
this
.
initializer
.
onApplicationEvent
(
this
.
event
);
assertEquals
(
"mysql"
,
assertEquals
(
"mysql"
,
getProperty
(
"vcap.services.mysql.name"
));
this
.
context
.
getEnvironment
().
getProperty
(
"vcap.services.mysql.name"
));
assertEquals
(
"3306"
,
getProperty
(
"vcap.services.mysql.credentials.port"
));
}
private
String
getProperty
(
String
key
)
{
return
this
.
context
.
getEnvironment
().
getProperty
(
key
);
}
}
}
}
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