34
34
public class VcapApplicationListenerTests {
35
35
36
36
private final VcapApplicationListener initializer = new VcapApplicationListener ();
37
+
37
38
private final ConfigurableApplicationContext context = new AnnotationConfigApplicationContext ();
39
+
38
40
private final ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent (
39
41
new SpringApplication (), new String [0 ], this .context .getEnvironment ());
40
42
@@ -43,7 +45,18 @@ public void testApplicationProperties() {
43
45
EnvironmentTestUtils
44
46
.addEnvironment (
45
47
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}" );
47
60
this .initializer .onApplicationEvent (this .event );
48
61
assertEquals ("bb7935245adf3e650dfb7c58a06e9ece" , this .context .getEnvironment ()
49
62
.getProperty ("vcap.application.instance_id" ));
@@ -53,46 +66,67 @@ public void testApplicationProperties() {
53
66
public void testUnparseableApplicationProperties () {
54
67
EnvironmentTestUtils .addEnvironment (this .context , "VCAP_APPLICATION:" );
55
68
this .initializer .onApplicationEvent (this .event );
56
- assertNull (this . context . getEnvironment (). getProperty ("vcap" ));
69
+ assertNull (getProperty ("vcap" ));
57
70
}
58
71
59
72
@ Test
60
73
public void testNullApplicationProperties () {
61
74
EnvironmentTestUtils
62
75
.addEnvironment (
63
76
this .context ,
64
- "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}" );
77
+ "VCAP_APPLICATION:{\" application_users\" :null,"
78
+ + "\" instance_id\" :\" bb7935245adf3e650dfb7c58a06e9ece\" ,"
79
+ + "\" instance_index\" :0,\" version\" :\" 3464e092-1c13-462e-a47c-807c30318a50\" ,"
80
+ + "\" name\" :\" foo\" ,\" uris\" :[\" foo.cfapps.io\" ],"
81
+ + "\" started_at\" :\" 2013-05-29 02:37:59 +0000\" ,"
82
+ + "\" started_at_timestamp\" :1369795079,"
83
+ + "\" host\" :\" 0.0.0.0\" ,\" port\" :61034,"
84
+ + "\" limits\" :{\" mem\" :128,\" disk\" :1024,\" fds\" :16384},"
85
+ + "\" version\" :\" 3464e092-1c13-462e-a47c-807c30318a50\" ,"
86
+ + "\" name\" :\" dsyerenv\" ,\" uris\" :[\" dsyerenv.cfapps.io\" ],"
87
+ + "\" users\" :[],\" start\" :\" 2013-05-29 02:37:59 +0000\" ,"
88
+ + "\" state_timestamp\" :1369795079}" );
65
89
this .initializer .onApplicationEvent (this .event );
66
- assertNull (this . context . getEnvironment (). getProperty ("vcap" ));
90
+ assertNull (getProperty ("vcap" ));
67
91
}
68
92
69
93
@ Test
70
94
public void testServiceProperties () {
71
95
EnvironmentTestUtils
72
96
.addEnvironment (
73
97
this .context ,
74
- "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\" }}]}" );
98
+ "VCAP_SERVICES:{\" rds-mysql-n/a\" :[{"
99
+ + "\" name\" :\" mysql\" ,\" label\" :\" rds-mysql-n/a\" ,"
100
+ + "\" plan\" :\" 10mb\" ,\" credentials\" :{"
101
+ + "\" name\" :\" d04fb13d27d964c62b267bbba1cffb9da\" ,"
102
+ + "\" hostname\" :\" mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\" ,"
103
+ + "\" host\" :\" mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\" ,"
104
+ + "\" port\" :3306,\" user\" :\" urpRuqTf8Cpe6\" ,\" username\" :"
105
+ + "\" urpRuqTf8Cpe6\" ,\" password\" :\" pxLsGVpsC9A5S\" }}]}" );
75
106
this .initializer .onApplicationEvent (this .event );
76
- assertEquals ("mysql" ,
77
- this .context .getEnvironment ().getProperty ("vcap.services.mysql.name" ));
78
- assertEquals (
79
- "3306" ,
80
- this .context .getEnvironment ().getProperty (
81
- "vcap.services.mysql.credentials.port" ));
107
+ assertEquals ("mysql" , getProperty ("vcap.services.mysql.name" ));
108
+ assertEquals ("3306" , getProperty ("vcap.services.mysql.credentials.port" ));
82
109
}
83
110
84
111
@ Test
85
112
public void testServicePropertiesWithoutNA () {
86
113
EnvironmentTestUtils
87
114
.addEnvironment (
88
115
this .context ,
89
- "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\" }}]}" );
116
+ "VCAP_SERVICES:{\" rds-mysql\" :[{"
117
+ + "\" name\" :\" mysql\" ,\" label\" :\" rds-mysql\" ,\" plan\" :\" 10mb\" ,"
118
+ + "\" credentials\" :{\" name\" :\" d04fb13d27d964c62b267bbba1cffb9da\" ,"
119
+ + "\" hostname\" :\" mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\" ,"
120
+ + "\" host\" :\" mysql-service-public.clqg2e2w3ecf.us-east-1.rds.amazonaws.com\" ,"
121
+ + "\" port\" :3306,\" user\" :\" urpRuqTf8Cpe6\" ,"
122
+ + "\" username\" :\" urpRuqTf8Cpe6\" ,"
123
+ + "\" password\" :\" pxLsGVpsC9A5S\" }}]}" );
90
124
this .initializer .onApplicationEvent (this .event );
91
- assertEquals ("mysql" ,
92
- this . context . getEnvironment (). getProperty ("vcap.services.mysql.name " ));
93
- assertEquals (
94
- "3306" ,
95
- this . context . getEnvironment (). getProperty (
96
- "vcap.services.mysql.credentials.port" ) );
125
+ assertEquals ("mysql" , getProperty ( "vcap.services.mysql.name" ));
126
+ assertEquals ( "3306" , getProperty ("vcap.services.mysql.credentials.port " ));
127
+ }
128
+
129
+ private String getProperty (String key ) {
130
+ return this . context . getEnvironment (). getProperty ( key );
97
131
}
98
132
}
0 commit comments