Skip to content

Commit 6a6ae64

Browse files
committed
Merge branch '1.1.x' into 1.2.x
2 parents 6322ea1 + 4d8cf71 commit 6a6ae64

File tree

2 files changed

+57
-12
lines changed

2 files changed

+57
-12
lines changed

spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2014 the original author or authors.
2+
* Copyright 2010-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -208,6 +208,9 @@ private void flatten(Properties properties, Map<String, Object> input, String pa
208208
if (value instanceof String) {
209209
properties.put(key, value);
210210
}
211+
else if (value instanceof Number) {
212+
properties.put(key, value.toString());
213+
}
211214
else if (value instanceof Map) {
212215
// Need a compound key
213216
@SuppressWarnings("unchecked")

spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,9 @@
3434
public class VcapApplicationListenerTests {
3535

3636
private final VcapApplicationListener initializer = new VcapApplicationListener();
37+
3738
private final ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
39+
3840
private final ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent(
3941
new SpringApplication(), new String[0], this.context.getEnvironment());
4042

@@ -43,7 +45,18 @@ public void testApplicationProperties() {
4345
EnvironmentTestUtils
4446
.addEnvironment(
4547
this.context,
46-
"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}");
48+
"VCAP_APPLICATION:{\"application_users\":[],"
49+
+ "\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\","
50+
+ "\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\","
51+
+ "\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],"
52+
+ "\"started_at\":\"2013-05-29 02:37:59 +0000\","
53+
+ "\"started_at_timestamp\":1369795079,"
54+
+ "\"host\":\"0.0.0.0\",\"port\":61034,"
55+
+ "\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},"
56+
+ "\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\","
57+
+ "\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],"
58+
+ "\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\","
59+
+ "\"state_timestamp\":1369795079}");
4760
this.initializer.onApplicationEvent(this.event);
4861
assertEquals("bb7935245adf3e650dfb7c58a06e9ece", this.context.getEnvironment()
4962
.getProperty("vcap.application.instance_id"));
@@ -64,38 +77,67 @@ public void testApplicationUris() {
6477
public void testUnparseableApplicationProperties() {
6578
EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:");
6679
this.initializer.onApplicationEvent(this.event);
67-
assertNull(this.context.getEnvironment().getProperty("vcap"));
80+
assertNull(getProperty("vcap"));
6881
}
6982

7083
@Test
7184
public void testNullApplicationProperties() {
7285
EnvironmentTestUtils
7386
.addEnvironment(
7487
this.context,
75-
"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}");
88+
"VCAP_APPLICATION:{\"application_users\":null,"
89+
+ "\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\","
90+
+ "\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\","
91+
+ "\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],"
92+
+ "\"started_at\":\"2013-05-29 02:37:59 +0000\","
93+
+ "\"started_at_timestamp\":1369795079,"
94+
+ "\"host\":\"0.0.0.0\",\"port\":61034,"
95+
+ "\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},"
96+
+ "\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\","
97+
+ "\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],"
98+
+ "\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\","
99+
+ "\"state_timestamp\":1369795079}");
76100
this.initializer.onApplicationEvent(this.event);
77-
assertNull(this.context.getEnvironment().getProperty("vcap"));
101+
assertNull(getProperty("vcap"));
78102
}
79103

80104
@Test
81105
public void testServiceProperties() {
82106
EnvironmentTestUtils
83107
.addEnvironment(
84108
this.context,
85-
"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\"}}]}");
109+
"VCAP_SERVICES:{\"rds-mysql-n/a\":[{"
110+
+ "\"name\":\"mysql\",\"label\":\"rds-mysql-n/a\","
111+
+ "\"plan\":\"10mb\",\"credentials\":{"
112+
+ "\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\","
113+
+ "\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
114+
+ "\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
115+
+ "\"port\":3306,\"user\":\"urpRuqTf8Cpe6\",\"username\":"
116+
+ "\"urpRuqTf8Cpe6\",\"password\":\"pxLsGVpsC9A5S\"}}]}");
86117
this.initializer.onApplicationEvent(this.event);
87-
assertEquals("mysql",
88-
this.context.getEnvironment().getProperty("vcap.services.mysql.name"));
118+
assertEquals("mysql", getProperty("vcap.services.mysql.name"));
119+
assertEquals("3306", getProperty("vcap.services.mysql.credentials.port"));
89120
}
90121

91122
@Test
92123
public void testServicePropertiesWithoutNA() {
93124
EnvironmentTestUtils
94125
.addEnvironment(
95126
this.context,
96-
"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\"}}]}");
127+
"VCAP_SERVICES:{\"rds-mysql\":[{"
128+
+ "\"name\":\"mysql\",\"label\":\"rds-mysql\",\"plan\":\"10mb\","
129+
+ "\"credentials\":{\"name\":\"d04fb13d27d964c62b267bbba1cffb9da\","
130+
+ "\"hostname\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
131+
+ "\"host\":\"mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\","
132+
+ "\"port\":3306,\"user\":\"urpRuqTf8Cpe6\","
133+
+ "\"username\":\"urpRuqTf8Cpe6\","
134+
+ "\"password\":\"pxLsGVpsC9A5S\"}}]}");
97135
this.initializer.onApplicationEvent(this.event);
98-
assertEquals("mysql",
99-
this.context.getEnvironment().getProperty("vcap.services.mysql.name"));
136+
assertEquals("mysql", getProperty("vcap.services.mysql.name"));
137+
assertEquals("3306", getProperty("vcap.services.mysql.credentials.port"));
138+
}
139+
140+
private String getProperty(String key) {
141+
return this.context.getEnvironment().getProperty(key);
100142
}
101143
}

0 commit comments

Comments
 (0)