3434public 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" ));
@@ -53,46 +66,67 @@ public void testApplicationProperties() {
5366 public void testUnparseableApplicationProperties () {
5467 EnvironmentTestUtils .addEnvironment (this .context , "VCAP_APPLICATION:" );
5568 this .initializer .onApplicationEvent (this .event );
56- assertNull (this . context . getEnvironment (). getProperty ("vcap" ));
69+ assertNull (getProperty ("vcap" ));
5770 }
5871
5972 @ Test
6073 public void testNullApplicationProperties () {
6174 EnvironmentTestUtils
6275 .addEnvironment (
6376 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}" );
6589 this .initializer .onApplicationEvent (this .event );
66- assertNull (this . context . getEnvironment (). getProperty ("vcap" ));
90+ assertNull (getProperty ("vcap" ));
6791 }
6892
6993 @ Test
7094 public void testServiceProperties () {
7195 EnvironmentTestUtils
7296 .addEnvironment (
7397 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\" }}]}" );
75106 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" ));
82109 }
83110
84111 @ Test
85112 public void testServicePropertiesWithoutNA () {
86113 EnvironmentTestUtils
87114 .addEnvironment (
88115 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\" }}]}" );
90124 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 );
97131 }
98132}
0 commit comments