public void Constructor_WithSingleServiceConfiguration() { // Arrange var configJson = @" { 'vcap': { 'services' : { 'p-config-server': [ { 'credentials': { 'access_token_uri': 'https://p-spring-cloud-services.uaa.wise.com/oauth/token', 'client_id': 'p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef', 'client_secret': 'e8KF1hXvAnGd', 'uri': 'http://localhost:8888' }, 'label': 'p-config-server', 'name': 'My Config Server', 'plan': 'standard', 'tags': [ 'configuration', 'spring-cloud' ] } ] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var options = new CloudFoundryServicesOptions(); var servSection = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX); servSection.Bind(options); Assert.NotNull(options.Services); Assert.Single(options.Services); Assert.NotNull(options.Services["p-config-server"]); Assert.Single(options.Services["p-config-server"]); Assert.Equal("p-config-server", options.ServicesList[0].Label); Assert.Equal("My Config Server", options.ServicesList[0].Name); Assert.Equal("standard", options.ServicesList[0].Plan); Assert.NotNull(options.ServicesList[0].Tags); Assert.Equal(2, options.ServicesList[0].Tags.Length); Assert.Equal("configuration", options.ServicesList[0].Tags[0]); Assert.Equal("spring-cloud", options.ServicesList[0].Tags[1]); Assert.NotNull(options.ServicesList[0].Credentials); Assert.Equal(4, options.ServicesList[0].Credentials.Count); Assert.Equal("https://p-spring-cloud-services.uaa.wise.com/oauth/token", options.ServicesList[0].Credentials["access_token_uri"].Value); Assert.Equal("p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef", options.ServicesList[0].Credentials["client_id"].Value); Assert.Equal("e8KF1hXvAnGd", options.ServicesList[0].Credentials["client_secret"].Value); Assert.Equal("http://localhost:8888", options.ServicesList[0].Credentials["uri"].Value); }
public void Constructor_WithIConfigurationRootBinds() { // Arrange var configJson = @" { ""vcap"": { ""services"" : { ""p-config-server"": [{ ""credentials"": { ""access_token_uri"": ""https://p-spring-cloud-services.uaa.wise.com/oauth/token"", ""client_id"": ""p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef"", ""client_secret"": ""e8KF1hXvAnGd"", ""uri"": ""http://localhost:8888"" }, ""label"": ""p-config-server"", ""name"": ""My Config Server"", ""plan"": ""standard"", ""tags"": [ ""configuration"", ""spring-cloud"" ] }] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var options = new CloudFoundryServicesOptions(config); Assert.NotNull(options.Services); Assert.Single(options.Services); Assert.NotNull(options.Services["p-config-server"]); Assert.Single(options.Services["p-config-server"]); var firstService = options.GetServicesList().First(); Assert.Equal("p-config-server", firstService.Label); Assert.Equal("My Config Server", firstService.Name); Assert.Equal("standard", firstService.Plan); Assert.NotNull(firstService.Tags); Assert.Equal(2, firstService.Tags.Count()); Assert.Contains("configuration", firstService.Tags); Assert.Contains("spring-cloud", firstService.Tags); Assert.NotNull(firstService.Credentials); Assert.Equal(4, firstService.Credentials.Count); Assert.Equal("https://p-spring-cloud-services.uaa.wise.com/oauth/token", firstService.Credentials["access_token_uri"].Value); Assert.Equal("p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef", firstService.Credentials["client_id"].Value); Assert.Equal("e8KF1hXvAnGd", firstService.Credentials["client_secret"].Value); Assert.Equal("http://localhost:8888", firstService.Credentials["uri"].Value); }
public void Bind_DoesNotBindsConfiguration() { var configJson = @" { ""foo"": { ""bar"" : { } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var opt = new MySqlServiceOption(); opt.Bind(config, "mySql2"); Assert.NotEqual("mySql2", opt.Name); Assert.NotEqual("p-mysql", opt.Label); }
public void Build_WithStreamSource_ReturnsExpected() { // Arrange var environment = @" { 'application_id': 'fa05c1a9-0fc1-4fbd-bae1-139850dec7a3', 'application_name': 'my-app', 'application_uris': [ 'my-app.10.244.0.34.xip.io' ], 'application_version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca', 'limits': { 'disk': 1024, 'fds': 16384, 'mem': 256 }, 'name': 'my-app', 'space_id': '06450c72-4669-4dc6-8096-45f9777db68a', 'space_name': 'my-space', 'uris': [ 'my-app.10.244.0.34.xip.io', 'my-app2.10.244.0.34.xip.io' ], 'users': null, 'version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca' }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(environment); var source = new JsonStreamConfigurationSource(memStream); var provider = new JsonStreamConfigurationProvider(source, memStream); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.Add(source); var root = builder.Build(); Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", root["application_id"]); Assert.Equal("1024", root["limits:disk"]); Assert.Equal("my-app.10.244.0.34.xip.io", root["uris:0"]); Assert.Equal("my-app2.10.244.0.34.xip.io", root["uris:1"]); }
public void Build_WithStreamSource_ReturnsExpected() { // Arrange var environment = @" { ""application_id"": ""fa05c1a9-0fc1-4fbd-bae1-139850dec7a3"", ""application_name"": ""my-app"", ""application_uris"": [""my-app.10.244.0.34.xip.io""], ""application_version"": ""fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca"", ""limits"": { ""disk"": 1024, ""fds"": 16384, ""mem"": 256 }, ""name"": ""my-app"", ""space_id"": ""06450c72-4669-4dc6-8096-45f9777db68a"", ""space_name"": ""my-space"", ""uris"": [ ""my-app.10.244.0.34.xip.io"", ""my-app2.10.244.0.34.xip.io"" ], ""users"": null, ""version"": ""fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca"" }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(environment); var source = new JsonStreamConfigurationSource(memStream); var provider = new JsonStreamConfigurationProvider(source); var builder = new ConfigurationBuilder(); builder.Add(source); var root = builder.Build(); Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", root["application_id"]); Assert.Equal("1024", root["limits:disk"]); Assert.Equal("my-app.10.244.0.34.xip.io", root["uris:0"]); Assert.Equal("my-app2.10.244.0.34.xip.io", root["uris:1"]); }
public void Constructor_WithMultipleSameServicesConfiguration() { // Arrange var configJson = @" { 'vcap': { 'services' : { 'p-mysql': [ { 'name': 'mySql1', 'label': 'p-mysql', 'tags': [ 'mysql', 'relational' ], 'plan': '100mb-dev', 'credentials': { 'hostname': '192.168.0.97', 'port': 3306, 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 'username': '******', 'password': '******', 'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' } }, { 'name': 'mySql2', 'label': 'p-mysql', 'tags': [ 'mysql', 'relational' ], 'plan': '100mb-dev', 'credentials': { 'hostname': '192.168.0.97', 'port': 3306, 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 'username': '******', 'password': '******', 'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' } } ] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var options = new CloudFoundryServicesOptions(); var servSection = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX); servSection.Bind(options); Assert.NotNull(options.Services); Assert.Single(options.Services); Assert.NotNull(options.Services["p-mysql"]); Assert.Equal(2, options.ServicesList.Count); Assert.Equal("p-mysql", options.ServicesList[0].Label); Assert.Equal("p-mysql", options.ServicesList[1].Label); Assert.True(options.ServicesList[0].Name.Equals("mySql1") || options.ServicesList[0].Name.Equals("mySql2")); Assert.True(options.ServicesList[1].Name.Equals("mySql1") || options.ServicesList[1].Name.Equals("mySql2")); Assert.Equal("192.168.0.97", options.ServicesList[0].Credentials["hostname"].Value); Assert.Equal("192.168.0.97", options.ServicesList[1].Credentials["hostname"].Value); Assert.Equal("3306", options.ServicesList[0].Credentials["port"].Value); Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", options.ServicesList[0].Credentials["name"].Value); Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", options.ServicesList[1].Credentials["name"].Value); }
public void Constructor_WithComplexSingleServiceConfiguration() { // Arrange var configJson = @" { 'vcap': { 'services' : { 'p-rabbitmq': [ { 'name': 'rabbitmq', 'label': 'p-rabbitmq', 'tags': [ 'rabbitmq', 'messaging', 'message-queue', 'amqp', 'stomp', 'mqtt', 'pivotal' ], 'plan': 'standard', 'credentials': { 'http_api_uris': [ 'https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/' ], 'ssl': false, 'dashboard_url': 'https://pivotal-rabbitmq.system.testcloud.com/#/login/268371bd-07e5-46f3-aec7-d1633ae20bbb/3fnpvbqm0djq5jl9fp6fc697f4', 'password': '******', 'protocols': { 'management': { 'path': '/api/', 'ssl': false, 'hosts': [ '192.168.0.97' ], 'password': '******', 'username': '******', 'port': 15672, 'host': '192.168.0.97', 'uri': 'http://*****:*****@192.168.0.97:15672/api/', 'uris': [ 'http://*****:*****@192.168.0.97:15672/api/' ] }, 'amqp': { 'vhost': '2260a117-cf28-4725-86dd-37b3b8971052', 'username': '******', 'password': '******', 'port': 5672, 'host': '192.168.0.97', 'hosts': [ '192.168.0.97' ], 'ssl': false, 'uri': 'amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052', 'uris': [ 'amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052' ] } }, 'username': '******', 'hostname': '192.168.0.97', 'hostnames': [ '192.168.0.97' ], 'vhost': '2260a117-cf28-4725-86dd-37b3b8971052', 'http_api_uri': 'https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/', 'uri': 'amqp://*****:*****@192.168.0.97/2260a117-cf28-4725-86dd-37b3b8971052', 'uris': [ 'amqp://*****:*****@192.168.0.97/2260a117-cf28-4725-86dd-37b3b8971052' ] } } ] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var options = new CloudFoundryServicesOptions(); var servSection = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX); servSection.Bind(options); Assert.NotNull(options.Services); Assert.Single(options.Services); Assert.Equal("p-rabbitmq", options.ServicesList[0].Label); Assert.Equal("rabbitmq", options.ServicesList[0].Name); Assert.Equal("standard", options.ServicesList[0].Plan); Assert.NotNull(options.ServicesList[0].Tags); Assert.Equal(7, options.ServicesList[0].Tags.Length); Assert.Equal("rabbitmq", options.ServicesList[0].Tags[0]); Assert.Equal("pivotal", options.ServicesList[0].Tags[6]); Assert.NotNull(options.ServicesList[0].Credentials); Assert.Equal(12, options.ServicesList[0].Credentials.Count); Assert.Equal("https://pivotal-rabbitmq.system.testcloud.com/#/login/268371bd-07e5-46f3-aec7-d1633ae20bbb/3fnpvbqm0djq5jl9fp6fc697f4", options.ServicesList[0].Credentials["dashboard_url"].Value); Assert.Equal("268371bd-07e5-46f3-aec7-d1633ae20bbb", options.ServicesList[0].Credentials["username"].Value); Assert.Equal("3fnpvbqm0djq5jl9fp6fc697f4", options.ServicesList[0].Credentials["password"].Value); Assert.Equal("268371bd-07e5-46f3-aec7-d1633ae20bbb", options.ServicesList[0].Credentials["protocols"]["amqp"]["username"].Value); Assert.Equal("3fnpvbqm0djq5jl9fp6fc697f4", options.ServicesList[0].Credentials["protocols"]["amqp"]["password"].Value); Assert.Equal( "amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052", options.ServicesList[0].Credentials["protocols"]["amqp"]["uris"]["0"].Value); }
public void Constructor_WithVcapApplicationConfiguration() { // Arrange var configJson = @" { ""vcap"": { ""application"" : { ""cf_api"": ""https://api.system.testcloud.com"", ""application_id"": ""fa05c1a9-0fc1-4fbd-bae1-139850dec7a3"", ""application_name"": ""my-app"", ""application_uris"": [ ""my-app.10.244.0.34.xip.io"" ], ""application_version"": ""fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca"", ""limits"": { ""disk"": 1024, ""fds"": 16384, ""mem"": 256 }, ""name"": ""my-app"", ""space_id"": ""06450c72-4669-4dc6-8096-45f9777db68a"", ""space_name"": ""my-space"", ""uris"": [ ""my-app.10.244.0.34.xip.io"", ""my-app2.10.244.0.34.xip.io"" ], ""users"": null, ""version"": ""fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca"" } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var options = new CloudFoundryApplicationOptions(config); Assert.Equal("https://api.system.testcloud.com", options.CF_Api); Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", options.ApplicationId); Assert.Equal("my-app", options.ApplicationName); Assert.NotNull(options.ApplicationUris); Assert.NotNull(options.Application_Uris); Assert.Single(options.ApplicationUris); Assert.Single(options.Application_Uris); Assert.Equal("my-app.10.244.0.34.xip.io", options.ApplicationUris.First()); Assert.Equal("my-app.10.244.0.34.xip.io", options.Application_Uris.First()); Assert.Equal("fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca", options.ApplicationVersion); Assert.Equal("my-app", options.Name); Assert.Equal("06450c72-4669-4dc6-8096-45f9777db68a", options.SpaceId); Assert.Equal("06450c72-4669-4dc6-8096-45f9777db68a", options.Space_Id); Assert.Equal("my-space", options.SpaceName); Assert.Equal("my-space", options.Space_Name); Assert.NotNull(options.Uris); Assert.Equal(2, options.Uris.Count()); Assert.Contains("my-app.10.244.0.34.xip.io", options.Uris); Assert.Contains("my-app2.10.244.0.34.xip.io", options.Uris); Assert.Equal("fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca", options.Version); }
public void Constructor_WithComplexSingleServiceConfiguration() { // Arrange var configJson = @" { ""vcap"": { ""services"" : { ""p-rabbitmq"": [{ ""name"": ""rabbitmq"", ""label"": ""p-rabbitmq"", ""tags"": [ ""rabbitmq"", ""messaging"", ""message-queue"", ""amqp"", ""stomp"", ""mqtt"", ""pivotal"" ], ""plan"": ""standard"", ""credentials"": { ""http_api_uris"": [ ""https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/"" ], ""ssl"": false, ""dashboard_url"": ""https://pivotal-rabbitmq.system.testcloud.com/#/login/268371bd-07e5-46f3-aec7-d1633ae20bbb/3fnpvbqm0djq5jl9fp6fc697f4"", ""password"": ""3fnpvbqm0djq5jl9fp6fc697f4"", ""protocols"": { ""management"": { ""path"": ""/api/"", ""ssl"": false, ""hosts"": [""192.168.0.97""], ""password"": ""3fnpvbqm0djq5jl9fp6fc697f4"", ""username"": ""268371bd-07e5-46f3-aec7-d1633ae20bbb"", ""port"": 15672, ""host"": ""192.168.0.97"", ""uri"": ""https://*****:*****@192.168.0.97:15672/api/"", ""uris"": [""https://*****:*****@192.168.0.97:15672/api/""] }, ""amqp"": { ""vhost"": ""2260a117-cf28-4725-86dd-37b3b8971052"", ""username"": ""268371bd-07e5-46f3-aec7-d1633ae20bbb"", ""password"": ""3fnpvbqm0djq5jl9fp6fc697f4"", ""port"": 5672, ""host"": ""192.168.0.97"", ""hosts"": [ ""192.168.0.97""], ""ssl"": false, ""uri"": ""amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052"", ""uris"": [""amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052""] } }, ""username"": ""268371bd-07e5-46f3-aec7-d1633ae20bbb"", ""hostname"": ""192.168.0.97"", ""hostnames"": [ ""192.168.0.97"" ], ""vhost"": ""2260a117-cf28-4725-86dd-37b3b8971052"", ""http_api_uri"": ""https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/"", ""uri"": ""amqp://*****:*****@192.168.0.97/2260a117-cf28-4725-86dd-37b3b8971052"", ""uris"": [ ""amqp://*****:*****@192.168.0.97/2260a117-cf28-4725-86dd-37b3b8971052"" ] } }] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var options = new CloudFoundryServicesOptions(config); Assert.NotNull(options.Services); Assert.Single(options.Services); var service = options.GetInstancesOfType("p-rabbitmq").First(); Assert.Equal("p-rabbitmq", service.Label); Assert.Equal("rabbitmq", service.Name); Assert.Equal("standard", service.Plan); Assert.NotNull(service.Tags); Assert.Equal(7, service.Tags.Count()); Assert.Contains("rabbitmq", service.Tags); Assert.Contains("pivotal", service.Tags); Assert.NotNull(service.Credentials); Assert.Equal(12, service.Credentials.Count); Assert.Equal("https://pivotal-rabbitmq.system.testcloud.com/#/login/268371bd-07e5-46f3-aec7-d1633ae20bbb/3fnpvbqm0djq5jl9fp6fc697f4", service.Credentials["dashboard_url"].Value); Assert.Equal("268371bd-07e5-46f3-aec7-d1633ae20bbb", service.Credentials["username"].Value); Assert.Equal("3fnpvbqm0djq5jl9fp6fc697f4", service.Credentials["password"].Value); Assert.Equal("268371bd-07e5-46f3-aec7-d1633ae20bbb", service.Credentials["protocols"]["amqp"]["username"].Value); Assert.Equal("3fnpvbqm0djq5jl9fp6fc697f4", service.Credentials["protocols"]["amqp"]["password"].Value); Assert.Equal( "amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052", service.Credentials["protocols"]["amqp"]["uris"]["0"].Value); }
public void Bind_BindsConfiguration() { // Arrange var configJson = @" { ""vcap"": { ""services"" : { ""p-mysql"": [{ ""name"": ""mySql1"", ""label"": ""p-mysql"", ""tags"": [ ""mysql"", ""relational"" ], ""plan"": ""100mb-dev"", ""credentials"": { ""hostname"": ""192.168.0.97"", ""port"": 3306, ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"", ""username"": ""9vD0Mtk3wFFuaaaY"", ""password"": ""Cjn4HsAiKV8sImst"", ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"", ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst"" } }, { ""name"": ""mySql2"", ""label"": ""p-mysql"", ""tags"": [ ""mysql"", ""relational"" ], ""plan"": ""100mb-dev"", ""credentials"": { ""hostname"": ""192.168.0.97"", ""port"": 3306, ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"", ""username"": ""9vD0Mtk3wFFuaaaY"", ""password"": ""Cjn4HsAiKV8sImst"", ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"", ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst"" } }] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var opt = new MySqlServiceOption(); opt.Bind(config, "mySql2"); Assert.Equal("mySql2", opt.Name); Assert.Equal("p-mysql", opt.Label); var opt2 = new MySqlServiceOption(); opt2.Bind(config, "mySql1"); Assert.Equal("mySql1", opt2.Name); Assert.Equal("p-mysql", opt2.Label); }
public void Constructor_WithVcapApplicationConfiguration() { // Arrange var configJson = @" { 'vcap': { 'application' : { 'cf_api': 'https://api.system.testcloud.com', 'application_id': 'fa05c1a9-0fc1-4fbd-bae1-139850dec7a3', 'application_name': 'my-app', 'application_uris': [ 'my-app.10.244.0.34.xip.io' ], 'application_version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca', 'limits': { 'disk': 1024, 'fds': 16384, 'mem': 256 }, 'name': 'my-app', 'space_id': '06450c72-4669-4dc6-8096-45f9777db68a', 'space_name': 'my-space', 'uris': [ 'my-app.10.244.0.34.xip.io', 'my-app2.10.244.0.34.xip.io' ], 'users': null, 'version': 'fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca' } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var options = new CloudFoundryApplicationOptions(); var appSection = config.GetSection(CloudFoundryApplicationOptions.CONFIGURATION_PREFIX); appSection.Bind(options); Assert.Equal("https://api.system.testcloud.com", options.CF_Api); Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", options.ApplicationId); Assert.Equal("fa05c1a9-0fc1-4fbd-bae1-139850dec7a3", options.Application_Id); Assert.Equal("my-app", options.ApplicationName); Assert.Equal("my-app", options.Application_Name); Assert.NotNull(options.ApplicationUris); Assert.NotNull(options.Application_Uris); Assert.Single(options.ApplicationUris); Assert.Single(options.Application_Uris); Assert.Equal("my-app.10.244.0.34.xip.io", options.ApplicationUris[0]); Assert.Equal("my-app.10.244.0.34.xip.io", options.Application_Uris[0]); Assert.Equal("fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca", options.ApplicationVersion); Assert.Equal("my-app", options.Name); Assert.Equal("06450c72-4669-4dc6-8096-45f9777db68a", options.SpaceId); Assert.Equal("06450c72-4669-4dc6-8096-45f9777db68a", options.Space_Id); Assert.Equal("my-space", options.SpaceName); Assert.Equal("my-space", options.Space_Name); Assert.NotNull(options.Uris); Assert.Equal(2, options.Uris.Length); Assert.Equal("my-app.10.244.0.34.xip.io", options.Uris[0]); Assert.Equal("my-app2.10.244.0.34.xip.io", options.Uris[1]); Assert.Equal("fb8fbcc6-8d58-479e-bcc7-3b4ce5a7f0ca", options.Version); }
public void Load_LoadsProvidedStream() { var environment = @" { 'p-config-server': [ { 'name': 'myConfigServer', 'label': 'p-config-server', 'tags': [ 'configuration', 'spring-cloud' ], 'plan': 'standard', 'credentials': { 'uri': 'https://config-eafc353b-77e2-4dcc-b52a-25777e996ed9.apps.testcloud.com', 'client_id': 'p-config-server-9bff4c87-7ffd-4536-9e76-e67ea3ec81d0', 'client_secret': 'AJUAjyxP3nO9', 'access_token_uri': 'https://p-spring-cloud-services.uaa.system.testcloud.com/oauth/token' } } ], 'p-service-registry': [ { 'name': 'myServiceRegistry', 'label': 'p-service-registry', 'tags': [ 'eureka', 'discovery', 'registry', 'spring-cloud' ], 'plan': 'standard', 'credentials': { 'uri': 'https://eureka-f4b98d1c-3166-4741-b691-79abba5b2d51.apps.testcloud.com', 'client_id': 'p-service-registry-9121b185-cd3b-497c-99f7-8e8064d4a6f0', 'client_secret': '3Rv1U79siLDa', 'access_token_uri': 'https://p-spring-cloud-services.uaa.system.testcloud.com/oauth/token' } } ], 'p-mysql': [ { 'name': 'mySql1', 'label': 'p-mysql', 'tags': [ 'mysql', 'relational' ], 'plan': '100mb-dev', 'credentials': { 'hostname': '192.168.0.97', 'port': 3306, 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 'username': '******', 'password': '******', 'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' } }, { 'name': 'mySql2', 'label': 'p-mysql', 'tags': [ 'mysql', 'relational' ], 'plan': '100mb-dev', 'credentials': { 'hostname': '192.168.0.97', 'port': 3306, 'name': 'cf_b2d83697_5fa1_4a51_991b_975c9d7e5515', 'username': '******', 'password': '******', 'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?reconnect=true', 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?user=gxXQb2pMbzFsZQW8&password=lvMkGf6oJQvKSOwn' } } ] }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(environment); var provider = new JsonStreamConfigurationProvider(new JsonStreamConfigurationSource(memStream)); provider.Load(); string value = null; Assert.True(provider.TryGet("p-config-server:0:name", out value)); Assert.Equal("myConfigServer", value); Assert.True(provider.TryGet("p-config-server:0:credentials:uri", out value)); Assert.Equal("https://config-eafc353b-77e2-4dcc-b52a-25777e996ed9.apps.testcloud.com", value); Assert.True(provider.TryGet("p-service-registry:0:name", out value)); Assert.Equal("myServiceRegistry", value); Assert.True(provider.TryGet("p-service-registry:0:credentials:uri", out value)); Assert.Equal("https://eureka-f4b98d1c-3166-4741-b691-79abba5b2d51.apps.testcloud.com", value); Assert.True(provider.TryGet("p-mysql:1:name", out value)); Assert.Equal("mySql2", value); Assert.True(provider.TryGet("p-mysql:1:credentials:uri", out value)); Assert.Equal("mysql://*****:*****@192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?reconnect=true", value); }
public void ConfigureCloudFoundryServices_ConfiguresServices() { // Arrange var configJson = @" { 'vcap': { 'services' : { 'p-mysql': [ { 'name': 'mySql1', 'label': 'p-mysql', 'tags': [ 'mysql', 'relational' ], 'plan': '100mb-dev', 'credentials': { 'hostname': '192.168.0.97', 'port': 3306, 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 'username': '******', 'password': '******', 'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' } }, { 'name': 'mySql2', 'label': 'p-mysql', 'tags': [ 'mysql', 'relational' ], 'plan': '100mb-dev', 'credentials': { 'hostname': '192.168.0.97', 'port': 3306, 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 'username': '******', 'password': '******', 'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' } } ] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var services = new ServiceCollection(); services.AddOptions(); // Act and Assert CloudFoundryServiceCollectionExtensions.ConfigureCloudFoundryServices <MySqlServiceOption>(services, config, "p-mysql"); var serviceProvider = services.BuildServiceProvider(); var snapShot = serviceProvider.GetRequiredService <IOptionsSnapshot <MySqlServiceOption> >(); var monitor = serviceProvider.GetRequiredService <IOptionsMonitor <MySqlServiceOption> >(); var snapOpt1 = snapShot.Get("mySql1"); var monOpt1 = monitor.Get("mySql1"); Assert.NotNull(snapOpt1); Assert.NotNull(monOpt1); Assert.Equal("mySql1", snapOpt1.Name); Assert.Equal("p-mysql", snapOpt1.Label); Assert.Equal("mySql1", monOpt1.Name); Assert.Equal("p-mysql", monOpt1.Label); var snapOpt2 = snapShot.Get("mySql2"); var monOpt2 = monitor.Get("mySql2"); Assert.NotNull(snapOpt2); Assert.NotNull(monOpt2); Assert.Equal("mySql2", snapOpt2.Name); Assert.Equal("p-mysql", snapOpt2.Label); Assert.Equal("mySql2", monOpt2.Name); Assert.Equal("p-mysql", monOpt2.Label); }
public void ConfigureCloudFoundryServices_ConfiguresServices() { // Arrange var configJson = @" { ""vcap"": { ""services"" : { ""p-mysql"": [{ ""name"": ""mySql1"", ""label"": ""p-mysql"", ""tags"": [ ""mysql"", ""relational"" ], ""plan"": ""100mb-dev"", ""credentials"": { ""hostname"": ""192.168.0.97"", ""port"": 3306, ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"", ""username"": ""9vD0Mtk3wFFuaaaY"", ""password"": ""Cjn4HsAiKV8sImst"", ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"", ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst"" } }, { ""name"": ""mySql2"", ""label"": ""p-mysql"", ""tags"": [ ""mysql"", ""relational"" ], ""plan"": ""100mb-dev"", ""credentials"": { ""hostname"": ""192.168.0.97"", ""port"": 3306, ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"", ""username"": ""9vD0Mtk3wFFuaaaY"", ""password"": ""Cjn4HsAiKV8sImst"", ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"", ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst"" } }] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var services = new ServiceCollection(); services.AddOptions(); // Act and Assert CloudFoundryServiceCollectionExtensions.ConfigureCloudFoundryServices <MySqlServiceOption>(services, config, "p-mysql"); var serviceProvider = services.BuildServiceProvider(); var snapShot = serviceProvider.GetRequiredService <IOptionsSnapshot <MySqlServiceOption> >(); var monitor = serviceProvider.GetRequiredService <IOptionsMonitor <MySqlServiceOption> >(); var snapOpt1 = snapShot.Get("mySql1"); var monOpt1 = monitor.Get("mySql1"); Assert.NotNull(snapOpt1); Assert.NotNull(monOpt1); Assert.Equal("mySql1", snapOpt1.Name); Assert.Equal("p-mysql", snapOpt1.Label); Assert.Equal("mySql1", monOpt1.Name); Assert.Equal("p-mysql", monOpt1.Label); var snapOpt2 = snapShot.Get("mySql2"); var monOpt2 = monitor.Get("mySql2"); Assert.NotNull(snapOpt2); Assert.NotNull(monOpt2); Assert.Equal("mySql2", snapOpt2.Name); Assert.Equal("p-mysql", snapOpt2.Label); Assert.Equal("mySql2", monOpt2.Name); Assert.Equal("p-mysql", monOpt2.Label); }
public void Constructor_WithMultipleSameServicesConfiguration() { // Arrange var configJson = @" { ""vcap"": { ""services"" : { ""p-mysql"": [ { ""name"": ""mySql1"", ""label"": ""p-mysql"", ""tags"": [""mysql"",""relational""], ""plan"": ""100mb-dev"", ""credentials"": { ""hostname"": ""192.168.0.97"", ""port"": 3306, ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"", ""username"": ""9vD0Mtk3wFFuaaaY"", ""password"": ""Cjn4HsAiKV8sImst"", ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"", ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst"" } }, { ""name"": ""mySql2"", ""label"": ""p-mysql"", ""tags"": [""mysql"",""relational""], ""plan"": ""100mb-dev"", ""credentials"": { ""hostname"": ""192.168.0.97"", ""port"": 3306, ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"", ""username"": ""9vD0Mtk3wFFuaaaY"", ""password"": ""Cjn4HsAiKV8sImst"", ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"", ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst"" } }] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var options = new CloudFoundryServicesOptions(config); Assert.NotNull(options.Services); Assert.Single(options.Services); Assert.NotNull(options.Services["p-mysql"]); Assert.Equal(2, options.GetServicesList().Count()); var service1 = options.GetServicesList().First(n => n.Name == "mySql1"); var service2 = options.GetServicesList().First(n => n.Name == "mySql2"); Assert.NotNull(service1); Assert.NotNull(service2); Assert.Equal("p-mysql", service1.Label); Assert.Equal("192.168.0.97", service1.Credentials["hostname"].Value); Assert.Equal("3306", service1.Credentials["port"].Value); Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", service1.Credentials["name"].Value); Assert.Equal("p-mysql", service2.Label); Assert.Equal("192.168.0.97", service2.Credentials["hostname"].Value); Assert.Equal("3306", service2.Credentials["port"].Value); Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", service2.Credentials["name"].Value); }
public void Load_LoadsProvidedStream() { var environment = @" { ""p-config-server"": [{ ""name"": ""myConfigServer"", ""label"": ""p-config-server"", ""tags"": [ ""configuration"", ""spring-cloud"" ], ""plan"": ""standard"", ""credentials"": { ""uri"": ""https://config-eafc353b-77e2-4dcc-b52a-25777e996ed9.apps.testcloud.com"", ""client_id"": ""p-config-server-9bff4c87-7ffd-4536-9e76-e67ea3ec81d0"", ""client_secret"": ""AJUAjyxP3nO9"", ""access_token_uri"": ""https://p-spring-cloud-services.uaa.system.testcloud.com/oauth/token"" } }], ""p-service-registry"": [{ ""name"": ""myServiceRegistry"", ""label"": ""p-service-registry"", ""tags"": [ ""eureka"", ""discovery"", ""registry"", ""spring-cloud"" ], ""plan"": ""standard"", ""credentials"": { ""uri"": ""https://eureka-f4b98d1c-3166-4741-b691-79abba5b2d51.apps.testcloud.com"", ""client_id"": ""p-service-registry-9121b185-cd3b-497c-99f7-8e8064d4a6f0"", ""client_secret"": ""3Rv1U79siLDa"", ""access_token_uri"": ""https://p-spring-cloud-services.uaa.system.testcloud.com/oauth/token"" } }], ""p-mysql"": [{ ""name"": ""mySql1"", ""label"": ""p-mysql"", ""tags"": [ ""mysql"", ""relational"" ], ""plan"": ""100mb-dev"", ""credentials"": { ""hostname"": ""192.168.0.97"", ""port"": 3306, ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"", ""username"": ""9vD0Mtk3wFFuaaaY"", ""password"": ""Cjn4HsAiKV8sImst"", ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"", ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst"" } }, { ""name"": ""mySql2"", ""label"": ""p-mysql"", ""tags"": [""mysql"",""relational""], ""plan"": ""100mb-dev"", ""credentials"": { ""hostname"": ""192.168.0.97"", ""port"": 3306, ""name"": ""cf_b2d83697_5fa1_4a51_991b_975c9d7e5515"", ""username"": ""gxXQb2pMbzFsZQW8"", ""password"": ""lvMkGf6oJQvKSOwn"", ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?reconnect=true"", ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?user=gxXQb2pMbzFsZQW8&password=lvMkGf6oJQvKSOwn"" } }] }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(environment); var provider = new JsonStreamConfigurationProvider(new JsonStreamConfigurationSource(memStream)); provider.Load(); string value = null; Assert.True(provider.TryGet("p-config-server:0:name", out value)); Assert.Equal("myConfigServer", value); Assert.True(provider.TryGet("p-config-server:0:credentials:uri", out value)); Assert.Equal("https://config-eafc353b-77e2-4dcc-b52a-25777e996ed9.apps.testcloud.com", value); Assert.True(provider.TryGet("p-service-registry:0:name", out value)); Assert.Equal("myServiceRegistry", value); Assert.True(provider.TryGet("p-service-registry:0:credentials:uri", out value)); Assert.Equal("https://eureka-f4b98d1c-3166-4741-b691-79abba5b2d51.apps.testcloud.com", value); Assert.True(provider.TryGet("p-mysql:1:name", out value)); Assert.Equal("mySql2", value); Assert.True(provider.TryGet("p-mysql:1:credentials:uri", out value)); Assert.Equal("mysql://*****:*****@192.168.0.97:3306/cf_b2d83697_5fa1_4a51_991b_975c9d7e5515?reconnect=true", value); }
public void Bind_BindsConfiguration() { // Arrange var configJson = @" { 'vcap': { 'services' : { 'p-mysql': [ { 'name': 'mySql1', 'label': 'p-mysql', 'tags': [ 'mysql', 'relational' ], 'plan': '100mb-dev', 'credentials': { 'hostname': '192.168.0.97', 'port': 3306, 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 'username': '******', 'password': '******', 'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' } }, { 'name': 'mySql2', 'label': 'p-mysql', 'tags': [ 'mysql', 'relational' ], 'plan': '100mb-dev', 'credentials': { 'hostname': '192.168.0.97', 'port': 3306, 'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31', 'username': '******', 'password': '******', 'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true', 'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst' } } ] } } }"; var memStream = CloudFoundryConfigurationProvider.GetMemoryStream(configJson); var jsonSource = new JsonStreamConfigurationSource(memStream); var builder = new ConfigurationBuilder().Add(jsonSource); var config = builder.Build(); var opt = new MySqlServiceOption(); opt.Bind(config, "mySql2"); Assert.Equal("mySql2", opt.Name); Assert.Equal("p-mysql", opt.Label); var opt2 = new MySqlServiceOption(); opt2.Bind(config, "mySql1"); Assert.Equal("mySql1", opt2.Name); Assert.Equal("p-mysql", opt2.Label); }